1
- #! /bin/sh
1
+ #! /bin/bash
2
2
3
3
if [[ $EUID -ne 0 ]]; then
4
4
echo " This script must be run as root or with sudo." >&2
5
5
exit 1
6
6
fi
7
7
8
+ function exitInstall {
9
+ cd " $install_dir "
10
+ php artisan up
11
+ echo " Panel is out of maintenance mode."
12
+ exit $1
13
+ }
14
+
8
15
read -p " Enter the directory for the panel location [/var/www/pelican]: " install_dir
9
16
install_dir=${install_dir:-/ var/ www/ pelican}
10
17
@@ -20,97 +27,141 @@ if [ ! -f "$env_file" ]; then
20
27
exit 1
21
28
fi
22
29
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
+
23
38
cd " $install_dir "
24
39
php artisan down
25
40
if [ $? -ne 0 ]; then
26
41
echo " Failed to put the panel into maintenance mode."
27
- exit 1
42
+ exitInstall 1
28
43
fi
29
44
echo " Panel is now in maintenance mode."
30
45
31
46
db_connection=$( grep " ^DB_CONNECTION=" " $env_file " | cut -d ' =' -f 2)
32
47
33
48
if [ -z " $db_connection " ]; then
34
49
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
46
71
fi
47
72
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
72
88
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."
73
97
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
76
110
fi
77
111
112
+ echo " Checksum verified."
78
113
read -p " Do you want to delete all files and folders in $install_dir except the backup folder? (y/n) [y]: " delete_confirm
79
114
delete_confirm=${delete_confirm:- y}
80
115
if [ " $delete_confirm " != " y" ]; then
81
116
echo " Deletion canceled."
82
- php artisan up
83
- echo " Panel is out of maintenance mode."
84
- exit 0
117
+ exitInstall 0
85
118
fi
86
119
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
89
125
echo " Deleted all files and folders in $install_dir except the backup folder."
90
126
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."
102
136
fi
103
137
104
138
echo " Installing Composer"
105
139
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
106
144
107
145
php artisan down
146
+ if [ $? -ne 0 ]; then
147
+ echo " Failed to put the panel into maintenance mode."
148
+ exitInstall 1
149
+ fi
108
150
109
151
echo " Restoring .env"
110
152
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
+
111
158
if [ " $db_connection " = " sqlite" ]; then
112
159
echo " Restoring sqlite database"
113
160
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
114
165
fi
115
166
116
167
echo " Optimizing"
@@ -120,16 +171,23 @@ php artisan filament:optimize
120
171
echo " Updating database"
121
172
php artisan migrate --seed --force
122
173
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
-
126
174
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
129
187
130
188
php artisan queue:restart
131
189
php artisan up
132
190
133
191
echo " Panel is now live and out of maintenance mode."
134
192
echo " Panel Updated!"
135
- exit 0
193
+ exit 0
0 commit comments