Added adjustments to symlinks and debugging

main
Anthony 2023-10-31 00:30:57 +08:00
parent 04fbbbb076
commit 8110ffaa22
2 changed files with 17 additions and 14 deletions

View File

@ -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"

View File

@ -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"