Skip to content

Commit e4024a1

Browse files
authored
Merge pull request #108 from RMartinOscar/fix/UpdateScriptSum
Various UpdateScript changes + checksum fix
2 parents 4fa5cdd + 10928bf commit e4024a1

File tree

1 file changed

+119
-61
lines changed

1 file changed

+119
-61
lines changed

static/updatePanel.sh

+119-61
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
if [[ $EUID -ne 0 ]]; then
44
echo "This script must be run as root or with sudo." >&2
55
exit 1
66
fi
77

8+
function exitInstall {
9+
cd "$install_dir"
10+
php artisan up
11+
echo "Panel is out of maintenance mode."
12+
exit $1
13+
}
14+
815
read -p "Enter the directory for the panel location [/var/www/pelican]: " install_dir
916
install_dir=${install_dir:-/var/www/pelican}
1017

@@ -20,97 +27,141 @@ if [ ! -f "$env_file" ]; then
2027
exit 1
2128
fi
2229

30+
owner=$(stat -c '%U' "$install_dir" || echo "www-data")
31+
read -p "Enter the owner of the files (www-data, apache, nginx) [$owner]: " owner
32+
owner=${owner:-www-data}
33+
34+
group=$(stat -c '%G' "$install_dir" || echo "www-data")
35+
read -p "Enter the group of the files (www-data, apache, nginx) [$group]: " group
36+
group=${group:-www-data}
37+
2338
cd "$install_dir"
2439
php artisan down
2540
if [ $? -ne 0 ]; then
2641
echo "Failed to put the panel into maintenance mode."
27-
exit 1
42+
exitInstall 1
2843
fi
2944
echo "Panel is now in maintenance mode."
3045

3146
db_connection=$(grep "^DB_CONNECTION=" "$env_file" | cut -d '=' -f 2)
3247

3348
if [ -z "$db_connection" ]; then
3449
echo "DB_CONNECTION not found in $env_file."
35-
exit 0
36-
else
37-
echo "DB_CONNECTION is set to: $db_connection"
38-
39-
read -p "Do you want to create a backup? (y/n) [y]: " backup_confirm
40-
backup_confirm=${backup_confirm:-y}
41-
if [ "$backup_confirm" != "y" ]; then
42-
echo "Backup canceled."
43-
php artisan up
44-
echo "Panel is out of maintenance mode."
45-
exit 0
50+
exitInstall 0
51+
fi
52+
53+
echo "DB_CONNECTION is set to: $db_connection"
54+
55+
read -p "Do you want to create a backup? (y/n) [y]: " backup_confirm
56+
backup_confirm=${backup_confirm:-y}
57+
if [ "$backup_confirm" != "y" ]; then
58+
echo "Backup canceled."
59+
exitInstall 0
60+
fi
61+
62+
backup_dir="$install_dir/backup"
63+
mkdir -p "$backup_dir"
64+
65+
if [ "$db_connection" = "sqlite" ]; then
66+
db_database=$(grep "^DB_DATABASE=" "$env_file" | cut -d '=' -f 2)
67+
68+
if [ -z "$db_database" ]; then
69+
echo "DB_DATABASE not found in $env_file."
70+
exitInstall 1
4671
fi
4772

48-
backup_dir="$install_dir/backup"
49-
mkdir -p "$backup_dir"
50-
51-
if [ "$db_connection" = "sqlite" ]; then
52-
db_database=$(grep "^DB_DATABASE=" "$env_file" | cut -d '=' -f 2)
53-
54-
if [ -z "$db_database" ]; then
55-
echo "DB_DATABASE not found in $env_file."
56-
php artisan up
57-
echo "Panel is out of maintenance mode."
58-
exit 1
59-
else
60-
echo "DB_DATABASE is set to: $db_database"
61-
cp "$install_dir/database/$db_database" "$backup_dir/$db_database.backup"
62-
fi
63-
else
64-
read -p "NOTE: THIS WILL NOT BACKUP MySQL/MariaDB DATABASES!!! You should pause now and make your own backup!! You've been warned! Continue? (y/n) [y]: " continue_confirm
65-
continue_confirm=${continue_confirm:-y}
66-
if [ "$continue_confirm" != "y" ]; then
67-
echo "Update Canceled."
68-
php artisan up
69-
echo "Panel is out of maintenance mode."
70-
exit 0
71-
fi
73+
if [[ "$db_database" != *.sqlite ]]; then
74+
db_database="$db_database.sqlite"
75+
fi
76+
echo "DB_DATABASE is set to: $db_database"
77+
cp "$install_dir/database/$db_database" "$backup_dir/$db_database.backup"
78+
if [ $? -ne 0 ]; then
79+
echo "Failed to backup $db_database file, aborting"
80+
exitInstall 1
81+
fi
82+
else
83+
read -p "NOTE: THIS WILL NOT BACKUP MySQL/MariaDB DATABASES!!! You should pause now and make your own backup!! You've been warned! Continue? (y/n) [y]: " database_confirm
84+
database_confirm=${database_confirm:-y}
85+
if [ "$database_confirm" != "y" ]; then
86+
echo "Update Canceled."
87+
exitInstall 0
7288
fi
89+
fi
90+
91+
cp "$env_file" "$backup_dir/.env.backup"
92+
if [ $? -ne 0 ]; then
93+
echo "Failed to backup .env file, aborting"
94+
exitInstall 1
95+
fi
96+
echo "Backed up .env file successfully."
7397

74-
cp "$env_file" "$backup_dir/.env.backup"
75-
echo "Backup completed successfully."
98+
echo "Downloading Files..."
99+
curl -L https://github.com/pelican-dev/panel/releases/latest/download/panel.tar.gz -o panel.tar.gz
100+
expected_checksum=$(curl -L https://github.com/pelican-dev/panel/releases/latest/download/checksum.txt | awk '{ print $1 }')
101+
calculated_checksum=$(sha256sum panel.tar.gz | awk '{ print $1 }')
102+
103+
if [[ -z "$expected_checksum" || -z "$calculated_checksum" || "$expected_checksum" != "$calculated_checksum" ]]; then
104+
read -p "NOTE: Checksum mismatch, the file may be corrupted!!! You've been warned! Continue? (y/n) [y]: " checksum_confirm
105+
checksum_confirm=${checksum_confirm:-y}
106+
if [ "$checksum_confirm" != "y" ]; then
107+
echo "Update Canceled."
108+
exitInstall 1
109+
fi
76110
fi
77111

112+
echo "Checksum verified."
78113
read -p "Do you want to delete all files and folders in $install_dir except the backup folder? (y/n) [y]: " delete_confirm
79114
delete_confirm=${delete_confirm:-y}
80115
if [ "$delete_confirm" != "y" ]; then
81116
echo "Deletion canceled."
82-
php artisan up
83-
echo "Panel is out of maintenance mode."
84-
exit 0
117+
exitInstall 0
85118
fi
86119

87-
find "$install_dir" -mindepth 1 -maxdepth 1 ! -name 'backup' -exec rm -rf {} +
88-
120+
find "$install_dir" -mindepth 1 -maxdepth 1 ! -name 'backup' ! -name 'panel.tar.gz' ! -name 'artisan' -exec rm -rf {} +
121+
if [ $? -ne 0 ]; then
122+
echo "Failed to delete old files, aborting"
123+
exitInstall 1
124+
fi
89125
echo "Deleted all files and folders in $install_dir except the backup folder."
90126

91-
echo "Downloading Files..."
92-
curl -L https://github.com/pelican-dev/panel/releases/latest/download/panel.tar.gz -o panel.tar.gz
93-
expected_checksum=$(curl -L https://github.com/pelican-dev/panel/releases/latest/download/checksum.txt)
94-
calculated_checksum=$(sha256sum panel.tar.gz | awk '{ print $1 }')
95-
96-
if [[ -n "$expected_checksum" && -n "$calculated_checksum" && "$expected_checksum" == "$calculated_checksum" ]]; then
97-
echo "Checksum verified. Proceeding to extract the tarball."
98-
tar -xzv panel.tar.gz -C "$install_dir"
99-
else
100-
echo "Checksum mismatch! The file may be corrupted."
101-
exit 1
127+
echo "Extracting tarball."
128+
tar -xzf panel.tar.gz -C "$install_dir"
129+
if [ $? -ne 0 ]; then
130+
echo "Failed to extract tarball, aborting"
131+
exitInstall 1
132+
fi
133+
rm panel.tar.gz
134+
if [ $? -ne 0 ]; then
135+
echo "Failed to delete leftover tarball, continuing."
102136
fi
103137

104138
echo "Installing Composer"
105139
COMPOSER_ALLOW_SUPERUSER=1 composer install --no-dev --optimize-autoloader --no-interaction
140+
if [ $? -ne 0 ]; then
141+
echo "Failed to run composer, aborting"
142+
exitInstall 1
143+
fi
106144

107145
php artisan down
146+
if [ $? -ne 0 ]; then
147+
echo "Failed to put the panel into maintenance mode."
148+
exitInstall 1
149+
fi
108150

109151
echo "Restoring .env"
110152
mv "$backup_dir/.env.backup" "$install_dir/.env"
153+
if [ $? -ne 0 ]; then
154+
echo "Failed to restore the .env file, aborting"
155+
exitInstall 1
156+
fi
157+
111158
if [ "$db_connection" = "sqlite" ]; then
112159
echo "Restoring sqlite database"
113160
mv "$backup_dir/$db_database.backup" "$install_dir/database/$db_database"
161+
if [ $? -ne 0 ]; then
162+
echo "Failed to restore the database, aborting"
163+
exitInstall 1
164+
fi
114165
fi
115166

116167
echo "Optimizing"
@@ -120,16 +171,23 @@ php artisan filament:optimize
120171
echo "Updating database"
121172
php artisan migrate --seed --force
122173

123-
read -p "Enter the owner of the files (www-data, apache, nginx) [www-data]: " file_owner
124-
file_owner=${file_owner:-www-data}
125-
126174
echo "Setting Permissions"
127-
chmod -R 755 storage/* bootstrap/cache
128-
chown -R "$file_owner":"$file_owner" "$install_dir"
175+
chmod_command="chmod -R 755 storage/* bootstrap/cache"
176+
eval $chmod_command
177+
if [ $? -ne 0 ]; then
178+
echo "Failed to run chmod, Please run the following commands manually:"
179+
echo "$chmod_command"
180+
fi
181+
chown_command="chown -R $owner:$group $install_dir"
182+
eval $chown_command
183+
if [ $? -ne 0 ]; then
184+
echo "Failed to run chown, Please run the following commands manually:"
185+
echo "$chown_command"
186+
fi
129187

130188
php artisan queue:restart
131189
php artisan up
132190

133191
echo "Panel is now live and out of maintenance mode."
134192
echo "Panel Updated!"
135-
exit 0
193+
exit 0

0 commit comments

Comments
 (0)