Skip to content

Commit 13b1c68

Browse files
authored
Refactor: 2FAuth (#5184)
* Refactor: 2fauth * Update
1 parent 5e649d7 commit 13b1c68

File tree

2 files changed

+10
-46
lines changed

2 files changed

+10
-46
lines changed

ct/2fauth.sh

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,59 +24,41 @@ function update_script() {
2424
check_container_storage
2525
check_container_resources
2626

27-
# Check if installation is present | -f for file, -d for folder
2827
if [[ ! -d "/opt/2fauth" ]]; then
2928
msg_error "No ${APP} Installation Found!"
3029
exit
3130
fi
32-
33-
# Crawling the new version and checking whether an update is required
3431
RELEASE=$(curl -fsSL https://api.github.com/repos/Bubka/2FAuth/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }')
3532
if [[ "${RELEASE}" != "$(cat /opt/2fauth_version.txt)" ]] || [[ ! -f /opt/2fauth_version.txt ]]; then
3633
msg_info "Updating $APP to ${RELEASE}"
37-
3834
$STD apt-get update
3935
$STD apt-get -y upgrade
4036

41-
# Creating Backup
4237
msg_info "Creating Backup"
4338
mv "/opt/2fauth" "/opt/2fauth-backup"
4439
if ! dpkg -l | grep -q 'php8.3'; then
4540
cp /etc/nginx/conf.d/2fauth.conf /etc/nginx/conf.d/2fauth.conf.bak
4641
fi
4742
msg_ok "Backup Created"
4843

49-
# Upgrade PHP
5044
if ! dpkg -l | grep -q 'php8.3'; then
5145
$STD apt-get install -y \
5246
lsb-release \
53-
gpg
54-
curl -fsSL https://packages.sury.org/php/apt.gpg | gpg --dearmor -o /usr/share/keyrings/deb.sury.org-php.gpg
55-
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
56-
$STD apt-get update
57-
$STD apt-get install -y php8.3-{bcmath,common,ctype,curl,fileinfo,fpm,gd,mbstring,mysql,xml,cli,intl}
47+
gnupg2
48+
PHP_VERSION="8.3" PHP_MODULE="common,ctype,fileinfo,fpm,mysql,cli" install_php
5849
sed -i 's/php8.2/php8.3/g' /etc/nginx/conf.d/2fauth.conf
5950
fi
60-
61-
# Execute Update
62-
curl -fsSL -o "${RELEASE}.zip" "https://github.com/Bubka/2FAuth/archive/refs/tags/${RELEASE}.zip"
63-
$STD unzip "${RELEASE}.zip"
64-
mv "2FAuth-${RELEASE//v/}/" "/opt/2fauth"
51+
fetch_and_deploy_gh_release "Bubka/2FAuth"
6552
mv "/opt/2fauth-backup/.env" "/opt/2fauth/.env"
6653
mv "/opt/2fauth-backup/storage" "/opt/2fauth/storage"
6754
cd "/opt/2fauth" || return
68-
6955
chown -R www-data: "/opt/2fauth"
7056
chmod -R 755 "/opt/2fauth"
71-
7257
export COMPOSER_ALLOW_SUPERUSER=1
7358
$STD composer install --no-dev --prefer-source
74-
7559
php artisan 2fauth:install
76-
7760
$STD systemctl restart nginx
7861

79-
# Cleaning up
8062
msg_info "Cleaning Up"
8163
rm -rf "v${RELEASE}.zip"
8264
if dpkg -l | grep -q 'php8.2'; then
@@ -86,7 +68,6 @@ function update_script() {
8668
$STD apt-get -y autoclean
8769
msg_ok "Cleanup Completed"
8870

89-
# Last Action
9071
echo "${RELEASE}" >/opt/2fauth_version.txt
9172
msg_ok "Updated $APP to ${RELEASE}"
9273
else

install/2fauth-install.sh

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,12 @@ update_os
1515

1616
msg_info "Installing Dependencies"
1717
$STD apt-get install -y \
18-
lsb-release
19-
curl -fsSL https://packages.sury.org/php/apt.gpg | gpg --dearmor -o /usr/share/keyrings/deb.sury.org-php.gpg
20-
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
21-
$STD apt-get update
22-
23-
$STD apt-get install -y \
24-
nginx \
25-
composer \
26-
php8.3-{bcmath,common,ctype,curl,fileinfo,fpm,gd,intl,mbstring,mysql,xml,cli}
18+
lsb-release \
19+
nginx
2720
msg_ok "Installed Dependencies"
2821

22+
PHP_VERSION="8.3" PHP_MODULE="common,ctype,fileinfo,fpm,mysql,cli" install_php
23+
install_composer
2924
install_mariadb
3025

3126
msg_info "Setting up Database"
@@ -43,39 +38,29 @@ $STD mariadb -u root -e "GRANT ALL ON $DB_NAME.* TO '$DB_USER'@'localhost'; FLUS
4338
} >>~/2FAuth.creds
4439
msg_ok "Set up Database"
4540

46-
msg_info "Setup 2FAuth"
47-
RELEASE=$(curl -fsSL https://api.github.com/repos/Bubka/2FAuth/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }')
48-
curl -fsSL "https://github.com/Bubka/2FAuth/archive/refs/tags/${RELEASE}.zip" -o "${RELEASE}.zip"
49-
$STD unzip "${RELEASE}.zip"
50-
mv "2FAuth-${RELEASE//v/}/" /opt/2fauth
41+
fetch_and_deploy_gh_release "Bubka/2FAuth"
5142

52-
cd "/opt/2fauth" || return
43+
msg_info "Setup 2FAuth"
44+
cd /opt/2fauth
5345
cp .env.example .env
5446
IPADDRESS=$(hostname -I | awk '{print $1}')
55-
5647
sed -i -e "s|^APP_URL=.*|APP_URL=http://$IPADDRESS|" \
5748
-e "s|^DB_CONNECTION=$|DB_CONNECTION=mysql|" \
5849
-e "s|^DB_DATABASE=$|DB_DATABASE=$DB_NAME|" \
5950
-e "s|^DB_HOST=$|DB_HOST=127.0.0.1|" \
6051
-e "s|^DB_PORT=$|DB_PORT=3306|" \
6152
-e "s|^DB_USERNAME=$|DB_USERNAME=$DB_USER|" \
6253
-e "s|^DB_PASSWORD=$|DB_PASSWORD=$DB_PASS|" .env
63-
6454
export COMPOSER_ALLOW_SUPERUSER=1
6555
$STD composer update --no-plugins --no-scripts
6656
$STD composer install --no-dev --prefer-source --no-plugins --no-scripts
67-
6857
$STD php artisan key:generate --force
69-
7058
$STD php artisan migrate:refresh
7159
$STD php artisan passport:install -q -n
7260
$STD php artisan storage:link
7361
$STD php artisan config:cache
74-
7562
chown -R www-data: /opt/2fauth
7663
chmod -R 755 /opt/2fauth
77-
78-
echo "${RELEASE}" >"/opt/2fauth_version.txt"
7964
msg_ok "Setup 2fauth"
8065

8166
msg_info "Configure Service"
@@ -107,15 +92,13 @@ server {
10792
}
10893
}
10994
EOF
110-
11195
systemctl reload nginx
11296
msg_ok "Configured Service"
11397

11498
motd_ssh
11599
customize
116100

117101
msg_info "Cleaning up"
118-
rm -f "/opt/v${RELEASE}.zip"
119102
$STD apt-get -y autoremove
120103
$STD apt-get -y autoclean
121104
msg_ok "Cleaned"

0 commit comments

Comments
 (0)