Skip to content

Commit 16b8c40

Browse files
committed
Added update script, fixed #15
1 parent f714e6c commit 16b8c40

1 file changed

Lines changed: 114 additions & 0 deletions

File tree

update.sh

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/bin/bash
2+
3+
# Prompt the user for confirmation
4+
echo "This will update Namingo Registrar from v1.0.0/v1.0.1 to v1.0.2."
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.2 from the repository..."
54+
git clone https://github.com/getnamingo/registrar /opt/registrar102
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/registrar102/automation" "/opt/registrar/automation"
74+
copy_files "/opt/registrar102/whois" "/opt/registrar/whois"
75+
copy_files "/opt/registrar102/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+
# Start services
96+
echo "Starting services..."
97+
systemctl start nginx
98+
systemctl start whois
99+
systemctl start rdap
100+
101+
# Check if services started successfully
102+
if [[ $? -eq 0 ]]; then
103+
echo "Services started successfully. Deleting /opt/registrar102..."
104+
rm -rf /opt/registrar102
105+
else
106+
echo "There was an issue starting the services. /opt/registrar102 will not be deleted."
107+
fi
108+
109+
# Final instructions to the user
110+
echo "Upgrade to v1.0.2 is almost complete. Please follow the final step below to finish the process:"
111+
echo
112+
echo "1. Open your browser and log in to the admin panel."
113+
echo "2. Navigate to System -> Update to apply the changes."
114+
echo

0 commit comments

Comments
 (0)