-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·94 lines (74 loc) · 2.13 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
sudo echo "Start"
if [ "$1" != "uninstall" ]; then
SOFT_URL_LAST=$(curl -Ls -o /dev/null -w %{url_effective} $1)
SOFT_URL_PATH=${1%%/latest*}
VERSION=${SOFT_URL_LAST##*release-}
SOFT_URL="$SOFT_URL_PATH/download/release-$VERSION/GitHubDesktop-linux-$VERSION.deb"
else
SOFT_URL=$1
fi
SOFT_PACKAGE=github-desktop
SOFT_KILL=github-desktop
DESK_PATH=$(xdg-user-dir DESKTOP) #/home/usernme/Dekstop/
LAUNCHER_PATH="/usr/share/applications/github-desktop.desktop"
LAUNCHER_DESK=${LAUNCHER_PATH##*/} #soft.desktop
# Permissions
chmodown() {
sudo chmod +x "$1"
sudo chown $USER:$USER "$1"
}
# Download and install
wget_dpkg_rm () {
SOFT_URL="$1"
SOFT_DEB=${SOFT_URL##*/}
sudo rm -rf "$SOFT_DEB"* 2> /dev/null
sudo wget -t inf "$SOFT_URL"
if [ ! -f "$SOFT_DEB" ]; then curl -L -O "$SOFT_URL"; fi
sudo mv "$SOFT_DEB" inst.deb
chmodown inst.deb
sudo dpkg -i inst.deb
sudo rm -rf inst.deb
}
if [ $USER == "root" ]; then
echo "Don't run as root user"
else
# Start count
START_TIME=`date +%s`
# UNINSTALLER
# Remove old versions and trash
# Close
kill $(pidof "$SOFT_KILL") 2> /dev/null
# Uninstall
sudo apt remove "$SOFT_PACKAGE"* -y 2> /dev/null
sudo apt purge "$SOFT_PACKAGE"* -y 2> /dev/null
sudo apt autoremove -y 2> /dev/null
# Remove trash
sudo rm -rf "$DESK_PATH/$LAUNCHER_DESK" 2> /dev/null
sudo rm -rf "$LAUNCHER_PATH"
sudo rm -rf ~/.config/GitHub* 2> /dev/null
sudo rm -rf $(xdg-user-dir DOCUMENTS)/GitHub
# Final message
if [[ $(sudo apt list "$SOFT_PACKAGE"* --installed 2> /dev/null) != *"$SOFT_PACKAGE"* ]]; then
echo "Software uninstalled!"
else
echo 'Error!'
fi
# INSTALLER
if [ "$SOFT_URL" != "uninstall" ]; then
wget_dpkg_rm "$SOFT_URL"
# Final fixes
sudo apt --fix-broken install -y
# Desktop launcher
sudo cp "$LAUNCHER_PATH" "$LAUNCHER_DESK"
chmodown "$LAUNCHER_DESK"
sudo rm -rf "$LAUNCHER_PATH"
sudo mv "$LAUNCHER_DESK" /usr/share/applications/
# Final message
if [[ $(sudo apt list "$SOFT_PACKAGE"* --installed 2> /dev/null) == *"$SOFT_PACKAGE"* ]]; then
sudo echo 'Software installed in '$(date -d @$((`date +%s`-$START_TIME)) -u +%H:%M:%S)
else
echo 'Error!'
fi # if installed
fi # if not uninstall
fi # if not root