Skip to content

Commit 0b09035

Browse files
authored
Run prettier
1 parent be81830 commit 0b09035

File tree

1 file changed

+85
-85
lines changed

1 file changed

+85
-85
lines changed

bin/v-import-directadmin

Lines changed: 85 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ delete_tmp() {
5858

5959
# URL decoding function
6060
urldecode() {
61-
local url_encoded="${1//+/ }"
62-
printf '%b' "${url_encoded//%/\\x}"
61+
local url_encoded="${1//+/ }"
62+
printf '%b' "${url_encoded//%/\\x}"
6363
}
6464

6565
tput setaf 3
@@ -184,7 +184,7 @@ echo "Start with databases"
184184
tput sgr0
185185

186186
echo "Get local databases"
187-
mysql -e "SHOW DATABASES" > server_dbs
187+
mysql -e "SHOW DATABASES" >server_dbs
188188
da_db_list=$(ls -1 backup/ | grep ".conf")
189189
function run_da_db() {
190190
for da_db in $da_db_list; do
@@ -203,16 +203,16 @@ function run_da_db() {
203203
mysql -e "CREATE DATABASE $db"
204204

205205
# Preprocess the SQL file to remove problematic lines: https://jira.mariadb.org/browse/MDEV-34203
206-
grep -vE '^/\*!(999999\\-)' "backup/${database_name}.sql" > "backup/${database_name}_processed.sql" 2>/dev/null
206+
grep -vE '^/\*!(999999\\-)' "backup/${database_name}.sql" >"backup/${database_name}_processed.sql" 2>/dev/null
207207

208208
# Import the preprocessed SQL file with --force to ignore errors and continue
209-
mysql --force "${db}" < "backup/${database_name}_processed.sql"
209+
mysql --force "${db}" <"backup/${database_name}_processed.sql"
210210

211211
if [ $? -ne 0 ]; then
212-
tput setaf 1
213-
echo "Error importing database $db"
214-
tput sgr0
215-
continue
212+
tput setaf 1
213+
echo "Error importing database $db"
214+
tput sgr0
215+
continue
216216
fi
217217

218218
# Get all the users of the database
@@ -227,9 +227,9 @@ function run_da_db() {
227227
echo "udb: $db_user"
228228
echo "Password: ${md5}"
229229

230-
echo "DB='$db' DBUSER='$db_user' MD5='$md5' HOST='localhost' TYPE='mysql' CHARSET='UTF8' U_DISK='0' SUSPENDED='no' TIME='$time' DATE='$date'" >> /usr/local/hestia/data/users/"$directadmin_user"/db.conf
230+
echo "DB='$db' DBUSER='$db_user' MD5='$md5' HOST='localhost' TYPE='mysql' CHARSET='UTF8' U_DISK='0' SUSPENDED='no' TIME='$time' DATE='$date'" >>/usr/local/hestia/data/users/"$directadmin_user"/db.conf
231231
fi
232-
done < "backup/${da_db}"
232+
done <"backup/${da_db}"
233233

234234
# Leave Hestia to restore passwords and create users
235235
tput setaf 2
@@ -274,13 +274,13 @@ for directadmin_domain in $directadmin_domain_list; do
274274
tput sgr0
275275
elif [ -d /home/"${directadmin_user}"/web/"${directadmin_domain}" ]; then
276276
echo "Domain $directadmin_domain added, restoring files"
277-
echo "$directadmin_domain" >> restored_domains
277+
echo "$directadmin_domain" >>restored_domains
278278
rm -f /home/"$directadmin_user"/web/"$directadmin_domain"/public_html/index.html
279279
rm -f /home/"$directadmin_user"/web/"$directadmin_domain"/public_html/robots.txt
280280

281281
public_sync_count=0
282-
rsync -av domains/"${directadmin_domain}"/public_html/ /home/"$directadmin_user"/web/"$directadmin_domain"/public_html 2>&1 \
283-
| while read file_dm; do
282+
rsync -av domains/"${directadmin_domain}"/public_html/ /home/"$directadmin_user"/web/"$directadmin_domain"/public_html 2>&1 |
283+
while read file_dm; do
284284
public_sync_count=$(($public_sync_count + 1))
285285
echo -en "-- $public_sync_count restored files\r"
286286
done
@@ -293,8 +293,8 @@ for directadmin_domain in $directadmin_domain_list; do
293293
else
294294
private_sync_count=0
295295

296-
rsync -av domains/"${directadmin_domain}"/private_html/ /home/"$directadmin_user"/web/"$directadmin_domain"/private 2>&1 \
297-
| while read file_dm; do
296+
rsync -av domains/"${directadmin_domain}"/private_html/ /home/"$directadmin_user"/web/"$directadmin_domain"/private 2>&1 |
297+
while read file_dm; do
298298
private_sync_count=$(($private_sync_count + 1))
299299
echo -en "-- $private_sync_count restored files\r"
300300
done
@@ -334,8 +334,8 @@ if [ -e restored_domains ]; then
334334
tmp_pass=$(generate_password)
335335
"$BIN"/v-add-mail-account "$directadmin_user" "$da_mail_domain" "$da_imap" "$tmp_pass"
336336
if [ "$debug" != 0 ]; then
337-
rsync -av imap/"${da_mail_domain}"/"${da_imap}"/Maildir/ /home/"${directadmin_user}"/mail/"${da_mail_domain}"/"${da_imap}" 2>&1 \
338-
| while read backup_file_dm; do
337+
rsync -av imap/"${da_mail_domain}"/"${da_imap}"/Maildir/ /home/"${directadmin_user}"/mail/"${da_mail_domain}"/"${da_imap}" 2>&1 |
338+
while read backup_file_dm; do
339339
sk_sync=$((sk_sync + 1))
340340
echo -en "-- $sk_sync restored files\r"
341341
done
@@ -361,40 +361,40 @@ tput sgr0
361361

362362
# Restore cron jobs
363363
if [ -f "backup/crontab.conf" ]; then
364-
while IFS= read -r cron_line; do
365-
# Skip empty lines and comments
366-
[[ -z "$cron_line" || "$cron_line" =~ ^#.*$ ]] && continue
367-
368-
# Check if the line is an environment variable
369-
if [[ "$cron_line" =~ ^[A-Z]+= ]]; then
370-
# Export environment variable
371-
# echo "Setting environment variable: $cron_line"
372-
export "$cron_line"
373-
continue
374-
fi
375-
376-
# Remove the cron job identifier and extract cron job details
377-
if [[ "$cron_line" =~ ^[0-9]+= ]]; then
378-
cron_line=${cron_line#*=}
379-
fi
380-
381-
# Extract cron job details (handle cases where command contains spaces)
382-
IFS=' ' read -r min hour day month wday command <<< "$cron_line"
383-
384-
# Ensure it is a valid cron job line
385-
if ! [[ "$min" =~ ^[\*0-9,-/]+$ && "$hour" =~ ^[\*0-9,-/]+$ && "$day" =~ ^[\*0-9,-/]+$ && "$month" =~ ^[\*0-9,-/]+$ && "$wday" =~ ^[\*0-9,-/]+$ ]]; then
386-
echo "Invalid cron job format: $cron_line"
387-
continue
388-
fi
389-
390-
# Reconstruct the command part
391-
command="${cron_line#"${min}" "${hour}" "${day}" "${month}" "${wday}" }"
392-
393-
echo "Adding cron job for user $directadmin_user: $cron_line"
394-
"$BIN"/v-add-cron-job "$directadmin_user" "$min" "$hour" "$day" "$month" "$wday" "$command"
395-
done < "backup/crontab.conf"
364+
while IFS= read -r cron_line; do
365+
# Skip empty lines and comments
366+
[[ -z "$cron_line" || "$cron_line" =~ ^#.*$ ]] && continue
367+
368+
# Check if the line is an environment variable
369+
if [[ "$cron_line" =~ ^[A-Z]+= ]]; then
370+
# Export environment variable
371+
# echo "Setting environment variable: $cron_line"
372+
export "$cron_line"
373+
continue
374+
fi
375+
376+
# Remove the cron job identifier and extract cron job details
377+
if [[ "$cron_line" =~ ^[0-9]+= ]]; then
378+
cron_line=${cron_line#*=}
379+
fi
380+
381+
# Extract cron job details (handle cases where command contains spaces)
382+
IFS=' ' read -r min hour day month wday command <<<"$cron_line"
383+
384+
# Ensure it is a valid cron job line
385+
if ! [[ "$min" =~ ^[\*0-9,-/]+$ && "$hour" =~ ^[\*0-9,-/]+$ && "$day" =~ ^[\*0-9,-/]+$ && "$month" =~ ^[\*0-9,-/]+$ && "$wday" =~ ^[\*0-9,-/]+$ ]]; then
386+
echo "Invalid cron job format: $cron_line"
387+
continue
388+
fi
389+
390+
# Reconstruct the command part
391+
command="${cron_line#"${min}" "${hour}" "${day}" "${month}" "${wday}" }"
392+
393+
echo "Adding cron job for user $directadmin_user: $cron_line"
394+
"$BIN"/v-add-cron-job "$directadmin_user" "$min" "$hour" "$day" "$month" "$wday" "$command"
395+
done <"backup/crontab.conf"
396396
else
397-
echo "No cron jobs found to restore."
397+
echo "No cron jobs found to restore."
398398
fi
399399

400400
tput setaf 3
@@ -407,29 +407,29 @@ tput sgr0
407407
domain_base_dir="backup"
408408

409409
if [ -d "$domain_base_dir" ]; then
410-
for domain_subdir in "$domain_base_dir"/*/; do
411-
domain_pointers_file="$domain_subdir/domain.pointers"
412-
if [ -f "$domain_pointers_file" ]; then
413-
while IFS= read -r pointer_line; do
414-
# Skip empty lines and comments
415-
[[ -z "$pointer_line" || "$pointer_line" =~ ^#.*$ ]] && continue
416-
417-
# Extract alias and type
418-
alias_domain=$(echo "$pointer_line" | cut -d'=' -f1)
419-
alias_type=$(echo "$pointer_line" | awk -F'type=' '{print $2}')
420-
421-
if [[ "$alias_type" == "alias" || "$alias_type" == "pointer" ]]; then
422-
domain_name=$(basename "$domain_subdir")
423-
echo "Adding domain alias $alias_domain for user $directadmin_user on domain $domain_name"
424-
"$BIN"/v-add-web-domain-alias "$directadmin_user" "$domain_name" "$alias_domain" no
425-
else
426-
echo "Skipping non-alias type for $alias_domain: $alias_type"
427-
fi
428-
done < "$domain_pointers_file"
429-
fi
430-
done
410+
for domain_subdir in "$domain_base_dir"/*/; do
411+
domain_pointers_file="$domain_subdir/domain.pointers"
412+
if [ -f "$domain_pointers_file" ]; then
413+
while IFS= read -r pointer_line; do
414+
# Skip empty lines and comments
415+
[[ -z "$pointer_line" || "$pointer_line" =~ ^#.*$ ]] && continue
416+
417+
# Extract alias and type
418+
alias_domain=$(echo "$pointer_line" | cut -d'=' -f1)
419+
alias_type=$(echo "$pointer_line" | awk -F'type=' '{print $2}')
420+
421+
if [[ "$alias_type" == "alias" || "$alias_type" == "pointer" ]]; then
422+
domain_name=$(basename "$domain_subdir")
423+
echo "Adding domain alias $alias_domain for user $directadmin_user on domain $domain_name"
424+
"$BIN"/v-add-web-domain-alias "$directadmin_user" "$domain_name" "$alias_domain" no
425+
else
426+
echo "Skipping non-alias type for $alias_domain: $alias_type"
427+
fi
428+
done <"$domain_pointers_file"
429+
fi
430+
done
431431
else
432-
echo "No domain directories found to restore."
432+
echo "No domain directories found to restore."
433433
fi
434434

435435
tput setaf 3
@@ -439,20 +439,20 @@ echo "#######################################"
439439
tput sgr0
440440

441441
if [ "$letsencrypt_enable" = 1 ]; then
442-
for directadmin_domain in $directadmin_domain_list; do
443-
echo "Enabling Let's Encrypt for $directadmin_domain"
444-
letsencrypt_output=$("$BIN"/v-add-letsencrypt-domain "$directadmin_user" "$directadmin_domain" '' yes 2>&1)
442+
for directadmin_domain in $directadmin_domain_list; do
443+
echo "Enabling Let's Encrypt for $directadmin_domain"
444+
letsencrypt_output=$("$BIN"/v-add-letsencrypt-domain "$directadmin_user" "$directadmin_domain" '' yes 2>&1)
445445
echo "$letsencrypt_output"
446-
if echo "$letsencrypt_output" | grep -q "Error: mail domain"; then
447-
echo "Error with Let's Encrypt: $letsencrypt_output"
448-
echo "Retrying Let's Encrypt without mail domain for $directadmin_domain"
449-
"$BIN"/v-add-letsencrypt-domain "$directadmin_user" "$directadmin_domain" '' no
450-
else
451-
echo "Let's Encrypt enabled for $directadmin_domain"
452-
fi
453-
done
446+
if echo "$letsencrypt_output" | grep -q "Error: mail domain"; then
447+
echo "Error with Let's Encrypt: $letsencrypt_output"
448+
echo "Retrying Let's Encrypt without mail domain for $directadmin_domain"
449+
"$BIN"/v-add-letsencrypt-domain "$directadmin_user" "$directadmin_domain" '' no
450+
else
451+
echo "Let's Encrypt enabled for $directadmin_domain"
452+
fi
453+
done
454454
else
455-
echo "Let's Encrypt is not enabled for any domain."
455+
echo "Let's Encrypt is not enabled for any domain."
456456
fi
457457

458458
delete_tmp

0 commit comments

Comments
 (0)