1+ #! /bin/bash
2+
3+ # Prompt the user for confirmation
4+ echo " This will update Namingo Registrar from v1.0.3 to v1.0.4."
5+ echo " Make sure you have a backup of the database, /var/www, and /opt/registrar."
6+ read -p " Are you sure you want to proceed? (y/n): " confirm
7+
8+ # Check user input
9+ if [[ " $confirm " != " y" ]]; then
10+ echo " Upgrade aborted."
11+ exit 0
12+ fi
13+
14+ # Create backup directory
15+ backup_dir=" /opt/backup"
16+ mkdir -p " $backup_dir "
17+
18+ # Backup directories
19+ echo " Creating backups..."
20+ tar -czf " $backup_dir /panel_backup_$( date +%F) .tar.gz" -C / var/www
21+ tar -czf " $backup_dir /registrar_backup_$( date +%F) .tar.gz" -C / opt/registrar
22+
23+ # Database credentials
24+ config_file=" /opt/registrar/whois/config.php"
25+ db_user=$( grep " 'db_username'" " $config_file " | awk -F " => '" ' {print $2}' | sed " s/',//" )
26+ db_pass=$( grep " 'db_password'" " $config_file " | awk -F " => '" ' {print $2}' | sed " s/',//" )
27+ db_host=$( grep " 'db_host'" " $config_file " | awk -F " => '" ' {print $2}' | sed " s/',//" )
28+
29+ # List of databases to back up
30+ databases=(" registrar" )
31+
32+ # Backup specific databases
33+ for db_name in " ${databases[@]} " ; do
34+ echo " Backing up database $db_name ..."
35+ sql_backup_file=" $backup_dir /db_${db_name} _backup_$( date +%F) .sql"
36+ mysqldump -u" $db_user " -p" $db_pass " -h" $db_host " " $db_name " > " $sql_backup_file "
37+
38+ # Compress the SQL backup file
39+ echo " Compressing database backup $db_name ..."
40+ tar -czf " ${sql_backup_file} .tar.gz" -C " $backup_dir " " $( basename " $sql_backup_file " ) "
41+
42+ # Remove the uncompressed SQL file
43+ rm " $sql_backup_file "
44+ done
45+
46+ # Stop services
47+ echo " Stopping services..."
48+ systemctl stop nginx
49+ systemctl stop whois
50+ systemctl stop rdap
51+
52+ # Clone the new version of the repository
53+ echo " Cloning v1.0.4 from the repository..."
54+ git clone https://github.com/getnamingo/registrar /opt/registrar104
55+
56+ # Copy files from the new version to the appropriate directories
57+ echo " Copying files..."
58+
59+ # Function to copy files and maintain directory structure
60+ copy_files () {
61+ src_dir=$1
62+ dest_dir=$2
63+
64+ if [[ -d " $src_dir " ]]; then
65+ echo " Copying from $src_dir to $dest_dir ..."
66+ cp -R " $src_dir /." " $dest_dir /"
67+ else
68+ echo " Source directory $src_dir does not exist. Skipping..."
69+ fi
70+ }
71+
72+ # Copy specific directories
73+ copy_files " /opt/registrar104/automation" " /opt/registrar/automation"
74+ copy_files " /opt/registrar104/whois" " /opt/registrar/whois"
75+ copy_files " /opt/registrar104/rdap" " /opt/registrar/rdap"
76+
77+ # Run composer update in copied directories (excluding docs)
78+ echo " Running composer update..."
79+
80+ composer_update () {
81+ dir=$1
82+ if [[ -d " $dir " ]]; then
83+ echo " Updating composer in $dir ..."
84+ cd " $dir " && composer update
85+ else
86+ echo " Directory $dir does not exist. Skipping composer update..."
87+ fi
88+ }
89+
90+ # Update composer in relevant directories
91+ composer_update " /opt/registrar/automation"
92+ composer_update " /opt/registrar/whois"
93+ composer_update " /opt/registrar/rdap"
94+
95+ git clone https://github.com/getnamingo/fossbilling-contact
96+ mv fossbilling-contact/Contact /var/www/modules/
97+
98+ # Start services
99+ echo " Starting services..."
100+ systemctl start nginx
101+ systemctl start whois
102+ systemctl start rdap
103+
104+ # Check if services started successfully
105+ if [[ $? -eq 0 ]]; then
106+ echo " Services started successfully. Deleting /opt/registrar104..."
107+ rm -rf /opt/registrar104
108+ else
109+ echo " There was an issue starting the services. /opt/registrar104 will not be deleted."
110+ fi
111+
112+ # Final instructions to the user
113+ echo " Upgrade to v1.0.4 is almost complete. Please follow the final step below to finish the process:"
114+ echo
115+ echo " 1. Open your browser and log in to the admin panel."
116+ echo " 2. Navigate to System -> Update to apply the changes."
117+ echo
0 commit comments