From 8110ffaa22adc2acaa166f95c5e171ee34b415d3 Mon Sep 17 00:00:00 2001 From: Anthony Date: Tue, 31 Oct 2023 00:30:57 +0800 Subject: [PATCH] Added adjustments to symlinks and debugging --- add-sftp.sh | 20 ++++++++++++++++---- manifest.jps | 11 +---------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/add-sftp.sh b/add-sftp.sh index 6a1e3ee..d5c3a5e 100644 --- a/add-sftp.sh +++ b/add-sftp.sh @@ -1,6 +1,8 @@ #!/bin/bash -echo "Script started" >> /home/jelastic/add-sftp-user-addon/script_output.log +LOG_FILE="/home/jelastic/add-sftp-user-addon/logs/script_output.log" + +echo "Script started" >> $LOG_FILE # Generate random username and password USERNAME="user$(shuf -i 10000-99999 -n 1)" @@ -15,25 +17,35 @@ ROOT_GROUP=$(stat -c '%G' $ROOT_DIRECTORY) # Check if user already exists if id "$USERNAME" &>/dev/null; then - echo "User $USERNAME already exists." >> /home/jelastic/add-sftp-user-addon/script_output.log + echo "User $USERNAME already exists." >> $LOG_FILE exit 1 fi # Create user with their own home directory useradd -m $USERNAME if [ $? -ne 0 ]; then - echo "Failed to create user $USERNAME." >> /home/jelastic/add-sftp-user-addon/script_output.log + echo "Failed to create user $USERNAME." >> $LOG_FILE exit 1 fi echo "$USERNAME:$PASSWORD" | chpasswd # Create a symlink in the user's home directory pointing to the shared ROOT_DIRECTORY ln -s $ROOT_DIRECTORY $USER_HOME/ROOT +if [ $? -ne 0 ]; then + echo "Failed to create symlink for $USERNAME." >> $LOG_FILE + exit 1 +fi +echo "Symlink created for $USERNAME pointing to $ROOT_DIRECTORY" >> $LOG_FILE # Set user's group to the ROOT_GROUP and any other groups as needed (e.g., root) usermod -aG $ROOT_GROUP,root $USERNAME +if [ $? -ne 0 ]; then + echo "Failed to modify groups for $USERNAME." >> $LOG_FILE + exit 1 +fi +echo "$USERNAME added to groups $ROOT_GROUP and root" >> $LOG_FILE HOSTNAME=$(hostname -f) -echo "Script completed for user $USERNAME with hostname $HOSTNAME" >> /home/jelastic/add-sftp-user-addon/script_output.log +echo "Script completed for user $USERNAME with hostname $HOSTNAME" >> $LOG_FILE echo "USERNAME:$USERNAME" echo "PASSWORD:$PASSWORD" diff --git a/manifest.jps b/manifest.jps index 80716a9..8c10ea2 100644 --- a/manifest.jps +++ b/manifest.jps @@ -27,6 +27,7 @@ globals: onInstall: - cmd[cp]: mkdir -p /home/jelastic/add-sftp-user-addon/ + - cmd[cp]: mkdir -p /home/jelastic/add-sftp-user-addon/logs - cmd[cp]: wget https://deploy-proxy.mightybox.io/addons/add-sftp-user/raw/branch/main/add-sftp.sh -O /home/jelastic/add-sftp-user-addon/add-sftp.sh - cmd[cp]: chmod +x /home/jelastic/add-sftp-user-addon/*.sh - cmd[cp]: @@ -59,17 +60,7 @@ actions: password: ${response.out.PASSWORD} - return: sftpSuccess -onUninstall: - - cmd[cp]: - commands: - - rm -rf /home/jelastic/add-sftp-user-addon/ - user: root - - return: uninstallSuccess - responses: - uninstallSuccess: - type: success - message: "Uninstalled Successfully" installSuccess: type: success message: "Installed Successfully"