Skip to content

Commit

Permalink
Faet: add mirzabot template
Browse files Browse the repository at this point in the history
  • Loading branch information
erfjab committed Sep 27, 2024
1 parent 11cc6e0 commit 0a2016f
Showing 1 changed file with 52 additions and 33 deletions.
85 changes: 52 additions & 33 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,30 +172,6 @@ manage_backups() {
clear
}

select_start_backup_type() {
clear
print "[TYPE]\n"
print "We offer two types of backup installers:\n"
print "1) Advanced - For more customization options."
print "2) Simple - For a quick and easy setup.\n"

while true; do
input "Enter your option number: " backup_type
case $backup_type in
1)
start_advenced_backup
;;
2)
start_simple_backup
;;
*)
error "Invalid option. Please select 1 for Simple or 2 for Advanced."
;;
esac
done
sleep 1
}

backup_template() {
clear
print "[TEMPLATE]\n"
Expand All @@ -204,6 +180,7 @@ backup_template() {
print "2) Marzban Logs"
print "3) All X-ui's"
print "4) Hiddify Manager"
print "5) Mirza Bot"
print "0) Custom"
print ""

Expand All @@ -227,6 +204,10 @@ backup_template() {
hiddify_template
break
;;
5)
mirzabot_template
break
;;
0)
success "You Chose Custom"
break
Expand All @@ -238,6 +219,39 @@ backup_template() {
done
}

mirzabot_template() {
log "Checking mirzabot backup..."
local mirzabot_file='/var/www/html/mirzabotconfig/config.php'

if [ ! -f "$mirzabot_file" ]; then
error "Backup file does not exist."
exit 1
else
success "$mirzabot_file Backup file exists."
fi

# Extract database values from config.php
dbname=$(grep -m 1 "\$dbname" $mirzabot_file | sed -E "s/.*dbname\s*=\s*'([^']+)'.*/\1/")
usernamedb=$(grep -m 1 "\$usernamedb" $mirzabot_file | sed -E "s/.*usernamedb\s*=\s*'([^']+)'.*/\1/")
passworddb=$(grep -m 1 "\$passworddb" $mirzabot_file | sed -E "s/.*passworddb\s*=\s*'([^']+)'.*/\1/")

# Check if the values are extracted correctly
if [ -z "$dbname" ] || [ -z "$usernamedb" ] || [ -z "$passworddb" ]; then
error "Failed to extract database values from $mirzabot_file."
exit 1
else
success "Database Name: $dbname"
success "Database Username: $usernamedb"
success "Database Password: $passworddb"

# Initialize the array if not already done
declare -gA mirza_database
mirza_database["$dbname"]="${dbname}:${usernamedb}:${passworddb}"
sleep 1
fi
}


hiddify_template() {
log "Checking hiddify backup..."
local hiddify_file="/opt/hiddify-manager/hiddify-panel/backup.sh"
Expand Down Expand Up @@ -416,15 +430,6 @@ backup_custom_dir() {
done
}

start_simple_backup() {
check_needs
backup_template
backup_name
backup_cronjob
send_to
backup_generate
}

start_advenced_backup() {
check_needs
backup_template
Expand Down Expand Up @@ -702,6 +707,20 @@ fi"
done
fi

if [ ${#mirza_database[@]} -gt 0 ]; then
for database in "${mirza_database[@]}"; do
IFS=':' read -r dbname usernamedb passworddb <<< "$database"
local db_address="/root/${name}_${dbname}_backuper.sql"
local dump_command="if ! mysqldump -u '${usernamedb}' -p'${passworddb}' '${dbname}' > '${db_address}'; then
message=\"Failed to backup database ${dbname}. Please check the server.\"
$send_notification_command
exit 1
fi"
DB+="${dump_command}\n"
directories+=("$db_address")
done
fi

local LOGS=""
if [ "$marzban_logs" = true ]; then
LOGS+="
Expand Down

0 comments on commit 0a2016f

Please sign in to comment.