parent
5e649d7cb1
commit
13b1c684ee
25
ct/2fauth.sh
25
ct/2fauth.sh
@ -24,21 +24,16 @@ function update_script() {
|
|||||||
check_container_storage
|
check_container_storage
|
||||||
check_container_resources
|
check_container_resources
|
||||||
|
|
||||||
# Check if installation is present | -f for file, -d for folder
|
|
||||||
if [[ ! -d "/opt/2fauth" ]]; then
|
if [[ ! -d "/opt/2fauth" ]]; then
|
||||||
msg_error "No ${APP} Installation Found!"
|
msg_error "No ${APP} Installation Found!"
|
||||||
exit
|
exit
|
||||||
fi
|
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) }')
|
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
|
if [[ "${RELEASE}" != "$(cat /opt/2fauth_version.txt)" ]] || [[ ! -f /opt/2fauth_version.txt ]]; then
|
||||||
msg_info "Updating $APP to ${RELEASE}"
|
msg_info "Updating $APP to ${RELEASE}"
|
||||||
|
|
||||||
$STD apt-get update
|
$STD apt-get update
|
||||||
$STD apt-get -y upgrade
|
$STD apt-get -y upgrade
|
||||||
|
|
||||||
# Creating Backup
|
|
||||||
msg_info "Creating Backup"
|
msg_info "Creating Backup"
|
||||||
mv "/opt/2fauth" "/opt/2fauth-backup"
|
mv "/opt/2fauth" "/opt/2fauth-backup"
|
||||||
if ! dpkg -l | grep -q 'php8.3'; then
|
if ! dpkg -l | grep -q 'php8.3'; then
|
||||||
@ -46,37 +41,24 @@ function update_script() {
|
|||||||
fi
|
fi
|
||||||
msg_ok "Backup Created"
|
msg_ok "Backup Created"
|
||||||
|
|
||||||
# Upgrade PHP
|
|
||||||
if ! dpkg -l | grep -q 'php8.3'; then
|
if ! dpkg -l | grep -q 'php8.3'; then
|
||||||
$STD apt-get install -y \
|
$STD apt-get install -y \
|
||||||
lsb-release \
|
lsb-release \
|
||||||
gpg
|
gnupg2
|
||||||
curl -fsSL https://packages.sury.org/php/apt.gpg | gpg --dearmor -o /usr/share/keyrings/deb.sury.org-php.gpg
|
PHP_VERSION="8.3" PHP_MODULE="common,ctype,fileinfo,fpm,mysql,cli" install_php
|
||||||
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}
|
|
||||||
sed -i 's/php8.2/php8.3/g' /etc/nginx/conf.d/2fauth.conf
|
sed -i 's/php8.2/php8.3/g' /etc/nginx/conf.d/2fauth.conf
|
||||||
fi
|
fi
|
||||||
|
fetch_and_deploy_gh_release "Bubka/2FAuth"
|
||||||
# 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"
|
|
||||||
mv "/opt/2fauth-backup/.env" "/opt/2fauth/.env"
|
mv "/opt/2fauth-backup/.env" "/opt/2fauth/.env"
|
||||||
mv "/opt/2fauth-backup/storage" "/opt/2fauth/storage"
|
mv "/opt/2fauth-backup/storage" "/opt/2fauth/storage"
|
||||||
cd "/opt/2fauth" || return
|
cd "/opt/2fauth" || return
|
||||||
|
|
||||||
chown -R www-data: "/opt/2fauth"
|
chown -R www-data: "/opt/2fauth"
|
||||||
chmod -R 755 "/opt/2fauth"
|
chmod -R 755 "/opt/2fauth"
|
||||||
|
|
||||||
export COMPOSER_ALLOW_SUPERUSER=1
|
export COMPOSER_ALLOW_SUPERUSER=1
|
||||||
$STD composer install --no-dev --prefer-source
|
$STD composer install --no-dev --prefer-source
|
||||||
|
|
||||||
php artisan 2fauth:install
|
php artisan 2fauth:install
|
||||||
|
|
||||||
$STD systemctl restart nginx
|
$STD systemctl restart nginx
|
||||||
|
|
||||||
# Cleaning up
|
|
||||||
msg_info "Cleaning Up"
|
msg_info "Cleaning Up"
|
||||||
rm -rf "v${RELEASE}.zip"
|
rm -rf "v${RELEASE}.zip"
|
||||||
if dpkg -l | grep -q 'php8.2'; then
|
if dpkg -l | grep -q 'php8.2'; then
|
||||||
@ -86,7 +68,6 @@ function update_script() {
|
|||||||
$STD apt-get -y autoclean
|
$STD apt-get -y autoclean
|
||||||
msg_ok "Cleanup Completed"
|
msg_ok "Cleanup Completed"
|
||||||
|
|
||||||
# Last Action
|
|
||||||
echo "${RELEASE}" >/opt/2fauth_version.txt
|
echo "${RELEASE}" >/opt/2fauth_version.txt
|
||||||
msg_ok "Updated $APP to ${RELEASE}"
|
msg_ok "Updated $APP to ${RELEASE}"
|
||||||
else
|
else
|
||||||
|
@ -15,17 +15,12 @@ update_os
|
|||||||
|
|
||||||
msg_info "Installing Dependencies"
|
msg_info "Installing Dependencies"
|
||||||
$STD apt-get install -y \
|
$STD apt-get install -y \
|
||||||
lsb-release
|
lsb-release \
|
||||||
curl -fsSL https://packages.sury.org/php/apt.gpg | gpg --dearmor -o /usr/share/keyrings/deb.sury.org-php.gpg
|
nginx
|
||||||
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}
|
|
||||||
msg_ok "Installed Dependencies"
|
msg_ok "Installed Dependencies"
|
||||||
|
|
||||||
|
PHP_VERSION="8.3" PHP_MODULE="common,ctype,fileinfo,fpm,mysql,cli" install_php
|
||||||
|
install_composer
|
||||||
install_mariadb
|
install_mariadb
|
||||||
|
|
||||||
msg_info "Setting up Database"
|
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
|
} >>~/2FAuth.creds
|
||||||
msg_ok "Set up Database"
|
msg_ok "Set up Database"
|
||||||
|
|
||||||
msg_info "Setup 2FAuth"
|
fetch_and_deploy_gh_release "Bubka/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
|
|
||||||
|
|
||||||
cd "/opt/2fauth" || return
|
msg_info "Setup 2FAuth"
|
||||||
|
cd /opt/2fauth
|
||||||
cp .env.example .env
|
cp .env.example .env
|
||||||
IPADDRESS=$(hostname -I | awk '{print $1}')
|
IPADDRESS=$(hostname -I | awk '{print $1}')
|
||||||
|
|
||||||
sed -i -e "s|^APP_URL=.*|APP_URL=http://$IPADDRESS|" \
|
sed -i -e "s|^APP_URL=.*|APP_URL=http://$IPADDRESS|" \
|
||||||
-e "s|^DB_CONNECTION=$|DB_CONNECTION=mysql|" \
|
-e "s|^DB_CONNECTION=$|DB_CONNECTION=mysql|" \
|
||||||
-e "s|^DB_DATABASE=$|DB_DATABASE=$DB_NAME|" \
|
-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_PORT=$|DB_PORT=3306|" \
|
||||||
-e "s|^DB_USERNAME=$|DB_USERNAME=$DB_USER|" \
|
-e "s|^DB_USERNAME=$|DB_USERNAME=$DB_USER|" \
|
||||||
-e "s|^DB_PASSWORD=$|DB_PASSWORD=$DB_PASS|" .env
|
-e "s|^DB_PASSWORD=$|DB_PASSWORD=$DB_PASS|" .env
|
||||||
|
|
||||||
export COMPOSER_ALLOW_SUPERUSER=1
|
export COMPOSER_ALLOW_SUPERUSER=1
|
||||||
$STD composer update --no-plugins --no-scripts
|
$STD composer update --no-plugins --no-scripts
|
||||||
$STD composer install --no-dev --prefer-source --no-plugins --no-scripts
|
$STD composer install --no-dev --prefer-source --no-plugins --no-scripts
|
||||||
|
|
||||||
$STD php artisan key:generate --force
|
$STD php artisan key:generate --force
|
||||||
|
|
||||||
$STD php artisan migrate:refresh
|
$STD php artisan migrate:refresh
|
||||||
$STD php artisan passport:install -q -n
|
$STD php artisan passport:install -q -n
|
||||||
$STD php artisan storage:link
|
$STD php artisan storage:link
|
||||||
$STD php artisan config:cache
|
$STD php artisan config:cache
|
||||||
|
|
||||||
chown -R www-data: /opt/2fauth
|
chown -R www-data: /opt/2fauth
|
||||||
chmod -R 755 /opt/2fauth
|
chmod -R 755 /opt/2fauth
|
||||||
|
|
||||||
echo "${RELEASE}" >"/opt/2fauth_version.txt"
|
|
||||||
msg_ok "Setup 2fauth"
|
msg_ok "Setup 2fauth"
|
||||||
|
|
||||||
msg_info "Configure Service"
|
msg_info "Configure Service"
|
||||||
@ -107,7 +92,6 @@ server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
systemctl reload nginx
|
systemctl reload nginx
|
||||||
msg_ok "Configured Service"
|
msg_ok "Configured Service"
|
||||||
|
|
||||||
@ -115,7 +99,6 @@ motd_ssh
|
|||||||
customize
|
customize
|
||||||
|
|
||||||
msg_info "Cleaning up"
|
msg_info "Cleaning up"
|
||||||
rm -f "/opt/v${RELEASE}.zip"
|
|
||||||
$STD apt-get -y autoremove
|
$STD apt-get -y autoremove
|
||||||
$STD apt-get -y autoclean
|
$STD apt-get -y autoclean
|
||||||
msg_ok "Cleaned"
|
msg_ok "Cleaned"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user