From 13eefff926a511cfcc5663efc030b15e28623d74 Mon Sep 17 00:00:00 2001
From: Pinga <121483313+getpinga@users.noreply.github.com>
Date: Thu, 5 Sep 2024 18:57:55 +0300
Subject: [PATCH] Added update script from 1.0.3 and also fixed issue with
installer
---
cp/resources/views/partials/footer.twig | 2 +-
docs/install.sh | 15 +--
docs/update104.sh | 126 ++++++++++++++++++++++++
3 files changed, 131 insertions(+), 12 deletions(-)
create mode 100644 docs/update104.sh
diff --git a/cp/resources/views/partials/footer.twig b/cp/resources/views/partials/footer.twig
index d797512..5095fd2 100644
--- a/cp/resources/views/partials/footer.twig
+++ b/cp/resources/views/partials/footer.twig
@@ -14,7 +14,7 @@
Namingo
- v1.0.3
+ v1.0.4
diff --git a/docs/install.sh b/docs/install.sh
index 3ff1672..5bf9dc5 100644
--- a/docs/install.sh
+++ b/docs/install.sh
@@ -138,7 +138,7 @@ if [[ ("$OS" == "Ubuntu" && "$VER" == "22.04") || ("$OS" == "Ubuntu" && "$VER" =
systemctl restart php8.2-fpm
fi
echo "PHP configuration update complete!"
-
+
#if [ "$DB_TYPE" == "MariaDB" ]; then
echo "Setting up MariaDB..."
curl -o /etc/apt/keyrings/mariadb-keyring.pgp 'https://mariadb.org/mariadb_release_signing_key.pgp'
@@ -156,18 +156,11 @@ if [[ ("$OS" == "Ubuntu" && "$VER" == "22.04") || ("$OS" == "Ubuntu" && "$VER" =
Components: main main/debug
Signed-By: /etc/apt/keyrings/mariadb-keyring.pgp
EOF
- elif [[ "$OS" == "Ubuntu" && "$VER" == "24.04" ]]; then
- cat > /etc/apt/sources.list.d/mariadb.sources << EOF
+ elif [[ "$OS" == "Ubuntu" && "$VER" == "24.04" ]]; then
+ cat > /etc/apt/sources.list.d/mariadb.list << EOF
# MariaDB 11.4 repository list - created 2024-07-23 18:24 UTC
# https://mariadb.org/download/
- X-Repolib-Name: MariaDB
- Types: deb
- # deb.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details.
- # URIs: https://deb.mariadb.org/11.4/ubuntu
- URIs: https://fastmirror.pp.ua/mariadb/repo/11.4/ubuntu
- Suites: noble
- Components: main main/debug
- Signed-By: /etc/apt/keyrings/mariadb-keyring.pgp
+ deb [signed-by=/etc/apt/keyrings/mariadb-keyring.pgp] https://fastmirror.pp.ua/mariadb/repo/11.4/ubuntu noble main
EOF
else
cat > /etc/apt/sources.list.d/mariadb.sources << EOF
diff --git a/docs/update104.sh b/docs/update104.sh
new file mode 100644
index 0000000..601aff0
--- /dev/null
+++ b/docs/update104.sh
@@ -0,0 +1,126 @@
+#!/bin/bash
+
+# Prompt the user for confirmation
+echo "This will update Namingo Registry from v1.0.3 to v1.0.4."
+echo "Make sure you have a backup of the database, /var/www/cp, and /opt/registry."
+read -p "Are you sure you want to proceed? (y/n): " confirm
+
+# Check user input
+if [[ "$confirm" != "y" ]]; then
+ echo "Upgrade aborted."
+ exit 0
+fi
+
+# Create backup directory
+backup_dir="/opt/backup"
+mkdir -p "$backup_dir"
+
+# Backup directories
+echo "Creating backups..."
+tar -czf "$backup_dir/cp_backup_$(date +%F).tar.gz" -C / var/www/cp
+tar -czf "$backup_dir/whois_backup_$(date +%F).tar.gz" -C / var/www/whois
+tar -czf "$backup_dir/registry_backup_$(date +%F).tar.gz" -C / opt/registry
+
+# Database credentials
+config_file="/opt/registry/whois/port43/config.php"
+db_user=$(grep "'db_username'" "$config_file" | awk -F "=> '" '{print $2}' | sed "s/',//")
+db_pass=$(grep "'db_password'" "$config_file" | awk -F "=> '" '{print $2}' | sed "s/',//")
+db_host=$(grep "'db_host'" "$config_file" | awk -F "=> '" '{print $2}' | sed "s/',//")
+
+# List of databases to back up
+databases=("registry" "registryAudit" "registryTransaction")
+
+# Backup specific databases
+for db_name in "${databases[@]}"; do
+ echo "Backing up database $db_name..."
+ sql_backup_file="$backup_dir/db_${db_name}_backup_$(date +%F).sql"
+ mysqldump -u"$db_user" -p"$db_pass" -h"$db_host" "$db_name" > "$sql_backup_file"
+
+ # Compress the SQL backup file
+ echo "Compressing database backup $db_name..."
+ tar -czf "${sql_backup_file}.tar.gz" -C "$backup_dir" "$(basename "$sql_backup_file")"
+
+ # Remove the uncompressed SQL file
+ rm "$sql_backup_file"
+done
+
+# Stop services
+echo "Stopping services..."
+systemctl stop caddy
+systemctl stop epp
+systemctl stop whois
+systemctl stop rdap
+systemctl stop das
+
+# Clear cache
+echo "Clearing cache..."
+php /var/www/cp/bin/clear_cache.php
+
+# Clone the new version of the repository
+echo "Cloning v1.0.4 from the repository..."
+git clone --branch v1.0.4 --single-branch https://github.com/getnamingo/registry /opt/registry104
+
+# Copy files from the new version to the appropriate directories
+echo "Copying files..."
+
+# Function to copy files and maintain directory structure
+copy_files() {
+ src_dir=$1
+ dest_dir=$2
+
+ if [[ -d "$src_dir" ]]; then
+ echo "Copying from $src_dir to $dest_dir..."
+ cp -R "$src_dir/." "$dest_dir/"
+ else
+ echo "Source directory $src_dir does not exist. Skipping..."
+ fi
+}
+
+# Copy specific directories
+copy_files "/opt/registry104/automation" "/opt/registry/automation"
+copy_files "/opt/registry104/cp" "/var/www/cp"
+copy_files "/opt/registry104/whois/web" "/var/www/whois"
+#copy_files "/opt/registry104/das" "/opt/registry/das"
+#copy_files "/opt/registry104/whois/port43" "/opt/registry/whois/port43"
+#copy_files "/opt/registry104/rdap" "/opt/registry/rdap"
+copy_files "/opt/registry104/epp" "/opt/registry/epp"
+copy_files "/opt/registry104/docs" "/opt/registry/docs"
+
+# Run composer update in copied directories (excluding docs)
+echo "Running composer update..."
+
+composer_update() {
+ dir=$1
+ if [[ -d "$dir" ]]; then
+ echo "Updating composer in $dir..."
+ cd "$dir" && composer update
+ else
+ echo "Directory $dir does not exist. Skipping composer update..."
+ fi
+}
+
+# Update composer in relevant directories
+composer_update "/opt/registry/automation"
+composer_update "/var/www/cp"
+#composer_update "/opt/registry/das"
+#composer_update "/opt/registry/whois/port43"
+#composer_update "/opt/registry/rdap"
+composer_update "/opt/registry/epp"
+
+# Start services
+echo "Starting services..."
+systemctl start epp
+systemctl start whois
+systemctl start rdap
+systemctl start das
+systemctl start caddy
+
+# Check if services started successfully
+if [[ $? -eq 0 ]]; then
+ echo "Services started successfully. Deleting /opt/registry104..."
+ rm -rf /opt/registry104
+else
+ echo "There was an issue starting the services. /opt/registry104 will not be deleted."
+fi
+
+echo "Upgrade to v1.0.4 completed successfully."