Added debug logs
parent
d7622fd2ab
commit
f38ef098fa
24
add-sftp.sh
24
add-sftp.sh
|
@ -1,33 +1,33 @@
|
|||
#!/bin/bash
|
||||
|
||||
echo "Script started" >> /home/jelastic/add-sftp-user-addon/script_output.log
|
||||
|
||||
# Generate random username and password
|
||||
USERNAME="user$(shuf -i 10000-99999 -n 1)"
|
||||
PASSWORD=$(openssl rand -base64 12)
|
||||
|
||||
# Set the user's home directory within the ROOT directory
|
||||
USER_HOME="/var/www/webroot/ROOT/$USERNAME"
|
||||
ROOT_DIRECTORY="/var/www/webroot/ROOT"
|
||||
|
||||
# Check if user already exists
|
||||
if id "$USERNAME" &>/dev/null; then
|
||||
echo "User $USERNAME already exists."
|
||||
echo "User $USERNAME already exists." >> /home/jelastic/add-sftp-user-addon/script_output.log
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create user with the specified home directory
|
||||
useradd -m -d $USER_HOME $USERNAME
|
||||
# Create user
|
||||
useradd -m -d $ROOT_DIRECTORY $USERNAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to create user $USERNAME."
|
||||
exit 1
|
||||
echo "Failed to create user $USERNAME." >> /home/jelastic/add-sftp-user-addon/script_output.log
|
||||
fi
|
||||
echo "$USERNAME:$PASSWORD" | chpasswd
|
||||
|
||||
# Set user's group to both litespeed and root
|
||||
usermod -aG litespeed,root $USERNAME
|
||||
|
||||
# Adjust permissions for the user to write to their home directory
|
||||
mkdir -p $USER_HOME
|
||||
chown $USERNAME:root $USER_HOME
|
||||
chmod 775 $USER_HOME
|
||||
# Adjust permissions for the user to write to the ROOT_DIRECTORY
|
||||
chown $USERNAME:root $ROOT_DIRECTORY
|
||||
chmod 775 $ROOT_DIRECTORY
|
||||
|
||||
# Get the hostname (if needed later in the script)
|
||||
# Get the hostname
|
||||
HOSTNAME=$(hostname -f)
|
||||
echo "Script completed for user $USERNAME with hostname $HOSTNAME" >> /home/jelastic/add-sftp-user-addon/script_output.log
|
||||
|
|
|
@ -52,12 +52,17 @@ actions:
|
|||
- cmd[cp]:
|
||||
commands: bash /home/jelastic/add-sftp-user-addon/add-sftp.sh
|
||||
user: root
|
||||
- if ("${response.exitStatus}" != "0"):
|
||||
return: sftpError
|
||||
- return: sftpSuccess
|
||||
|
||||
responses:
|
||||
installSuccess:
|
||||
type: success
|
||||
message: "Installed Successfully"
|
||||
sftpError:
|
||||
type: error
|
||||
message: "Failed to add SFTP user. Please check the server logs for more details."
|
||||
sftpSuccess:
|
||||
type: success
|
||||
email: |-
|
||||
|
|
Loading…
Reference in New Issue