#!/bin/sh

TARGET=root@${1}

CMD_ATP="apt update; apt install -y vsftpd python3 python3-pip sqlite3 python3-waitress"
CMD_PIP="python3 -m pip install flask flask-sqlalchemy"
CMD_FLASK_USER="useradd -m flask; usermod -L flask"
CMD_SUDOERS_ADD="echo 'flask      ALL=(ALL)     NOPASSWD: /home/flask/jeffrey_miller_flask_ftp/scripts/create_user.sh' >> /etc/sudoers"
CMD_SUDOERS_DEL="echo 'flask      ALL=(ALL)     NOPASSWD: /home/flask/jeffrey_miller_flask_ftp/scripts/delete_user.sh' >> /etc/sudoers"

ssh -t ${TARGET} "${CMD_ATP}"
ssh -t ${TARGET} "${CMD_PIP}"
ssh -t ${TARGET} "${CMD_FLASK_USER}"
ssh -t ${TARGET} "${CMD_SUDOERS_ADD}"
ssh -t ${TARGET} "${CMD_SUDOERS_DEL}"

rsync -rP ../jeffrey_miller_flask_ftp ${TARGET}:/home/flask/

CMD_OWNERSHIP="chown -R flask:flask /home/flask"

ssh -t ${TARGET} "${CMD_OWNERSHIP}"

CMD_SET_FTP_WRITE_YES="sed -i 's/\#write_enable=YES/write_enable=YES/' /etc/vsftpd.conf"
CMD_RESTART_FTP="systemctl restart vsftpd"
ssh -t ${TARGET} "${CMD_SET_FTP_WRITE_YES}"
ssh -t ${TARGET} "${CMD_RESTART_FTP}"
