Skip to content

Commit d54e15a

Browse files
Merge pull request #169 from pelican-dev/chore/updatePanel
updatePanel script Cleanup
2 parents 46a328b + 8600031 commit d54e15a

File tree

1 file changed

+30
-46
lines changed

1 file changed

+30
-46
lines changed

static/updatePanel.sh

Lines changed: 30 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ if [[ $EUID -ne 0 ]]; then
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-
158
read -p "Enter the directory for the panel location [/var/www/pelican]: " install_dir
169
install_dir=${install_dir:-/var/www/pelican}
1710

@@ -35,15 +28,7 @@ group=$(stat -c '%G' "$install_dir" || echo "www-data")
3528
read -p "Enter the group of the files (www-data, apache, nginx) [$group]: " group
3629
group=${group:-www-data}
3730

38-
cd "$install_dir"
39-
php artisan down
40-
if [ $? -ne 0 ]; then
41-
echo "Failed to put the panel into maintenance mode."
42-
exitInstall 1
43-
fi
44-
echo "Panel is now in maintenance mode."
45-
46-
db_connection=$(grep "^DB_CONNECTION=" "$env_file" | cut -d '=' -f 2)
31+
db_connection=$(grep "^DB_CONNECTION=" "$env_file" | cut -d '=' -f 2 | tr -d "\"'")
4732

4833
if [ -z "$db_connection" ]; then
4934
db_connection='sqlite'
@@ -56,29 +41,33 @@ read -p "Do you want to create a backup? (y/n) [y]: " backup_confirm
5641
backup_confirm=${backup_confirm:-y}
5742
if [ "$backup_confirm" != "y" ]; then
5843
echo "Backup canceled."
59-
exitInstall 0
44+
exit 1
6045
fi
6146

6247
backup_dir="$install_dir/backup"
6348
mkdir -p "$backup_dir/storage/app"
49+
if [ $? -ne 0 ]; then
50+
echo "Failed to create backup directory $backup_dir, aborting"
51+
exit 1
52+
fi
6453

6554
cp -a "$env_file" "$backup_dir/.env.backup"
6655
if [ $? -ne 0 ]; then
6756
echo "Failed to backup .env file, aborting"
68-
exitInstall 1
57+
exit 1
6958
fi
7059
echo "Backed up .env file successfully."
7160

7261
if [ -d "$install_dir/storage/app/public" ]; then
7362
cp -a "$install_dir/storage/app/public" "$backup_dir/storage/app/"
7463
if [ $? -ne 0 ]; then
7564
echo "Failed to backup avatars & fonts files, aborting"
76-
exitInstall 1
65+
exit 1
7766
fi
7867
fi
7968

8069
if [ "$db_connection" = "sqlite" ]; then
81-
db_database=$(grep "^DB_DATABASE=" "$env_file" | cut -d '=' -f 2)
70+
db_database=$(grep "^DB_DATABASE=" "$env_file" | cut -d '=' -f 2 | tr -d "\"'")
8271

8372
if [ -z "$db_database" ]; then
8473
uses_default=true
@@ -97,14 +86,14 @@ if [ "$db_connection" = "sqlite" ]; then
9786
cp -a "$install_dir/database/$db_database" "$backup_dir/$db_database.backup"
9887
if [ $? -ne 0 ]; then
9988
echo "Failed to backup $db_database file, aborting"
100-
exitInstall 1
89+
exit 1
10190
fi
10291
else
10392
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
10493
database_confirm=${database_confirm:-y}
10594
if [ "$database_confirm" != "y" ]; then
10695
echo "Update Canceled."
107-
exitInstall 0
96+
exit 1
10897
fi
10998
fi
11099

@@ -118,62 +107,50 @@ if [[ -z "$expected_checksum" || -z "$calculated_checksum" || "$expected_checksu
118107
checksum_confirm=${checksum_confirm:-y}
119108
if [ "$checksum_confirm" != "y" ]; then
120109
echo "Update Canceled."
121-
exitInstall 1
110+
exit 1
122111
fi
112+
else
113+
echo "Checksum verified."
123114
fi
124115

125-
echo "Checksum verified."
126116
read -p "Do you want to delete all files and folders in $install_dir except the backup folder? (y/n) [y]: " delete_confirm
127117
delete_confirm=${delete_confirm:-y}
128118
if [ "$delete_confirm" != "y" ]; then
129119
echo "Deletion canceled."
130-
exitInstall 0
120+
exit 1
131121
fi
132122

133-
find "$install_dir" -mindepth 1 -maxdepth 1 ! -name 'backup' ! -name 'panel.tar.gz' ! -name 'artisan' -exec rm -rf {} +
123+
find "$install_dir" -mindepth 1 -maxdepth 1 ! -name 'backup' ! -name 'panel.tar.gz' -exec rm -rf {} +
134124
if [ $? -ne 0 ]; then
135125
echo "Failed to delete old files, aborting"
136-
exitInstall 1
126+
exit 1
137127
fi
138128
echo "Deleted all files and folders in $install_dir except the backup folder."
139129

140130
echo "Extracting tarball."
141131
tar -xzf panel.tar.gz -C "$install_dir"
142132
if [ $? -ne 0 ]; then
143133
echo "Failed to extract tarball, aborting"
144-
exitInstall 1
134+
exit 1
145135
fi
146136
rm panel.tar.gz
147137
if [ $? -ne 0 ]; then
148138
echo "Failed to delete leftover tarball, continuing."
149139
fi
150140

151-
echo "Installing Composer"
152-
COMPOSER_ALLOW_SUPERUSER=1 composer install --no-dev --optimize-autoloader --no-interaction
153-
if [ $? -ne 0 ]; then
154-
echo "Failed to run composer, aborting"
155-
exitInstall 1
156-
fi
157-
158-
php artisan down
159-
if [ $? -ne 0 ]; then
160-
echo "Failed to put the panel into maintenance mode."
161-
exitInstall 1
162-
fi
163-
164141
echo "Restoring .env"
165142
cp -a "$backup_dir/.env.backup" "$install_dir/.env"
166143
if [ $? -ne 0 ]; then
167144
echo "Failed to restore the .env file, aborting"
168-
exitInstall 1
145+
exit 1
169146
fi
170147

171148
if [ -d "$backup_dir/storage/app/public" ]; then
172149
echo "Restoring avatars & fonts"
173150
cp -a "$backup_dir/storage/app/public" "$install_dir/storage/app/"
174151
if [ $? -ne 0 ]; then
175152
echo "Failed to restore avatars & fonts files, aborting"
176-
exitInstall 1
153+
exit 1
177154
fi
178155
fi
179156

@@ -182,10 +159,19 @@ if [ -f "$backup_dir/$db_database.backup" ]; then
182159
cp -a "$backup_dir/$db_database.backup" "$install_dir/database/$db_database"
183160
if [ $? -ne 0 ]; then
184161
echo "Failed to restore the database, aborting"
185-
exitInstall 1
162+
exit 1
186163
fi
187164
fi
188165

166+
cd $install_dir
167+
168+
echo "Installing Composer"
169+
COMPOSER_ALLOW_SUPERUSER=1 composer install --no-dev --optimize-autoloader --no-interaction
170+
if [ $? -ne 0 ]; then
171+
echo "Failed to run composer, aborting"
172+
exit 1
173+
fi
174+
189175
echo "Optimizing"
190176
php artisan optimize:clear
191177
php artisan filament:optimize
@@ -211,8 +197,6 @@ if [ $? -ne 0 ]; then
211197
fi
212198

213199
php artisan queue:restart
214-
php artisan up
215200

216-
echo "Panel is now live and out of maintenance mode."
217201
echo "Panel Updated!"
218202
exit 0

0 commit comments

Comments
 (0)