Refactor: 2FAuth (#5184)

* Refactor: 2fauth

* Update
This commit is contained in:
Slaviša Arežina
2025-06-16 17:00:14 +02:00
committed by GitHub
parent 5e649d7cb1
commit 13b1c684ee
2 changed files with 10 additions and 46 deletions

View File

@ -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