forked from fjueic/gsconnect-mount-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·68 lines (56 loc) · 2.72 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# if root, exit
if [ "$(id -u)" -eq 0 ]; then
echo -e "\e[91mPlease run this script as a normal user\e[0m"
exit 1
fi
# Get home directory of user
if [ "$(id -u)" -eq 0 ]; then
USER_HOME=$(getent passwd "$SUDO_USER" | cut -d: -f6)
else
USER_HOME=$(getent passwd "$USER" | cut -d: -f6)
fi
# Get the directory where the plugin is installed(System or local)
echo "Checking if GS-Connect extension if installed"
if [ -e "$USER_HOME/.local/share/gnome-shell/extensions/gsconnect@andyholmes.github.io/service/" ]; then
extension_dir="$USER_HOME/.local/share/gnome-shell/extensions/gsconnect@andyholmes.github.io/service/"
elif [ -e "/usr/share/gnome-shell/extensions/gsconnect@andyholmes.github.io/service/" ]; then
extension_dir="/usr/share/gnome-shell/extensions/gsconnect@andyholmes.github.io/service/"
else
echo "Extension not installed."
echo "Please install gsconnect extension"
exit 0
fi
echo "Checking if the patch has been applied"
block_of_code="this block of code is not part of gsconnect connect extension"
if grep -q "$block_of_code" "$extension_dir/plugins/sftp.js"; then
echo "Patch is already applied"
echo "To Update, Reinstall gsconnect extension and Try Again"
exit 1
fi
# changing directory to the script directory
script_dir=$(dirname "$0")
cd "$script_dir" || exit # Exit the script if cd doesn't work, prevents following commands from running
# putting files in place
mkdir -p "$USER_HOME/.config/gsconnect-mount-manager/" && cp -f ./run.py "$USER_HOME/.config/gsconnect-mount-manager/" && cp -f ./mount.py "$USER_HOME/.config/gsconnect-mount-manager/"
touch "$USER_HOME/.config/gsconnect-mount-manager/temp.json"
[ -e /etc/systemd/user/gsconnect-mount-manager.service ] || sudo touch /etc/systemd/user/gsconnect-mount-manager.service
# update service file
# Change > to " | sudo tee " because shell doesn't have to permission to redirect to system file
# redirecting to >/dev/null prevent the information from being put to stdout(Doesn't output the service file)
# ( It would work if the whole script is run with sudo )
echo "Creating a user systemd service"
echo " "
sudo ./update_servicefile.py "$USER_HOME" "$script_dir" | sudo tee /etc/systemd/user/gsconnect-mount-manager.service >/dev/null
# editing sftp.js in gsconnect extension
echo " "
echo "Editing sftp.js in gsconnect extension"
sudo ./update_sftp.py "$USER_HOME" "$extension_dir"
# enabling service
echo "Enabling Custom gsconnect-mount-manager.service Now"
systemctl --user daemon-reload
systemctl --user enable gsconnect-mount-manager.service
systemctl --user start gsconnect-mount-manager.service
echo "============================================="
echo "====================DONE!===================="
echo "============================================="
echo " "