Skip to content

Commit 024ffcb

Browse files
feat: Add script installation tracking and update functionality (#36)
* feat: Add script installation tracking with Container ID detection - Add installed_scripts table to database schema - Implement Container ID parsing from terminal output - Add installation tracking for both local and SSH executions - Create InstalledScriptsTab component with filtering and search - Add tab navigation to main page (Scripts | Installed Scripts) - Add tRPC endpoints for installed scripts CRUD operations - Track installation status, server info, and output logs - Support both local and SSH execution modes * fix: Resolve SQL syntax error in database queries - Change table alias from 'is' to 'inst' in SQL queries - 'is' is a reserved keyword in SQLite causing syntax errors - Fixes getAllInstalledScripts, getInstalledScriptById, and getInstalledScriptsByServer methods * feat: Enhance Container ID detection and add manual editing - Add comprehensive Container ID detection patterns for various script formats - Add debug logging to help identify detection issues - Add manual Container ID editing feature in the frontend - Add updateInstalledScript tRPC mutation for updating records - Improve Container ID column with inline editing UI - Test and verify Container ID detection is working (detected 132 from 2fauth script) * fix: Improve Container ID detection with ANSI code handling - Add ANSI color code stripping before pattern matching - Add primary pattern for exact format: 🆔 Container ID: 113 - Test patterns on both original and cleaned output - Add better debug logging to show matched text - This should fix Container ID detection for Proxmox scripts * feat: Add script update functionality with terminal output - Add Update button for each installed script (only shows when container_id exists) - Add WebSocket support for update action (pct enter <ct-id> -- update) - Add updateScript tRPC endpoint for initiating updates - Add startScriptUpdate, startLocalScriptUpdate, startSSHScriptUpdate methods - Modify Terminal component to handle update operations - Display real-time terminal output for update commands - Support both local and SSH execution modes for updates - Show 'Update Container <ID>' in terminal title for update operations * fix: Fix SSH update functionality - Replace sshService.executeScript with direct sshpass command - Use bash -c to execute SSH command: sshpass -p 'password' ssh -o StrictHostKeyChecking=no user@ip 'pct enter <ct-id> -- update' - This fixes the 'Permission denied' and rsync errors - SSH updates now work properly for remote containers * fix: Fix WebSocket update action handling - Add containerId to WebSocketMessage typedef - Extract containerId from message in handleMessage function - Remove debug logging from Terminal component - This fixes the 'containerId is not defined' error - Update action should now work properly without creating script records * feat: Add Update functionality for installed scripts - Add Update button to InstalledScriptsTab for scripts with Container ID - Modify Terminal component to handle update operations with isUpdate and containerId props - Add startUpdateExecution method to WebSocket handler - Implement local update execution using 'pct enter <CT ID> -c update' - Implement SSH update execution for remote servers - Update WebSocket message parsing to handle update parameters - Users can now update installed scripts by entering the LXC container and running update command * fix: Fix SSH update execution by using direct command execution - Add executeCommand method to SSH service for direct command execution - Update startSSHUpdateExecution to use executeCommand instead of executeScript - This fixes the rsync permission denied error when updating scripts via SSH - Update functionality now works properly for both local and SSH installations * fix: Add server credentials fetching for SSH updates - Create servers router with getServerById endpoint - Update handleUpdateScript to fetch full server details including credentials - This fixes the permission denied error by providing user/password for SSH authentication - SSH updates now have access to complete server configuration * fix: Simplify server credentials fetching for SSH updates - Add server_user and server_password to database query - Update InstalledScript interface to include server credentials - Simplify handleUpdateScript to use data already available - Remove complex tRPC server fetching that was causing errors - SSH updates now work with complete server authentication data * fix: Correct pct enter command sequence for updates - Change from 'pct enter <CT ID> -c "update"' to proper sequence - First run 'pct enter <CT ID>' to enter container shell - Then send 'update' command after entering the container - Apply fix to both local and SSH update execution methods - Add 1-second delay to ensure container shell is ready before sending update command * fix: Increase delay to 4 seconds before sending update command - Change delay from 1 second to 4 seconds for both local and SSH updates - Ensures container shell is fully ready before sending update command - Prevents premature command execution that could fail * cleanup: Remove all debug console.log statements - Remove debug logging from server.js WebSocket handlers - Remove debug logging from Terminal component - Remove debug logging from page.tsx - Remove debug logging from ExecutionModeModal component - Remove debug logging from githubJsonService.ts - Keep only essential server startup messages and error logging - Clean up codebase for production readiness * fix: Resolve all build and linter errors - Fix React Hook useEffect missing dependencies in Terminal.tsx - Fix TypeScript unsafe argument error in installedScripts.ts by properly typing updateData - Add missing isUpdate and containerId properties to WebSocketMessage type definition - Add proper type annotations for callback parameters in server.js - Fix TypeScript errors with execution.process by adding type assertions - Remove duplicate updateInstalledScript method in installedScripts.ts - Build now passes successfully with no errors or warnings
1 parent 9d2a1a1 commit 024ffcb

File tree

16 files changed

+1431
-37
lines changed

16 files changed

+1431
-37
lines changed

scripts/core/install.func

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ EOF
195195
systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//')
196196
msg_ok "Customized Container"
197197
fi
198-
198+
echo "bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/ct/${app}.sh)\"" >/usr/bin/update
199+
chmod +x /usr/bin/update
199200

200201
if [[ -n "${SSH_AUTHORIZED_KEY}" ]]; then
201202
mkdir -p /root/.ssh

scripts/ct/2fauth.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env bash
2+
SCRIPT_DIR="$(dirname "$0")"
3+
source "$SCRIPT_DIR/../core/build.func"
4+
# Copyright (c) 2021-2025 community-scripts ORG
5+
# Author: jkrgr0
6+
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
7+
# Source: https://docs.2fauth.app/
8+
9+
APP="2FAuth"
10+
var_tags="${var_tags:-2fa;authenticator}"
11+
var_cpu="${var_cpu:-1}"
12+
var_ram="${var_ram:-512}"
13+
var_disk="${var_disk:-2}"
14+
var_os="${var_os:-debian}"
15+
var_version="${var_version:-12}"
16+
var_unprivileged="${var_unprivileged:-1}"
17+
18+
header_info "$APP"
19+
variables
20+
color
21+
catch_errors
22+
23+
function update_script() {
24+
header_info
25+
check_container_storage
26+
check_container_resources
27+
28+
if [[ ! -d "/opt/2fauth" ]]; then
29+
msg_error "No ${APP} Installation Found!"
30+
exit
31+
fi
32+
if check_for_gh_release "2fauth" "Bubka/2FAuth"; then
33+
$STD apt-get update
34+
$STD apt-get -y upgrade
35+
36+
msg_info "Creating Backup"
37+
mv "/opt/2fauth" "/opt/2fauth-backup"
38+
if ! dpkg -l | grep -q 'php8.3'; then
39+
cp /etc/nginx/conf.d/2fauth.conf /etc/nginx/conf.d/2fauth.conf.bak
40+
fi
41+
msg_ok "Backup Created"
42+
43+
if ! dpkg -l | grep -q 'php8.3'; then
44+
$STD apt-get install -y \
45+
lsb-release \
46+
gnupg2
47+
PHP_VERSION="8.3" PHP_MODULE="common,ctype,fileinfo,mysql,cli" PHP_FPM="YES" setup_php
48+
sed -i 's/php8.2/php8.3/g' /etc/nginx/conf.d/2fauth.conf
49+
fi
50+
fetch_and_deploy_gh_release "2fauth" "Bubka/2FAuth"
51+
setup_composer
52+
mv "/opt/2fauth-backup/.env" "/opt/2fauth/.env"
53+
mv "/opt/2fauth-backup/storage" "/opt/2fauth/storage"
54+
cd "/opt/2fauth" || return
55+
chown -R www-data: "/opt/2fauth"
56+
chmod -R 755 "/opt/2fauth"
57+
export COMPOSER_ALLOW_SUPERUSER=1
58+
$STD composer install --no-dev --prefer-source
59+
php artisan 2fauth:install
60+
$STD systemctl restart nginx
61+
62+
msg_info "Cleaning Up"
63+
if dpkg -l | grep -q 'php8.2'; then
64+
$STD apt-get remove --purge -y php8.2*
65+
fi
66+
$STD apt-get -y autoremove
67+
$STD apt-get -y autoclean
68+
msg_ok "Cleanup Completed"
69+
msg_ok "Updated Successfully"
70+
fi
71+
exit
72+
}
73+
74+
start
75+
build_container
76+
description
77+
78+
msg_ok "Completed Successfully!\n"
79+
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
80+
echo -e "${INFO}${YW} Access it using the following URL:${CL}"
81+
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:80${CL}"

scripts/ct/debian.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
SCRIPT_DIR="$(dirname "$0")"
3+
source "$SCRIPT_DIR/../core/build.func"
4+
# Copyright (c) 2021-2025 tteck
5+
# Author: tteck (tteckster)
6+
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
7+
# Source: https://www.debian.org/
8+
9+
APP="Debian"
10+
var_tags="${var_tags:-os}"
11+
var_cpu="${var_cpu:-1}"
12+
var_ram="${var_ram:-512}"
13+
var_disk="${var_disk:-2}"
14+
var_os="${var_os:-debian}"
15+
var_version="${var_version:-13}"
16+
var_unprivileged="${var_unprivileged:-1}"
17+
18+
header_info "$APP"
19+
variables
20+
color
21+
catch_errors
22+
23+
function update_script() {
24+
header_info
25+
check_container_storage
26+
check_container_resources
27+
if [[ ! -d /var ]]; then
28+
msg_error "No ${APP} Installation Found!"
29+
exit
30+
fi
31+
msg_info "Updating $APP LXC"
32+
$STD apt update
33+
$STD apt -y upgrade
34+
msg_ok "Updated $APP LXC"
35+
exit
36+
}
37+
38+
start
39+
build_container
40+
description
41+
42+
msg_ok "Completed Successfully!\n"
43+
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"

scripts/install/2fauth-install.sh

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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"

scripts/install/debian-install.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright (c) 2021-2025 tteck
4+
# Author: tteck (tteckster)
5+
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
6+
# Source: https://www.debian.org/
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+
motd_ssh
17+
customize
18+
19+
msg_info "Cleaning up"
20+
$STD apt -y autoremove
21+
$STD apt -y autoclean
22+
$STD apt -y clean
23+
msg_ok "Cleaned"
24+

0 commit comments

Comments
 (0)