It might look silly to have several scripts instead of just one, but there are a reasons for it.
Modularity and reusable code: I have different deployment scripts that make use of the same task-related sub-scripts.
Security: One of those task-related scripts is the one that exports the keys of my application as OS environment variables. You are supposed to ask the admin for that script (It is out of version control for security reasons) and copy paste it where you are told before the deployment. That's easier and cleaner than copy-pasting its code at a certain line of a gigantic script with duplicated code.
This is the script that works for me currently. The problem I want to solve is that I have to enter the ssh password several times (5 in this case) and I would like to do it just once at the beginning:
#!/usr/bin/env bash
set -e
PROJECT_PARENT_DIR=/srv/webapps
PROJECT_DIR_NAME=example
PROJECT_REPO_URL=https://github.com/user/example.git
VIRTUALENV_PARENT_DIR=/srv/virtualenvs
VIRTUALENV_DIR_NAME=example
ssh root@serverip "bash -s" < setup/download_project.sh $PROJECT_PARENT_DIR $PROJECT_DIR_NAME $PROJECT_REPO_URL
ssh root@serverip "bash -s" < setup/create_virtualenv.sh $VIRTUALENV_PARENT_DIR $VIRTUALENV_DIR_NAME
ssh root@serverip "bash -s" < setup/export_production_keys.sh production $VIRTUALENV_PARENT_DIR $VIRTUALENV_DIR_NAME
ssh root@serverip "bash -s" < setup/configure_project.sh production $PROJECT_PARENT_DIR $PROJECT_DIR_NAME $VIRTUALENV_PARENT_DIR $VIRTUALENV_DIR_NAME
ssh root@serverip "bash -s" < setup/configure_server.sh production $PROJECT_PARENT_DIR $PROJECT_DIR_NAME $VIRTUALENV_PARENT_DIR $VIRTUALENV_DIR_NAME
echo -e "\e[32mPRODUCTION DEPLOYMENT IS FINISHED! LISTENING AT http://example.com\e[0m"
echo ""
I was not able to find a similar question/answer on Stack Overflow or other internet sources to help me with this.