Compare commits

...

2 Commits

Author SHA1 Message Date
9b70bd9480 databases initializer script
All checks were successful
gitea.arg.rip/deployment/pipeline/head This commit looks good
I think I figured it out. your -s << 'ENDMARKER' is looking for a line that starts with ENDMARKER - no spaces. so you can't indent it nicely.
2024-12-06 21:23:57 -05:00
84c023783f it was the newline 2024-12-06 20:58:44 -05:00
2 changed files with 19 additions and 10 deletions

19
scripts/databases.sh Normal file
View File

@ -0,0 +1,19 @@
#!/bin/bash
SUDOER_PSW=
pw_productiondatabase=
pw_developmentdatabase=
servicename=
service_dev="${servicename}_dev"
echo "${SUDOER_PSW}" | sudo -Su postgres psql && bash -s << 'ENDPSQL'
create database $servicename;
create user $servicename with encrypted password '$pw_productiondatabase';
grant all privileges on database $servicename to $servicename;
create database $service_dev;
create user $service_dev with encrypted password '$pw_developmentdatabase';
grant all privileges on database $service_dev to $service_dev;
ENDPSQL
exit

View File

@ -5,25 +5,15 @@ SUDOER_PSW=
function restofscript(){
USERNAMETOADD=
PASSWORDTOADD=
echo "hello, $(whoami)"
useradd -m -s /bin/bash ${USERNAMETOADD}
echo "user added"
echo "${USERNAMETOADD}:${PASSWORDTOADD}" | chpasswd
echo "password updated"
loginctl enable-linger ${USERNAMETOADD}
echo "linger enabled"
mkdir /home/${USERNAMETOADD}/.ssh
echo "user has .ssh/"
touch /home/${USERNAMETOADD}/authorized_keys
echo "user has .ssh/authorized keys"
cat ssh.pub >> /home/${USERNAMETOADD}/.ssh/authorized_keys
echo "authorized keys should accept ssh.pub"
chmod 600 /home/${USERNAMETOADD}/authorized_keys
echo "authorized keys should be mode 600"
chown -R "${USERNAMETOADD}:${USERNAMETOADD}" /home/${USERNAMETOADD}/.ssh
echo "correct user should own his .ssh directory. done!"
}
echo "${SUDOER_PSW}" | sudo -S bash -c "$(declare -f restofscript); restofscript"
echo "restofscript should be done, exiting."
exit