Spaces:
Paused
Paused
| # Function to set working directory | |
| set_working_directory() { | |
| cd /app || { echo "Failed to change directory to /app"; exit 1; } | |
| } | |
| # Function to print the contents of the working directory | |
| print_working_directory_contents() { | |
| echo "* Contents of /app directory: *" | |
| ls -la /app | |
| } | |
| # Function to keep the container running | |
| keep_container_running() { | |
| tail -f /var/log/auth.log | |
| } | |
| generate_admin_ssh_keys() { | |
| if [ ! -f /home/admin/.ssh/id_rsa ]; then | |
| echo "* Generating SSH keys for 'admin' user *" | |
| mkdir -p /home/admin/.ssh || { echo "Failed to create .ssh directory"; exit 1; } | |
| #ssh-keygen -t rsa -b 2048 -f /home/admin/.ssh/id_rsa -q -N "" | |
| #yes y | ssh-keygen -t rsa -b 2048 -f /home/admin/.ssh/id_rsa -N "" || { echo "Failed to generate admin SSH key"; exit 1; } | |
| yes y | ssh-keygen -t rsa -b 2048 -f /home/admin/.ssh/id_rsa -N "" || { echo "Failed to generate admin SSH key"; exit 1; } | |
| ssh-keyscan -p 2222 127.0.0.1 >> /home/admin/.ssh/known_hosts | |
| cp /home/admin/.ssh/known_hosts /home/admin/.ssh/ssh_known_hosts | |
| #ssh-copy-id -i ~/.ssh/id_rsa.pub -p 2222 admin@localhost | |
| chown -R admin:admin /home/admin | |
| #chmod -R 777 /home/admin/.ssh | |
| chmod 700 /home/admin/.ssh || { echo "Failed to set .ssh directory permissions"; exit 1; } | |
| chmod 600 /home/admin/.ssh/id_rsa || { echo "Failed to set private key permissions"; exit 1; } | |
| chmod 644 /home/admin/.ssh/id_rsa.pub || { echo "Failed to set public key permissions"; exit 1; } | |
| fi | |
| } | |
| add_admin_authorized_keys() { | |
| #echo "* Adding public key to authorized_keys for 'admin' user *" | |
| #echo "* Admin Public Key :$(cat /home/admin/.ssh/id_rsa.pub)" | |
| #echo "* Admin Private Key :$(cat /home/admin/.ssh/id_rsa.pub)" | |
| cat /home/admin/.ssh/id_rsa.pub >> /home/admin/.ssh/authorized_keys || { echo "Failed to add public key to authorized_keys"; exit 1; } | |
| #echo "* Authorised Keys: $(cat /home/admin/.ssh/authorized_keys)" | |
| #echo "* Known HOST File :$(cat /home/admin/.ssh/known_hosts)" | |
| #chmod 600 /home/admin/.ssh/authorized_keys || { echo "Failed to set authorized_keys permissions"; exit 1; } | |
| } | |
| echo "password" || su - admin | |
| echo "I am : $(whoami)" | |
| generate_admin_ssh_keys | |
| add_admin_authorized_keys | |
| tail -f /var/log/auth.log | |
| echo "* Activating virtual environment *" | |
| source /app/WebSSHEnv/bin/activate || { echo "Failed to activate virtual environment"; exit 1; } | |
| echo "* Starting WebSSH application *PWD $(pwd)*" | |
| cd /app || { echo "Failed to change directory to /app"; exit 1; } | |
| python3 -u -m WebSSH || { echo "Failed to start WebSSH application"; exit 1; } | |