|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright (c) 2021-2025 community-scripts ORG |
| 4 | +# Author: jkrgr0 |
| 5 | +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE |
| 6 | +# Source: https://docs.2fauth.app/ |
| 7 | + |
| 8 | +source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" |
| 9 | +color |
| 10 | +verb_ip6 |
| 11 | +catch_errors |
| 12 | +setting_up_container |
| 13 | +network_check |
| 14 | +update_os |
| 15 | + |
| 16 | +msg_info "Installing Dependencies" |
| 17 | +$STD apt-get install -y \ |
| 18 | + lsb-release \ |
| 19 | + nginx |
| 20 | +msg_ok "Installed Dependencies" |
| 21 | + |
| 22 | +PHP_VERSION="8.3" PHP_MODULE="common,ctype,fileinfo,mysql,cli" PHP_FPM="YES" setup_php |
| 23 | +setup_composer |
| 24 | +setup_mariadb |
| 25 | + |
| 26 | +msg_info "Setting up Database" |
| 27 | +DB_NAME=2fauth_db |
| 28 | +DB_USER=2fauth |
| 29 | +DB_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | head -c13) |
| 30 | +$STD mariadb -u root -e "CREATE DATABASE $DB_NAME;" |
| 31 | +$STD mariadb -u root -e "CREATE USER '$DB_USER'@'localhost' IDENTIFIED BY '$DB_PASS';" |
| 32 | +$STD mariadb -u root -e "GRANT ALL ON $DB_NAME.* TO '$DB_USER'@'localhost'; FLUSH PRIVILEGES;" |
| 33 | +{ |
| 34 | + echo "2FAuth Credentials" |
| 35 | + echo "Database User: $DB_USER" |
| 36 | + echo "Database Password: $DB_PASS" |
| 37 | + echo "Database Name: $DB_NAME" |
| 38 | +} >>~/2FAuth.creds |
| 39 | +msg_ok "Set up Database" |
| 40 | + |
| 41 | +fetch_and_deploy_gh_release "2fauth" "Bubka/2FAuth" |
| 42 | + |
| 43 | +msg_info "Setup 2FAuth" |
| 44 | +cd /opt/2fauth |
| 45 | +cp .env.example .env |
| 46 | +IPADDRESS=$(hostname -I | awk '{print $1}') |
| 47 | +sed -i -e "s|^APP_URL=.*|APP_URL=http://$IPADDRESS|" \ |
| 48 | + -e "s|^DB_CONNECTION=$|DB_CONNECTION=mysql|" \ |
| 49 | + -e "s|^DB_DATABASE=$|DB_DATABASE=$DB_NAME|" \ |
| 50 | + -e "s|^DB_HOST=$|DB_HOST=127.0.0.1|" \ |
| 51 | + -e "s|^DB_PORT=$|DB_PORT=3306|" \ |
| 52 | + -e "s|^DB_USERNAME=$|DB_USERNAME=$DB_USER|" \ |
| 53 | + -e "s|^DB_PASSWORD=$|DB_PASSWORD=$DB_PASS|" .env |
| 54 | +export COMPOSER_ALLOW_SUPERUSER=1 |
| 55 | +$STD composer update --no-plugins --no-scripts |
| 56 | +$STD composer install --no-dev --prefer-source --no-plugins --no-scripts |
| 57 | +$STD php artisan key:generate --force |
| 58 | +$STD php artisan migrate:refresh |
| 59 | +$STD php artisan passport:install -q -n |
| 60 | +$STD php artisan storage:link |
| 61 | +$STD php artisan config:cache |
| 62 | +chown -R www-data: /opt/2fauth |
| 63 | +chmod -R 755 /opt/2fauth |
| 64 | +msg_ok "Setup 2fauth" |
| 65 | + |
| 66 | +msg_info "Configure Service" |
| 67 | +cat <<EOF >/etc/nginx/conf.d/2fauth.conf |
| 68 | +server { |
| 69 | + listen 80; |
| 70 | + root /opt/2fauth/public; |
| 71 | + server_name $IPADDRESS; |
| 72 | + index index.php; |
| 73 | + charset utf-8; |
| 74 | +
|
| 75 | + location / { |
| 76 | + try_files \$uri \$uri/ /index.php?\$query_string; |
| 77 | + } |
| 78 | +
|
| 79 | + location = /favicon.ico { access_log off; log_not_found off; } |
| 80 | + location = /robots.txt { access_log off; log_not_found off; } |
| 81 | +
|
| 82 | + error_page 404 /index.php; |
| 83 | +
|
| 84 | + location ~ \.php\$ { |
| 85 | + fastcgi_pass unix:/var/run/php/php8.3-fpm.sock; |
| 86 | + fastcgi_param SCRIPT_FILENAME \$realpath_root\$fastcgi_script_name; |
| 87 | + include fastcgi_params; |
| 88 | + } |
| 89 | +
|
| 90 | + location ~ /\.(?!well-known).* { |
| 91 | + deny all; |
| 92 | + } |
| 93 | +} |
| 94 | +EOF |
| 95 | +systemctl reload nginx |
| 96 | +msg_ok "Configured Service" |
| 97 | + |
| 98 | +motd_ssh |
| 99 | +customize |
| 100 | + |
| 101 | +msg_info "Cleaning up" |
| 102 | +$STD apt-get -y autoremove |
| 103 | +$STD apt-get -y autoclean |
| 104 | +msg_ok "Cleaned" |
0 commit comments