Clean up shell script comments
This commit is contained in:
1 parent
227b632ad8
commit
c148db231d
2 files changed
-183
No files matched your search
-118
@@ -1,7 +1,6 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# ============================================================================
|
||||
# Tor Hosting - Automated Installer for Debian 13 (Trixie)
|
||||
# https://github.com/bigbong420/hosting
|
||||
#
|
||||
@@ -9,7 +8,6 @@ set -e
|
||||
# curl -sSL https://raw.githubusercontent.com/bigbong420/hosting/upgrades/install.sh | bash
|
||||
# Or with options:
|
||||
# curl -sSL https://raw.githubusercontent.com/bigbong420/hosting/upgrades/install.sh | bash -s -- --non-interactive
|
||||
# ============================================================================
|
||||
|
||||
REPO_URL="https://github.com/bigbong420/hosting.git"
|
||||
REPO_BRANCH="upgrades"
|
||||
@@ -31,11 +29,6 @@ DB_PMA_PASS="${HOSTING_PMA_PASS:-}"
|
||||
ADMIN_PASS="${HOSTING_ADMIN_PASS:-}"
|
||||
BLOWFISH_SECRET=""
|
||||
ONION_ENC_KEY=""
|
||||
|
||||
# ============================================================================
|
||||
# Functions
|
||||
# ============================================================================
|
||||
|
||||
log_info() { echo -e "${CYAN}[INFO]${NC} $1"; }
|
||||
log_ok() { echo -e "${GREEN}[OK]${NC} $1"; }
|
||||
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
|
||||
@@ -65,11 +58,6 @@ Examples:
|
||||
EOF
|
||||
exit 0
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Parse arguments
|
||||
# ============================================================================
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--non-interactive) NONINTERACTIVE=true; shift ;;
|
||||
@@ -83,11 +71,6 @@ while [[ $# -gt 0 ]]; do
|
||||
*) log_error "Unknown option: $1"; usage ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# ============================================================================
|
||||
# Pre-flight checks
|
||||
# ============================================================================
|
||||
|
||||
log_step "Pre-flight checks"
|
||||
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
@@ -135,9 +118,7 @@ fi
|
||||
|
||||
log_ok "Repository found at $SCRIPT_DIR"
|
||||
|
||||
# ============================================================================
|
||||
# Interactive prompts (skipped with --non-interactive)
|
||||
# ============================================================================
|
||||
|
||||
if [ "$NONINTERACTIVE" = false ]; then
|
||||
log_step "Configuration"
|
||||
@@ -191,8 +172,6 @@ if [ "$NONINTERACTIVE" = false ]; then
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Generate any passwords that weren't provided
|
||||
[ -z "$DB_HOSTING_PASS" ] && DB_HOSTING_PASS=$(gen_pass)
|
||||
[ -z "$DB_PMA_PASS" ] && DB_PMA_PASS=$(gen_pass)
|
||||
[ -z "$ADMIN_PASS" ] && ADMIN_PASS=$(gen_pass)
|
||||
@@ -213,8 +192,6 @@ if [ "$NONINTERACTIVE" = false ]; then
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Save credentials to file
|
||||
CREDS_FILE="/root/hosting-credentials.txt"
|
||||
cat > "$CREDS_FILE" <<EOF
|
||||
=== Daniel's Hosting Credentials ===
|
||||
@@ -233,11 +210,6 @@ Onion Key Encryption Key: $ONION_ENC_KEY
|
||||
EOF
|
||||
chmod 600 "$CREDS_FILE"
|
||||
log_ok "Credentials saved to $CREDS_FILE"
|
||||
|
||||
# ============================================================================
|
||||
# Step 1: Purge conflicting packages and fix DNS
|
||||
# ============================================================================
|
||||
|
||||
log_step "Step 1: Purge conflicting packages"
|
||||
|
||||
DEBIAN_FRONTEND=noninteractive apt purge -y apache2* dnsmasq* eatmydata exim4* \
|
||||
@@ -249,11 +221,6 @@ systemctl stop systemd-resolved.service 2>/dev/null || true
|
||||
|
||||
echo "nameserver 1.1.1.1" > /etc/resolv.conf
|
||||
log_ok "DNS set to 1.1.1.1"
|
||||
|
||||
# ============================================================================
|
||||
# Step 2: Add repositories
|
||||
# ============================================================================
|
||||
|
||||
log_step "Step 2: Add repositories"
|
||||
|
||||
apt update -qq
|
||||
@@ -275,11 +242,6 @@ grep -q "sury.org" /etc/apt/sources.list || \
|
||||
apt update -qq
|
||||
DEBIAN_FRONTEND=noninteractive apt upgrade -y
|
||||
log_ok "Repositories configured"
|
||||
|
||||
# ============================================================================
|
||||
# Step 3: Build binaries (PHP, ImageMagick, etc)
|
||||
# ============================================================================
|
||||
|
||||
if [ "$SKIP_BINARIES" = true ]; then
|
||||
log_step "Step 3: Skipping binary compilation (--skip-binaries)"
|
||||
else
|
||||
@@ -295,11 +257,6 @@ else
|
||||
fi
|
||||
log_ok "All binaries compiled and installed"
|
||||
fi
|
||||
|
||||
# ============================================================================
|
||||
# Step 4: Vanity onion generation (if requested)
|
||||
# ============================================================================
|
||||
|
||||
if [ -n "$VANITY_PREFIX" ]; then
|
||||
log_step "Step 4: Generating vanity .onion address (prefix: $VANITY_PREFIX)"
|
||||
|
||||
@@ -334,22 +291,12 @@ if [ -n "$VANITY_PREFIX" ]; then
|
||||
else
|
||||
log_step "Step 4: Skipping vanity generation (random onion)"
|
||||
fi
|
||||
|
||||
# ============================================================================
|
||||
# Step 5: Copy site and config files
|
||||
# ============================================================================
|
||||
|
||||
log_step "Step 5: Copy site and config files"
|
||||
|
||||
cp -a "$SCRIPT_DIR/var/www/"* /var/www/
|
||||
cp -a "$SCRIPT_DIR/etc/"* /etc/
|
||||
|
||||
log_ok "Files copied"
|
||||
|
||||
# ============================================================================
|
||||
# Step 6: Create systemd service files for all PHP versions
|
||||
# ============================================================================
|
||||
|
||||
log_step "Step 6: Create PHP-FPM systemd service files"
|
||||
|
||||
# 8.2 service files should exist from install_binaries.sh packages
|
||||
@@ -363,11 +310,6 @@ done
|
||||
|
||||
systemctl daemon-reload
|
||||
log_ok "PHP-FPM service files created for 8.2, 8.3, 8.4, 8.5"
|
||||
|
||||
# ============================================================================
|
||||
# Step 7: Start Tor and get .onion address
|
||||
# ============================================================================
|
||||
|
||||
log_step "Step 7: Configure Tor"
|
||||
|
||||
systemctl restart bind9.service
|
||||
@@ -387,17 +329,10 @@ if [ -z "$ONION_ADDR" ]; then
|
||||
fi
|
||||
|
||||
log_ok "Onion address: ${GREEN}${ONION_ADDR}${NC}"
|
||||
|
||||
# ============================================================================
|
||||
# Step 8: Configure common.php
|
||||
# ============================================================================
|
||||
|
||||
log_step "Step 8: Configure hosting"
|
||||
|
||||
ADMIN_HASH=$(php8.2 -r "echo password_hash('$ADMIN_PASS', PASSWORD_DEFAULT);" 2>/dev/null || \
|
||||
php8.5 -r "echo password_hash('$ADMIN_PASS', PASSWORD_DEFAULT);")
|
||||
|
||||
# Replace passwords and settings
|
||||
sed -i "s|const DBPASS='MY_PASSWORD'|const DBPASS='$DB_HOSTING_PASS'|" /var/www/common.php
|
||||
sed -i "s|const ADMIN_PASSWORD='MY_PASSWORD'|const ADMIN_PASSWORD='$ADMIN_HASH'|" /var/www/common.php
|
||||
sed -i "s|const ONION_KEY_ENCRYPTION_KEY=''|const ONION_KEY_ENCRYPTION_KEY='$ONION_ENC_KEY'|" /var/www/common.php
|
||||
@@ -415,11 +350,6 @@ sed -i "s/$DEFAULT_ONION/$ONION_ADDR/g" \
|
||||
/var/www/html/squirrelmail/config/config.php
|
||||
|
||||
log_ok "Configuration applied"
|
||||
|
||||
# ============================================================================
|
||||
# Step 9: Configure Dovecot for Debian 13
|
||||
# ============================================================================
|
||||
|
||||
log_step "Step 9: Configure Dovecot"
|
||||
|
||||
# Dovecot 2.4 in trixie has different config syntax
|
||||
@@ -459,22 +389,12 @@ fi
|
||||
|
||||
systemctl restart dovecot
|
||||
log_ok "Dovecot configured"
|
||||
|
||||
# ============================================================================
|
||||
# Step 10: Postfix maps
|
||||
# ============================================================================
|
||||
|
||||
log_step "Step 10: Configure Postfix"
|
||||
|
||||
postalias /etc/aliases
|
||||
postmap /etc/postfix/canonical /etc/postfix/sender_login_maps /etc/postfix/transport
|
||||
|
||||
log_ok "Postfix maps created"
|
||||
|
||||
# ============================================================================
|
||||
# Step 11: Configure fstab (tmpfs, hidepid, quota)
|
||||
# ============================================================================
|
||||
|
||||
log_step "Step 11: Configure fstab and quota"
|
||||
|
||||
grep -q "tmpfs /tmp" /etc/fstab || \
|
||||
@@ -498,11 +418,6 @@ quotacheck -cMu "$QUOTA_TARGET" 2>/dev/null || true
|
||||
quotaon "$QUOTA_TARGET" 2>/dev/null || true
|
||||
|
||||
log_ok "Filesystem configured"
|
||||
|
||||
# ============================================================================
|
||||
# Step 12: Composer install (sodium_compat)
|
||||
# ============================================================================
|
||||
|
||||
log_step "Step 12: Install Composer dependencies"
|
||||
|
||||
echo "nameserver 1.1.1.1" > /etc/resolv.conf
|
||||
@@ -521,11 +436,6 @@ if [ ! -f /var/www/vendor/autoload.php ]; then
|
||||
fi
|
||||
|
||||
log_ok "Composer dependencies installed"
|
||||
|
||||
# ============================================================================
|
||||
# Step 13: MySQL setup
|
||||
# ============================================================================
|
||||
|
||||
log_step "Step 13: Configure MySQL"
|
||||
|
||||
mysql -e "CREATE USER IF NOT EXISTS 'phpmyadmin'@'%' IDENTIFIED BY '$DB_PMA_PASS';
|
||||
@@ -538,26 +448,15 @@ mysql phpmyadmin < /var/www/html/phpmyadmin/sql/create_tables.sql 2>/dev/null ||
|
||||
mysql -e "CREATE USER IF NOT EXISTS 'hosting'@'%' IDENTIFIED BY '$DB_HOSTING_PASS';
|
||||
GRANT ALL PRIVILEGES ON *.* TO 'hosting'@'%' WITH GRANT OPTION;
|
||||
FLUSH PRIVILEGES;"
|
||||
|
||||
# Configure phpMyAdmin
|
||||
sed -i "s|\$cfg\['blowfish_secret'\] = '.*'|\$cfg['blowfish_secret'] = '$BLOWFISH_SECRET'|" \
|
||||
/var/www/html/phpmyadmin/config.inc.php
|
||||
sed -i "s|YOUR_PASSWORD|$DB_PMA_PASS|g" /var/www/html/phpmyadmin/config.inc.php 2>/dev/null || true
|
||||
|
||||
log_ok "MySQL users and databases created"
|
||||
|
||||
# ============================================================================
|
||||
# Step 14: Run setup.php
|
||||
# ============================================================================
|
||||
|
||||
log_step "Step 14: Run setup.php"
|
||||
|
||||
php8.2 /var/www/setup.php 2>&1 || true
|
||||
|
||||
# Ensure nginx runtime directories exist
|
||||
mkdir -p /var/log/nginx /var/run/nginx
|
||||
|
||||
# Enable FPM services for all PHP versions
|
||||
for ver in 8.2 8.3 8.4 8.5; do
|
||||
systemctl enable "php$ver-fpm@default" 2>/dev/null || true
|
||||
systemctl start "php$ver-fpm@default" 2>/dev/null || true
|
||||
@@ -565,11 +464,6 @@ done
|
||||
systemctl restart nginx 2>/dev/null || true
|
||||
|
||||
log_ok "Setup complete"
|
||||
|
||||
# ============================================================================
|
||||
# Step 15: Vanity onion import (if generated)
|
||||
# ============================================================================
|
||||
|
||||
if [ -n "$VANITY_PREFIX" ] && [ -n "$VANITY_SECRET" ]; then
|
||||
log_step "Step 15: Import vanity onion address"
|
||||
|
||||
@@ -611,26 +505,14 @@ if [ -n "$VANITY_PREFIX" ] && [ -n "$VANITY_SECRET" ]; then
|
||||
else
|
||||
log_step "Step 15: Skipping vanity import"
|
||||
fi
|
||||
|
||||
# ============================================================================
|
||||
# Step 16: Enable timers and disable sftp subsystem
|
||||
# ============================================================================
|
||||
|
||||
log_step "Step 16: Final configuration"
|
||||
|
||||
systemctl enable hosting-del.timer hosting.timer
|
||||
sed -i 's/^Subsystem/#Subsystem/' /etc/ssh/sshd_config
|
||||
|
||||
# Restart all services
|
||||
systemctl restart nginx postfix dovecot
|
||||
systemctl restart tor@default.service
|
||||
|
||||
log_ok "Timers enabled, services configured"
|
||||
|
||||
# ============================================================================
|
||||
# Summary
|
||||
# ============================================================================
|
||||
|
||||
log_step "Installation Complete"
|
||||
|
||||
echo -e "${BOLD}Onion Address:${NC} ${GREEN}http://${ONION_ADDR}${NC}"
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# ============================================================================
|
||||
# Tor Hosting - Update Script
|
||||
# https://github.com/bigbong420/hosting
|
||||
#
|
||||
@@ -13,7 +12,6 @@ set -e
|
||||
# ./update.sh --rebuild # Also rebuild PHP/ImageMagick
|
||||
# ./update.sh --php-only # Only rebuild PHP (skip ImageMagick)
|
||||
# ./update.sh --code-only # Only update PHP code, no config changes
|
||||
# ============================================================================
|
||||
|
||||
REPO_URL="https://github.com/bigbong420/hosting.git"
|
||||
REPO_BRANCH="upgrades"
|
||||
@@ -64,11 +62,6 @@ while [[ $# -gt 0 ]]; do
|
||||
*) log_error "Unknown option: $1"; usage ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# ============================================================================
|
||||
# Pre-flight
|
||||
# ============================================================================
|
||||
|
||||
log_step "Pre-flight checks"
|
||||
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
@@ -76,7 +69,6 @@ if [ "$(id -u)" -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Find the repo
|
||||
if [ -d "/root/hosting" ]; then
|
||||
REPO_DIR="/root/hosting"
|
||||
elif [ -d "$(dirname "$0")/.git" ]; then
|
||||
@@ -87,17 +79,10 @@ else
|
||||
fi
|
||||
|
||||
log_ok "Repository at $REPO_DIR"
|
||||
|
||||
# ============================================================================
|
||||
# Backup current config
|
||||
# ============================================================================
|
||||
|
||||
log_step "Backing up current configuration"
|
||||
|
||||
BACKUP_DIR="/root/hosting-backup-$(date +%Y%m%d-%H%M%S)"
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
|
||||
# Save current secrets from common.php
|
||||
if [ -f /var/www/common.php ]; then
|
||||
cp /var/www/common.php "$BACKUP_DIR/common.php.bak"
|
||||
DBHOST=$(php8.2 -r "require('/var/www/common.php'); echo DBHOST;" 2>/dev/null || echo "127.0.0.1")
|
||||
@@ -119,16 +104,9 @@ if [ -z "$DBPASS" ] || [ -z "$ADDRESS" ]; then
|
||||
fi
|
||||
|
||||
log_ok "Backup saved to $BACKUP_DIR"
|
||||
|
||||
# ============================================================================
|
||||
# Pull latest code
|
||||
# ============================================================================
|
||||
|
||||
log_step "Pulling latest code"
|
||||
|
||||
cd "$REPO_DIR"
|
||||
|
||||
# Save hash of install_binaries.sh before pull to detect changes
|
||||
OLD_BINARIES_HASH=""
|
||||
if [ -f "$REPO_DIR/install_binaries.sh" ]; then
|
||||
OLD_BINARIES_HASH=$(md5sum "$REPO_DIR/install_binaries.sh" | cut -d' ' -f1)
|
||||
@@ -140,11 +118,6 @@ git reset --hard "origin/$REPO_BRANCH"
|
||||
NEW_BINARIES_HASH=$(md5sum "$REPO_DIR/install_binaries.sh" | cut -d' ' -f1)
|
||||
|
||||
log_ok "Code updated to latest"
|
||||
|
||||
# ============================================================================
|
||||
# Check for binary changes
|
||||
# ============================================================================
|
||||
|
||||
BINARIES_CHANGED=false
|
||||
if [ "$OLD_BINARIES_HASH" != "$NEW_BINARIES_HASH" ] && [ -n "$OLD_BINARIES_HASH" ]; then
|
||||
BINARIES_CHANGED=true
|
||||
@@ -184,10 +157,6 @@ if [ "$OLD_BINARIES_HASH" != "$NEW_BINARIES_HASH" ] && [ -n "$OLD_BINARIES_HASH"
|
||||
fi
|
||||
fi
|
||||
|
||||
# ============================================================================
|
||||
# Rebuild binaries (if requested or needed)
|
||||
# ============================================================================
|
||||
|
||||
if [ "$REBUILD" = true ]; then
|
||||
log_step "Rebuilding all binaries (PHP + ImageMagick)"
|
||||
bash "$REPO_DIR/install_binaries.sh" 2>&1 | tee /root/rebuild.log
|
||||
@@ -205,13 +174,7 @@ elif [ "$BINARIES_CHANGED" = true ] && [ "$CODE_ONLY" != true ]; then
|
||||
log_warn "Continuing with code-only update for now."
|
||||
fi
|
||||
|
||||
# ============================================================================
|
||||
# Update code files
|
||||
# ============================================================================
|
||||
|
||||
log_step "Updating code files"
|
||||
|
||||
# Copy updated PHP files
|
||||
cp -a "$REPO_DIR/var/www/common.php" /var/www/common.php
|
||||
cp -a "$REPO_DIR/var/www/html/home.php" /var/www/html/home.php
|
||||
cp -a "$REPO_DIR/var/www/html/login.php" /var/www/html/login.php
|
||||
@@ -233,25 +196,15 @@ cp -a "$REPO_DIR/var/www/find_old.php" /var/www/find_old.php 2>/dev/null || true
|
||||
|
||||
log_ok "Code files updated"
|
||||
|
||||
# ============================================================================
|
||||
# Restore configuration
|
||||
# ============================================================================
|
||||
|
||||
log_step "Restoring configuration"
|
||||
|
||||
DEFAULT_ONION="dhosting4xxoydyaivckq7tsmtgi4wfs3flpeyitekkmqwu4v4r46syd.onion"
|
||||
|
||||
# Restore DB settings
|
||||
sed -i "s|const DBHOST='127.0.0.1'|const DBHOST='$DBHOST'|" /var/www/common.php
|
||||
sed -i "s|const DBPASS='MY_PASSWORD'|const DBPASS='$DBPASS'|" /var/www/common.php
|
||||
sed -i "s|const ADMIN_PASSWORD='MY_PASSWORD'|const ADMIN_PASSWORD='$ADMIN_PASSWORD'|" /var/www/common.php
|
||||
sed -i "s|const ONION_KEY_ENCRYPTION_KEY=''|const ONION_KEY_ENCRYPTION_KEY='$ONION_KEY_ENCRYPTION_KEY'|" /var/www/common.php
|
||||
|
||||
# Restore onion address
|
||||
sed -i "s|$DEFAULT_ONION|$ADDRESS|g" /var/www/common.php
|
||||
sed -i "s|$DEFAULT_ONION|$ADDRESS|g" /var/www/skel/www/index.hosting.html 2>/dev/null || true
|
||||
|
||||
# Fix permissions
|
||||
chown root:www-data /var/www/common.php
|
||||
chmod 640 /var/www/common.php
|
||||
|
||||
@@ -263,25 +216,13 @@ if [ "$CODE_ONLY" = true ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# ============================================================================
|
||||
# Update configs and restart services
|
||||
# ============================================================================
|
||||
|
||||
log_step "Updating services"
|
||||
|
||||
# Run setup.php to update database schema and configs
|
||||
php8.2 /var/www/setup.php 2>&1 || true
|
||||
|
||||
# Ensure runtime dirs exist
|
||||
mkdir -p /var/log/nginx /var/run/nginx
|
||||
|
||||
# Restart FPM and nginx
|
||||
for ver in 8.2 8.3 8.4 8.5; do
|
||||
systemctl restart "php$ver-fpm@default" 2>/dev/null || true
|
||||
done
|
||||
systemctl restart nginx 2>/dev/null || true
|
||||
|
||||
# Verify
|
||||
FAILS=0
|
||||
for svc in nginx php8.2-fpm@default php8.3-fpm@default php8.4-fpm@default php8.5-fpm@default; do
|
||||
if ! systemctl is-active --quiet "$svc"; then
|
||||
@@ -296,17 +237,11 @@ else
|
||||
log_warn "$FAILS service(s) need attention"
|
||||
fi
|
||||
|
||||
# ============================================================================
|
||||
# Summary
|
||||
# ============================================================================
|
||||
|
||||
log_step "Update Complete"
|
||||
|
||||
echo -e "${BOLD}Onion:${NC} $ADDRESS"
|
||||
echo -e "${BOLD}Backup:${NC} $BACKUP_DIR"
|
||||
echo ""
|
||||
|
||||
# Quick smoke test
|
||||
TITLE=$(curl -s --max-time 30 --socks5-hostname 127.0.0.1:9050 "http://$ADDRESS/" 2>/dev/null | grep -o "<title>[^<]*</title>")
|
||||
if [ -n "$TITLE" ]; then
|
||||
log_ok "Site responding: $TITLE"
|
||||
|
||||
Reference in new issue
Block a user