Spaces:
Paused
Paused
Create start.sh
Browse files
start.sh
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
# Function to print the current hostname and user details
|
| 4 |
+
print_host_details() {
|
| 5 |
+
#echo "0.0.0.0 abc" | sudo tee -a /etc/hosts
|
| 6 |
+
echo "* The hostname of this container is: $(cat /etc/hostname). PWD $(pwd)"
|
| 7 |
+
echo "* The host File of this container is: $(cat /etc/hosts)"
|
| 8 |
+
echo "* The Sudoers of this container is: $(cat /etc/sudoers)"
|
| 9 |
+
echo "* ID of the user running the script:($whoami) *ID : $(id -u) * Group: $(id -g)"
|
| 10 |
+
echo "* Changing User to Admin :$(echo "password" || su - admin)"
|
| 11 |
+
echo "* Current User WHO AM I $(whoami)"
|
| 12 |
+
echo "* Status of Admin: $(id admin 2>/dev/null || echo 'Admin user not found')"
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
# Function to start SSH service if not running
|
| 18 |
+
start_ssh_service() {
|
| 19 |
+
if ! pgrep -x "sshd" >/dev/null; then
|
| 20 |
+
echo "* Starting SSH server on port 2222 *"
|
| 21 |
+
/usr/sbin/sshd -p 2222 || { echo "Failed to start SSH server"; exit 1; }
|
| 22 |
+
#/usr/sbin/sshd -D || { echo "Failed to start SSH server"; exit 1; }
|
| 23 |
+
else
|
| 24 |
+
echo "* SSH server is already running *"
|
| 25 |
+
fi
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
# Function to create 'admin' user if missing
|
| 29 |
+
create_admin_user() {
|
| 30 |
+
echo "* Creating 'admin' user *"
|
| 31 |
+
#useradd -m admin || { echo "Failed to create admin user"; exit 1; }
|
| 32 |
+
echo "admin:password" | chpasswd || { echo "Failed to set admin password"; exit 1; }
|
| 33 |
+
#echo "%sudo ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers || { echo "Failed to update sudoers"; exit 1; }
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
# Function to fix permissions for 'admin' user
|
| 37 |
+
fix_admin_permissions() {
|
| 38 |
+
echo "* Fixing permissions for 'admin' user *"
|
| 39 |
+
#chown -R admin:admin /home/admin || { echo "Failed to change ownership"; exit 1; }
|
| 40 |
+
chmod -R 777 /home/* || { echo "Failed to set permissions"; exit 1; }
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
# Function to activate virtual environment
|
| 44 |
+
activate_virtual_env() {
|
| 45 |
+
if [ -d "/app/WebSSHEnv" ]; then
|
| 46 |
+
echo "* Activating virtual environment *"
|
| 47 |
+
source /app/WebSSHEnv/bin/activate || { echo "Failed to activate virtual environment"; exit 1; }
|
| 48 |
+
else
|
| 49 |
+
echo "* Virtual environment not found, please check setup *"
|
| 50 |
+
fi
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
# Function to set working directory
|
| 54 |
+
set_working_directory() {
|
| 55 |
+
cd /app || { echo "Failed to change directory to /app"; exit 1; }
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
# Function to print the contents of the working directory
|
| 59 |
+
print_working_directory_contents() {
|
| 60 |
+
echo "* Contents of /app directory: *"
|
| 61 |
+
ls -la /app
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
# Function to run the WebSSH application
|
| 65 |
+
run_webssh_application() {
|
| 66 |
+
echo "* Starting WebSSH application *"
|
| 67 |
+
python3 -u -m WebSSH || { echo "Failed to start WebSSH application"; exit 1; }
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
# Function to keep the container running
|
| 71 |
+
keep_container_running() {
|
| 72 |
+
tail -f /var/log/auth.log
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
# Main script execution
|
| 76 |
+
print_host_details
|
| 77 |
+
start_ssh_service
|
| 78 |
+
#sshd -T | grep -i 'known hosts'
|
| 79 |
+
echo "* Status of SSH service: *"
|
| 80 |
+
netstat -tuln
|
| 81 |
+
|
| 82 |
+
echo "* Testing admin's SSH login locally *"
|
| 83 |
+
sshpass -p "password" ssh -v -o StrictHostKeyChecking=no -i /home/admin/.ssh/id_rsa admin@0.0.0.0 -p 2222
|
| 84 |
+
|
| 85 |
+
activate_virtual_env
|
| 86 |
+
set_working_directory
|
| 87 |
+
print_working_directory_contents
|
| 88 |
+
run_webssh_application
|
| 89 |
+
keep_container_running
|