Added adjustments to symlinks and debugging
parent
04fbbbb076
commit
8110ffaa22
20
add-sftp.sh
20
add-sftp.sh
|
@ -1,6 +1,8 @@
|
||||||
#!/bin/bash
|
#!/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
|
# Generate random username and password
|
||||||
USERNAME="user$(shuf -i 10000-99999 -n 1)"
|
USERNAME="user$(shuf -i 10000-99999 -n 1)"
|
||||||
|
@ -15,25 +17,35 @@ ROOT_GROUP=$(stat -c '%G' $ROOT_DIRECTORY)
|
||||||
|
|
||||||
# Check if user already exists
|
# Check if user already exists
|
||||||
if id "$USERNAME" &>/dev/null; then
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create user with their own home directory
|
# Create user with their own home directory
|
||||||
useradd -m $USERNAME
|
useradd -m $USERNAME
|
||||||
if [ $? -ne 0 ]; then
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "$USERNAME:$PASSWORD" | chpasswd
|
echo "$USERNAME:$PASSWORD" | chpasswd
|
||||||
|
|
||||||
# Create a symlink in the user's home directory pointing to the shared ROOT_DIRECTORY
|
# Create a symlink in the user's home directory pointing to the shared ROOT_DIRECTORY
|
||||||
ln -s $ROOT_DIRECTORY $USER_HOME/ROOT
|
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)
|
# Set user's group to the ROOT_GROUP and any other groups as needed (e.g., root)
|
||||||
usermod -aG $ROOT_GROUP,root $USERNAME
|
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)
|
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 "USERNAME:$USERNAME"
|
||||||
echo "PASSWORD:$PASSWORD"
|
echo "PASSWORD:$PASSWORD"
|
||||||
|
|
11
manifest.jps
11
manifest.jps
|
@ -27,6 +27,7 @@ globals:
|
||||||
|
|
||||||
onInstall:
|
onInstall:
|
||||||
- cmd[cp]: mkdir -p /home/jelastic/add-sftp-user-addon/
|
- 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]: 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]: chmod +x /home/jelastic/add-sftp-user-addon/*.sh
|
||||||
- cmd[cp]:
|
- cmd[cp]:
|
||||||
|
@ -59,17 +60,7 @@ actions:
|
||||||
password: ${response.out.PASSWORD}
|
password: ${response.out.PASSWORD}
|
||||||
- return: sftpSuccess
|
- return: sftpSuccess
|
||||||
|
|
||||||
onUninstall:
|
|
||||||
- cmd[cp]:
|
|
||||||
commands:
|
|
||||||
- rm -rf /home/jelastic/add-sftp-user-addon/
|
|
||||||
user: root
|
|
||||||
- return: uninstallSuccess
|
|
||||||
|
|
||||||
responses:
|
responses:
|
||||||
uninstallSuccess:
|
|
||||||
type: success
|
|
||||||
message: "Uninstalled Successfully"
|
|
||||||
installSuccess:
|
installSuccess:
|
||||||
type: success
|
type: success
|
||||||
message: "Installed Successfully"
|
message: "Installed Successfully"
|
||||||
|
|
Loading…
Reference in New Issue