Skip to content

Commit b5a26e4

Browse files
authored
Use default fallbacks when DB_CONNECTION or DB_DATABASE are missing (#164)
* Use database.sqlite as default DB_DATABASE * Avoid duplicated echo * Quotes * Check if file exist before trying to restore it * Check for dirs not files
1 parent 0a98d15 commit b5a26e4

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

static/updatePanel.sh

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ echo "Panel is now in maintenance mode."
4646
db_connection=$(grep "^DB_CONNECTION=" "$env_file" | cut -d '=' -f 2)
4747

4848
if [ -z "$db_connection" ]; then
49-
echo "DB_CONNECTION not found in $env_file."
50-
exitInstall 0
49+
db_connection='sqlite'
50+
echo "DB_CONNECTION not found in $env_file, using $db_connection as default."
51+
else
52+
echo "DB_CONNECTION is set to: $db_connection"
5153
fi
5254

53-
echo "DB_CONNECTION is set to: $db_connection"
54-
5555
read -p "Do you want to create a backup? (y/n) [y]: " backup_confirm
5656
backup_confirm=${backup_confirm:-y}
5757
if [ "$backup_confirm" != "y" ]; then
@@ -69,24 +69,31 @@ if [ $? -ne 0 ]; then
6969
fi
7070
echo "Backed up .env file successfully."
7171

72-
cp -a "$install_dir/storage/app/public" "$backup_dir/storage/app/"
73-
if [ $? -ne 0 ]; then
74-
echo "Failed to backup avatars & fonts files, aborting"
75-
exitInstall 1
72+
if [ -d "$install_dir/storage/app/public" ]; then
73+
cp -a "$install_dir/storage/app/public" "$backup_dir/storage/app/"
74+
if [ $? -ne 0 ]; then
75+
echo "Failed to backup avatars & fonts files, aborting"
76+
exitInstall 1
77+
fi
7678
fi
7779

7880
if [ "$db_connection" = "sqlite" ]; then
7981
db_database=$(grep "^DB_DATABASE=" "$env_file" | cut -d '=' -f 2)
8082

8183
if [ -z "$db_database" ]; then
82-
echo "DB_DATABASE not found in $env_file."
83-
exitInstall 1
84+
uses_default=true
85+
db_database='database.sqlite'
86+
echo "DB_DATABASE not found in $env_file, using $db_database as default."
8487
fi
8588

8689
if [[ "$db_database" != *.sqlite ]]; then
8790
db_database="$db_database.sqlite"
8891
fi
89-
echo "DB_DATABASE is set to: $db_database"
92+
93+
if [ -z "$uses_default" ]; then
94+
echo "DB_DATABASE is set to: $db_database"
95+
fi
96+
9097
cp -a "$install_dir/database/$db_database" "$backup_dir/$db_database.backup"
9198
if [ $? -ne 0 ]; then
9299
echo "Failed to backup $db_database file, aborting"
@@ -161,14 +168,16 @@ if [ $? -ne 0 ]; then
161168
exitInstall 1
162169
fi
163170

164-
echo "Restoring avatars & fonts"
165-
cp -a "$backup_dir/storage/app/public" "$install_dir/storage/app/"
166-
if [ $? -ne 0 ]; then
167-
echo "Failed to restore avatars & fonts files, aborting"
168-
exitInstall 1
171+
if [ -d "$backup_dir/storage/app/public" ]; then
172+
echo "Restoring avatars & fonts"
173+
cp -a "$backup_dir/storage/app/public" "$install_dir/storage/app/"
174+
if [ $? -ne 0 ]; then
175+
echo "Failed to restore avatars & fonts files, aborting"
176+
exitInstall 1
177+
fi
169178
fi
170179

171-
if [ "$db_connection" = "sqlite" ]; then
180+
if [ -f "$backup_dir/$db_database.backup" ]; then
172181
echo "Restoring sqlite database"
173182
cp -a "$backup_dir/$db_database.backup" "$install_dir/database/$db_database"
174183
if [ $? -ne 0 ]; then

0 commit comments

Comments
 (0)