Browse Source

Run prettier

RikkerdNL 1 year ago
parent
commit
0b090352cd
1 changed files with 85 additions and 85 deletions
  1. 85 85
      bin/v-import-directadmin

+ 85 - 85
bin/v-import-directadmin

@@ -58,8 +58,8 @@ delete_tmp() {
 
 # URL decoding function
 urldecode() {
-    local url_encoded="${1//+/ }"
-    printf '%b' "${url_encoded//%/\\x}"
+	local url_encoded="${1//+/ }"
+	printf '%b' "${url_encoded//%/\\x}"
 }
 
 tput setaf 3
@@ -184,7 +184,7 @@ echo "Start with databases"
 tput sgr0
 
 echo "Get local databases"
-mysql -e "SHOW DATABASES" > server_dbs
+mysql -e "SHOW DATABASES" >server_dbs
 da_db_list=$(ls -1 backup/ | grep ".conf")
 function run_da_db() {
 	for da_db in $da_db_list; do
@@ -203,16 +203,16 @@ function run_da_db() {
 				mysql -e "CREATE DATABASE $db"
 
 				# Preprocess the SQL file to remove problematic lines: https://jira.mariadb.org/browse/MDEV-34203
-				grep -vE '^/\*!(999999\\-)' "backup/${database_name}.sql" > "backup/${database_name}_processed.sql" 2>/dev/null
+				grep -vE '^/\*!(999999\\-)' "backup/${database_name}.sql" >"backup/${database_name}_processed.sql" 2>/dev/null
 
 				# Import the preprocessed SQL file with --force to ignore errors and continue
-				mysql --force "${db}" < "backup/${database_name}_processed.sql"
+				mysql --force "${db}" <"backup/${database_name}_processed.sql"
 
 				if [ $? -ne 0 ]; then
-				    tput setaf 1
-				    echo "Error importing database $db"
-				    tput sgr0
-				    continue
+					tput setaf 1
+					echo "Error importing database $db"
+					tput sgr0
+					continue
 				fi
 
 				# Get all the users of the database
@@ -227,9 +227,9 @@ function run_da_db() {
 						echo "udb: $db_user"
 						echo "Password: ${md5}"
 
-						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
+						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
 					fi
-				done < "backup/${da_db}"
+				done <"backup/${da_db}"
 
 				# Leave Hestia to restore passwords and create users
 				tput setaf 2
@@ -274,13 +274,13 @@ for directadmin_domain in $directadmin_domain_list; do
 		tput sgr0
 	elif [ -d /home/"${directadmin_user}"/web/"${directadmin_domain}" ]; then
 		echo "Domain $directadmin_domain added, restoring files"
-		echo "$directadmin_domain" >> restored_domains
+		echo "$directadmin_domain" >>restored_domains
 		rm -f /home/"$directadmin_user"/web/"$directadmin_domain"/public_html/index.html
 		rm -f /home/"$directadmin_user"/web/"$directadmin_domain"/public_html/robots.txt
 
 		public_sync_count=0
-		rsync -av domains/"${directadmin_domain}"/public_html/ /home/"$directadmin_user"/web/"$directadmin_domain"/public_html 2>&1 \
-			| while read file_dm; do
+		rsync -av domains/"${directadmin_domain}"/public_html/ /home/"$directadmin_user"/web/"$directadmin_domain"/public_html 2>&1 |
+			while read file_dm; do
 				public_sync_count=$(($public_sync_count + 1))
 				echo -en "-- $public_sync_count restored files\r"
 			done
@@ -293,8 +293,8 @@ for directadmin_domain in $directadmin_domain_list; do
 		else
 			private_sync_count=0
 
-			rsync -av domains/"${directadmin_domain}"/private_html/ /home/"$directadmin_user"/web/"$directadmin_domain"/private 2>&1 \
-				| while read file_dm; do
+			rsync -av domains/"${directadmin_domain}"/private_html/ /home/"$directadmin_user"/web/"$directadmin_domain"/private 2>&1 |
+				while read file_dm; do
 					private_sync_count=$(($private_sync_count + 1))
 					echo -en "-- $private_sync_count restored files\r"
 				done
@@ -334,8 +334,8 @@ if [ -e restored_domains ]; then
 				tmp_pass=$(generate_password)
 				"$BIN"/v-add-mail-account "$directadmin_user" "$da_mail_domain" "$da_imap" "$tmp_pass"
 				if [ "$debug" != 0 ]; then
-					rsync -av imap/"${da_mail_domain}"/"${da_imap}"/Maildir/ /home/"${directadmin_user}"/mail/"${da_mail_domain}"/"${da_imap}" 2>&1 \
-						| while read backup_file_dm; do
+					rsync -av imap/"${da_mail_domain}"/"${da_imap}"/Maildir/ /home/"${directadmin_user}"/mail/"${da_mail_domain}"/"${da_imap}" 2>&1 |
+						while read backup_file_dm; do
 							sk_sync=$((sk_sync + 1))
 							echo -en "-- $sk_sync restored files\r"
 						done
@@ -361,40 +361,40 @@ tput sgr0
 
 # Restore cron jobs
 if [ -f "backup/crontab.conf" ]; then
-    while IFS= read -r cron_line; do
-        # Skip empty lines and comments
-        [[ -z "$cron_line" || "$cron_line" =~ ^#.*$ ]] && continue
-
-        # Check if the line is an environment variable
-        if [[ "$cron_line" =~ ^[A-Z]+= ]]; then
-            # Export environment variable
-            # echo "Setting environment variable: $cron_line"
-            export "$cron_line"
-            continue
-        fi
-
-        # Remove the cron job identifier and extract cron job details
-        if [[ "$cron_line" =~ ^[0-9]+= ]]; then
-            cron_line=${cron_line#*=}
-        fi
-
-        # Extract cron job details (handle cases where command contains spaces)
-        IFS=' ' read -r min hour day month wday command <<< "$cron_line"
-
-        # Ensure it is a valid cron job line
-        if ! [[ "$min" =~ ^[\*0-9,-/]+$ && "$hour" =~ ^[\*0-9,-/]+$ && "$day" =~ ^[\*0-9,-/]+$ && "$month" =~ ^[\*0-9,-/]+$ && "$wday" =~ ^[\*0-9,-/]+$ ]]; then
-            echo "Invalid cron job format: $cron_line"
-            continue
-        fi
-
-        # Reconstruct the command part
-        command="${cron_line#"${min}" "${hour}" "${day}" "${month}" "${wday}" }"
-
-        echo "Adding cron job for user $directadmin_user: $cron_line"
-        "$BIN"/v-add-cron-job "$directadmin_user" "$min" "$hour" "$day" "$month" "$wday" "$command"
-    done < "backup/crontab.conf"
+	while IFS= read -r cron_line; do
+		# Skip empty lines and comments
+		[[ -z "$cron_line" || "$cron_line" =~ ^#.*$ ]] && continue
+
+		# Check if the line is an environment variable
+		if [[ "$cron_line" =~ ^[A-Z]+= ]]; then
+			# Export environment variable
+			# echo "Setting environment variable: $cron_line"
+			export "$cron_line"
+			continue
+		fi
+
+		# Remove the cron job identifier and extract cron job details
+		if [[ "$cron_line" =~ ^[0-9]+= ]]; then
+			cron_line=${cron_line#*=}
+		fi
+
+		# Extract cron job details (handle cases where command contains spaces)
+		IFS=' ' read -r min hour day month wday command <<<"$cron_line"
+
+		# Ensure it is a valid cron job line
+		if ! [[ "$min" =~ ^[\*0-9,-/]+$ && "$hour" =~ ^[\*0-9,-/]+$ && "$day" =~ ^[\*0-9,-/]+$ && "$month" =~ ^[\*0-9,-/]+$ && "$wday" =~ ^[\*0-9,-/]+$ ]]; then
+			echo "Invalid cron job format: $cron_line"
+			continue
+		fi
+
+		# Reconstruct the command part
+		command="${cron_line#"${min}" "${hour}" "${day}" "${month}" "${wday}" }"
+
+		echo "Adding cron job for user $directadmin_user: $cron_line"
+		"$BIN"/v-add-cron-job "$directadmin_user" "$min" "$hour" "$day" "$month" "$wday" "$command"
+	done <"backup/crontab.conf"
 else
-    echo "No cron jobs found to restore."
+	echo "No cron jobs found to restore."
 fi
 
 tput setaf 3
@@ -407,29 +407,29 @@ tput sgr0
 domain_base_dir="backup"
 
 if [ -d "$domain_base_dir" ]; then
-    for domain_subdir in "$domain_base_dir"/*/; do
-        domain_pointers_file="$domain_subdir/domain.pointers"
-        if [ -f "$domain_pointers_file" ]; then
-            while IFS= read -r pointer_line; do
-                # Skip empty lines and comments
-                [[ -z "$pointer_line" || "$pointer_line" =~ ^#.*$ ]] && continue
-
-                # Extract alias and type
-                alias_domain=$(echo "$pointer_line" | cut -d'=' -f1)
-                alias_type=$(echo "$pointer_line" | awk -F'type=' '{print $2}')
-
-                if [[ "$alias_type" == "alias" || "$alias_type" == "pointer" ]]; then
-                    domain_name=$(basename "$domain_subdir")
-                    echo "Adding domain alias $alias_domain for user $directadmin_user on domain $domain_name"
-                    "$BIN"/v-add-web-domain-alias "$directadmin_user" "$domain_name" "$alias_domain" no
-                else
-                    echo "Skipping non-alias type for $alias_domain: $alias_type"
-                fi
-            done < "$domain_pointers_file"
-        fi
-    done
+	for domain_subdir in "$domain_base_dir"/*/; do
+		domain_pointers_file="$domain_subdir/domain.pointers"
+		if [ -f "$domain_pointers_file" ]; then
+			while IFS= read -r pointer_line; do
+				# Skip empty lines and comments
+				[[ -z "$pointer_line" || "$pointer_line" =~ ^#.*$ ]] && continue
+
+				# Extract alias and type
+				alias_domain=$(echo "$pointer_line" | cut -d'=' -f1)
+				alias_type=$(echo "$pointer_line" | awk -F'type=' '{print $2}')
+
+				if [[ "$alias_type" == "alias" || "$alias_type" == "pointer" ]]; then
+					domain_name=$(basename "$domain_subdir")
+					echo "Adding domain alias $alias_domain for user $directadmin_user on domain $domain_name"
+					"$BIN"/v-add-web-domain-alias "$directadmin_user" "$domain_name" "$alias_domain" no
+				else
+					echo "Skipping non-alias type for $alias_domain: $alias_type"
+				fi
+			done <"$domain_pointers_file"
+		fi
+	done
 else
-    echo "No domain directories found to restore."
+	echo "No domain directories found to restore."
 fi
 
 tput setaf 3
@@ -439,20 +439,20 @@ echo "#######################################"
 tput sgr0
 
 if [ "$letsencrypt_enable" = 1 ]; then
-    for directadmin_domain in $directadmin_domain_list; do
-        echo "Enabling Let's Encrypt for $directadmin_domain"
-        letsencrypt_output=$("$BIN"/v-add-letsencrypt-domain "$directadmin_user" "$directadmin_domain" '' yes 2>&1)
+	for directadmin_domain in $directadmin_domain_list; do
+		echo "Enabling Let's Encrypt for $directadmin_domain"
+		letsencrypt_output=$("$BIN"/v-add-letsencrypt-domain "$directadmin_user" "$directadmin_domain" '' yes 2>&1)
 		echo "$letsencrypt_output"
-        if echo "$letsencrypt_output" | grep -q "Error: mail domain"; then
-            echo "Error with Let's Encrypt: $letsencrypt_output"
-            echo "Retrying Let's Encrypt without mail domain for $directadmin_domain"
-            "$BIN"/v-add-letsencrypt-domain "$directadmin_user" "$directadmin_domain" '' no
-        else
-            echo "Let's Encrypt enabled for $directadmin_domain"
-        fi
-    done
+		if echo "$letsencrypt_output" | grep -q "Error: mail domain"; then
+			echo "Error with Let's Encrypt: $letsencrypt_output"
+			echo "Retrying Let's Encrypt without mail domain for $directadmin_domain"
+			"$BIN"/v-add-letsencrypt-domain "$directadmin_user" "$directadmin_domain" '' no
+		else
+			echo "Let's Encrypt enabled for $directadmin_domain"
+		fi
+	done
 else
-    echo "Let's Encrypt is not enabled for any domain."
+	echo "Let's Encrypt is not enabled for any domain."
 fi
 
 delete_tmp