From 13b1c684eea3e2ce46d50a5eafc5e6f28ae75dbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Slavi=C5=A1a=20Are=C5=BEina?= <58952836+tremor021@users.noreply.github.com> Date: Mon, 16 Jun 2025 17:00:14 +0200 Subject: [PATCH] Refactor: 2FAuth (#5184) * Refactor: 2fauth * Update --- ct/2fauth.sh | 25 +++---------------------- install/2fauth-install.sh | 31 +++++++------------------------ 2 files changed, 10 insertions(+), 46 deletions(-) diff --git a/ct/2fauth.sh b/ct/2fauth.sh index 9dc9fc5419..f16c854fb0 100644 --- a/ct/2fauth.sh +++ b/ct/2fauth.sh @@ -24,21 +24,16 @@ function update_script() { check_container_storage check_container_resources - # Check if installation is present | -f for file, -d for folder if [[ ! -d "/opt/2fauth" ]]; then msg_error "No ${APP} Installation Found!" exit fi - - # Crawling the new version and checking whether an update is required RELEASE=$(curl -fsSL https://api.github.com/repos/Bubka/2FAuth/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }') if [[ "${RELEASE}" != "$(cat /opt/2fauth_version.txt)" ]] || [[ ! -f /opt/2fauth_version.txt ]]; then msg_info "Updating $APP to ${RELEASE}" - $STD apt-get update $STD apt-get -y upgrade - # Creating Backup msg_info "Creating Backup" mv "/opt/2fauth" "/opt/2fauth-backup" if ! dpkg -l | grep -q 'php8.3'; then @@ -46,37 +41,24 @@ function update_script() { fi msg_ok "Backup Created" - # Upgrade PHP if ! dpkg -l | grep -q 'php8.3'; then $STD apt-get install -y \ lsb-release \ - gpg - curl -fsSL https://packages.sury.org/php/apt.gpg | gpg --dearmor -o /usr/share/keyrings/deb.sury.org-php.gpg - echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" >/etc/apt/sources.list.d/php.list - $STD apt-get update - $STD apt-get install -y php8.3-{bcmath,common,ctype,curl,fileinfo,fpm,gd,mbstring,mysql,xml,cli,intl} + gnupg2 + PHP_VERSION="8.3" PHP_MODULE="common,ctype,fileinfo,fpm,mysql,cli" install_php sed -i 's/php8.2/php8.3/g' /etc/nginx/conf.d/2fauth.conf fi - - # Execute Update - curl -fsSL -o "${RELEASE}.zip" "https://github.com/Bubka/2FAuth/archive/refs/tags/${RELEASE}.zip" - $STD unzip "${RELEASE}.zip" - mv "2FAuth-${RELEASE//v/}/" "/opt/2fauth" + fetch_and_deploy_gh_release "Bubka/2FAuth" mv "/opt/2fauth-backup/.env" "/opt/2fauth/.env" mv "/opt/2fauth-backup/storage" "/opt/2fauth/storage" cd "/opt/2fauth" || return - chown -R www-data: "/opt/2fauth" chmod -R 755 "/opt/2fauth" - export COMPOSER_ALLOW_SUPERUSER=1 $STD composer install --no-dev --prefer-source - php artisan 2fauth:install - $STD systemctl restart nginx - # Cleaning up msg_info "Cleaning Up" rm -rf "v${RELEASE}.zip" if dpkg -l | grep -q 'php8.2'; then @@ -86,7 +68,6 @@ function update_script() { $STD apt-get -y autoclean msg_ok "Cleanup Completed" - # Last Action echo "${RELEASE}" >/opt/2fauth_version.txt msg_ok "Updated $APP to ${RELEASE}" else diff --git a/install/2fauth-install.sh b/install/2fauth-install.sh index f32f554575..291d52ca16 100644 --- a/install/2fauth-install.sh +++ b/install/2fauth-install.sh @@ -15,17 +15,12 @@ update_os msg_info "Installing Dependencies" $STD apt-get install -y \ - lsb-release -curl -fsSL https://packages.sury.org/php/apt.gpg | gpg --dearmor -o /usr/share/keyrings/deb.sury.org-php.gpg -echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" >/etc/apt/sources.list.d/php.list -$STD apt-get update - -$STD apt-get install -y \ - nginx \ - composer \ - php8.3-{bcmath,common,ctype,curl,fileinfo,fpm,gd,intl,mbstring,mysql,xml,cli} + lsb-release \ + nginx msg_ok "Installed Dependencies" +PHP_VERSION="8.3" PHP_MODULE="common,ctype,fileinfo,fpm,mysql,cli" install_php +install_composer install_mariadb msg_info "Setting up Database" @@ -43,16 +38,12 @@ $STD mariadb -u root -e "GRANT ALL ON $DB_NAME.* TO '$DB_USER'@'localhost'; FLUS } >>~/2FAuth.creds msg_ok "Set up Database" -msg_info "Setup 2FAuth" -RELEASE=$(curl -fsSL https://api.github.com/repos/Bubka/2FAuth/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }') -curl -fsSL "https://github.com/Bubka/2FAuth/archive/refs/tags/${RELEASE}.zip" -o "${RELEASE}.zip" -$STD unzip "${RELEASE}.zip" -mv "2FAuth-${RELEASE//v/}/" /opt/2fauth +fetch_and_deploy_gh_release "Bubka/2FAuth" -cd "/opt/2fauth" || return +msg_info "Setup 2FAuth" +cd /opt/2fauth cp .env.example .env IPADDRESS=$(hostname -I | awk '{print $1}') - sed -i -e "s|^APP_URL=.*|APP_URL=http://$IPADDRESS|" \ -e "s|^DB_CONNECTION=$|DB_CONNECTION=mysql|" \ -e "s|^DB_DATABASE=$|DB_DATABASE=$DB_NAME|" \ @@ -60,22 +51,16 @@ sed -i -e "s|^APP_URL=.*|APP_URL=http://$IPADDRESS|" \ -e "s|^DB_PORT=$|DB_PORT=3306|" \ -e "s|^DB_USERNAME=$|DB_USERNAME=$DB_USER|" \ -e "s|^DB_PASSWORD=$|DB_PASSWORD=$DB_PASS|" .env - export COMPOSER_ALLOW_SUPERUSER=1 $STD composer update --no-plugins --no-scripts $STD composer install --no-dev --prefer-source --no-plugins --no-scripts - $STD php artisan key:generate --force - $STD php artisan migrate:refresh $STD php artisan passport:install -q -n $STD php artisan storage:link $STD php artisan config:cache - chown -R www-data: /opt/2fauth chmod -R 755 /opt/2fauth - -echo "${RELEASE}" >"/opt/2fauth_version.txt" msg_ok "Setup 2fauth" msg_info "Configure Service" @@ -107,7 +92,6 @@ server { } } EOF - systemctl reload nginx msg_ok "Configured Service" @@ -115,7 +99,6 @@ motd_ssh customize msg_info "Cleaning up" -rm -f "/opt/v${RELEASE}.zip" $STD apt-get -y autoremove $STD apt-get -y autoclean msg_ok "Cleaned"