-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdate.sh
More file actions
170 lines (146 loc) · 5.76 KB
/
update.sh
File metadata and controls
170 lines (146 loc) · 5.76 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/bash
# PiPass installer for v>=1.3.5
CL_BLANK='\e[0m'
CL_GREEN='\e[1;32m'
CL_RED='\e[1;31m'
CL_YELLOW='\e[1;93m'
SYM_CHECK="[${CL_GREEN}✓${CL_BLANK}]"
SYM_X="[${CL_RED}✗${CL_BLANK}]"
SYM_QUESTION="[${CL_YELLOW}?${CL_BLANK}]"
SYM_INFO="[i]"
# Global variables
PKGMAN=apt
WEBROOT=/var/www/html/
BLOCKPAGE_REPO_URL=https://github.com/pipass/blockpage.git
# Function declarations
command_exists() {
local check_command="$1"
command -v "${check_command}" >/dev/null 2>&1
}
update_system() {
get_package_manager() {
if command_exists apt; then
PKGMAN=apt
elif command_exists dnf; then
PKGMAN=dnf
else
printf "${SYM_INFO} ${CL_YELLOW}WARN:${CL_BLANK} We couldn't reliabliy determine your package manager. The installer will not attempt to install dependencies.\\n"
fi
}
get_package_manager
if [ "$PKGMAN" = "apt" ]; then
sudo apt update > pipass-update-stdout.log 2> pipass-update-err.log;
sudo apt -y upgrade > pipass-update-stdout.log 2> pipass-update-err.log;
elif [ "$PKGMAN" = "dnf" ]; then
sudo dnf -y update > pipass-update-stdout.log 2> pipass-update-err.log;
fi
}
dependencies_install() {
# git
if command_exists git; then
printf "\\n${SYM_CHECK} git is installed.\\n"
else
printf "\\n${SYM_X} git is not installed.\\n"
if [ "$PKGMAN" = "apt" ]; then
sudo apt install -y git > pipass-update-stdout.log 2> pipass-update-err.log;
elif [ "$PKGMAN" = "dnf" ]; then
sudo dnf install -y git > pipass-update-stdout.log 2> pipass-update-err.log;
fi
fi
# php
if command_exists php; then
printf "${SYM_CHECK} php is installed.\\n"
else
printf "${SYM_X} php is not installed.\\n"
if [ "$PKGMAN" = "apt" ]; then
sudo apt install -y php php-curl > pipass-update-stdout.log 2> pipass-update-err.log;
elif [ "$PKGMAN" = "dnf" ]; then
sudo dnf install -y php php-curl > pipass-update-stdout.log 2> pipass-update-err.log;
fi
fi
# php7.3/4-curl
if [ "$PKGMAN" = "apt" ]; then
if (apt list --installed | grep php-curl) > pipass-update-stdout.log 2> pipass-update-err.log; then
printf "${SYM_CHECK} php-curl is installed.\\n"
else
printf "${SYM_X} php-curl is not installed.\\n"
sudo apt install -y php-curl > pipass-update-stdout.log 2> pipass-update-err.log;
fi
elif [ "$PKGMAN" = "dnf" ]; then
if dnf list installed | egrep "php7.3-curl|php-7.4-curl" > pipass-update-stdout.log 2> pipass-update-err.log; then
printf "${SYM_CHECK} php-curl is installed.\\n"
else
printf "${SYM_X} php-curl is not installed.\\n"
sudo dnf install -y php-curl > pipass-update-stdout.log 2> pipass-update-err.log;
fi
fi
# curl
if command_exists curl; then
printf "${SYM_CHECK} curl is installed.\\n"
else
printf "${SYM_X} curl is not installed.\\n"
if [ "$PKGMAN" = "apt" ]; then
sudo apt install -y curl > pipass-update-stdout.log 2> pipass-update-err.log;
elif [ "$PKGMAN" = "dnf" ]; then
sudo dnf install -y curl > pipass-update-stdout.log 2> pipass-update-err.log;
fi
fi
}
update_pipass() {
cd $WEBROOT
# Copy config file
printf "${SYM_INFO} Making a copy of your current configuration file in case anything goes wrong.\\n"
sudo cp config.php config.update-backup.php
# Remove old origin and add new
printf "${SYM_INFO} Re-adding git upstream since its URL was moved.\\n"
sudo git remote remove origin
printf "${SYM_CHECK} Removed old repository from system.\\n"
sudo git remote add origin $BLOCKPAGE_REPO_URL
printf "${SYM_CHECK} Added new repository to system.\\n"
sudo git reset --hard
printf "${SYM_CHECK} Forcibly removed local changes to source code and updated to current version tagged upstream copy.\\n"
VERSION=$(curl https://raw.githubusercontent.com/PiPass/bin/master/currentversion)
printf "${SYM_INFO} The latest stable version is $VERSION.\\n"
printf "${SYM_INFO} Downloading lastest source code from upstream.\\n"
sudo git pull origin master
printf "${SYM_CHECK} Downloaded complete.\\n"
sudo git checkout tags/v$VERSION
printf "${SYM_CHECK} Checked out latest stable version.\\n"
printf "${SYM_CHECK} Nice! Your PiPass installation is now on v$VERSION.\\n"
}
if [[ $EUID -ne 0 ]]; then
printf "${SYM_X} ${CL_RED}FATAL:${CL_BLANK} The updater must be run with root permissions\\n"
exit 1;
fi
while true; do
printf "\\n"
read -p "To ensure compatibility, the system should be updated. Is this ok? [Y/n] " yn
case $yn in
[Yy]* ) update_system; break;;
[Nn]* ) break;;
* ) update_system; break;;
esac
done
while true; do
printf "\\n"
read -p "The updater will now check for and install dependencies. Is this ok? [Y/n] " yn
case $yn in
[Yy]* ) dependencies_install; break;;
[Nn]* ) break;;
* ) update_system; break;;
esac
done
if [ -d "$WEBROOT" ]; then
printf "\\n"
read -p "Changes to ALL PIPASS FILES will be overwritten (except local config file, PiPass.ini) with the update. Really continue? [Y/n] " yn
while true; do
case $yn in
[Yy]* ) update_pipass; break;;
[Nn]* ) exit;;
* ) update_pipass; break;;
esac
done
else
printf "${SYM_INFO} ${CL_YELLOW}WARN:${CL_BLANK} We couldn't reliabliy determine your webroot. Please manually modify the \"WEBROOT\" variable in the script and re-run. Sometimes, this can happen if there is no webserver installed. The updater will exit now.\\n"
exit;
fi