From bfc69885295cd42561a7c822de657cdad7d61864 Mon Sep 17 00:00:00 2001 From: Osinachi Chukwujama Date: Fri, 19 Jul 2024 00:54:23 +0000 Subject: [PATCH 1/2] chore: include setup script for pm2 --- .../{nginx.sh => install_and_setup_nginx.sh} | 0 scripts/install_app_dependencies.sh | 33 ++++++++++++++++--- scripts/install_pm2.sh | 9 +++++ ...tgres_go.sh => install_postgres_and_go.sh} | 0 .../{postgres_setup.sh => setup_postgres.sh} | 0 5 files changed, 38 insertions(+), 4 deletions(-) rename scripts/{nginx.sh => install_and_setup_nginx.sh} (100%) create mode 100644 scripts/install_pm2.sh rename scripts/{postgres_go.sh => install_postgres_and_go.sh} (100%) rename scripts/{postgres_setup.sh => setup_postgres.sh} (100%) diff --git a/scripts/nginx.sh b/scripts/install_and_setup_nginx.sh similarity index 100% rename from scripts/nginx.sh rename to scripts/install_and_setup_nginx.sh diff --git a/scripts/install_app_dependencies.sh b/scripts/install_app_dependencies.sh index 2148aa62..82e8dcf5 100644 --- a/scripts/install_app_dependencies.sh +++ b/scripts/install_app_dependencies.sh @@ -6,8 +6,33 @@ if [ "$(id -u)" -ne 0 ]; then exit 1 fi -chmod +x nginx.sh postgres_go.sh postgres_setup.sh +# Define the script directory +SCRIPT_DIR="$HOME/scripts" -./nginx.sh -./postgres_go.sh -./postgres_setup.sh +# Ensure script directory exists +if [ ! -d "$SCRIPT_DIR" ]; then + echo "Script directory $SCRIPT_DIR does not exist." + exit 1 +fi + +# Array of scripts to execute +SCRIPTS=( + "install_and_setup_nginx.sh" + "install_postgres_and_go.sh" + "install_pm2.sh" + "setup_postgres.sh" +) + +# Make all scripts executable and execute them +for script in "${SCRIPTS[@]}"; then + SCRIPT_PATH="$SCRIPT_DIR/$script" + + if [ -f "$SCRIPT_PATH" ]; then + chmod +x "$SCRIPT_PATH" + echo "Executing $SCRIPT_PATH..." + "$SCRIPT_PATH" + else + echo "Script $SCRIPT_PATH does not exist." + exit 1 + fi +done \ No newline at end of file diff --git a/scripts/install_pm2.sh b/scripts/install_pm2.sh new file mode 100644 index 00000000..d2e2d654 --- /dev/null +++ b/scripts/install_pm2.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash +export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" +[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm + +nvm install 20 + +npm i -g pm2 \ No newline at end of file diff --git a/scripts/postgres_go.sh b/scripts/install_postgres_and_go.sh similarity index 100% rename from scripts/postgres_go.sh rename to scripts/install_postgres_and_go.sh diff --git a/scripts/postgres_setup.sh b/scripts/setup_postgres.sh similarity index 100% rename from scripts/postgres_setup.sh rename to scripts/setup_postgres.sh From bd1dc55190f8191b85b2f312360cbae92f768def Mon Sep 17 00:00:00 2001 From: Osinachi Chukwujama Date: Fri, 19 Jul 2024 02:03:43 +0100 Subject: [PATCH 2/2] Update install_app_dependencies.sh to include a dir check Signed-off-by: Osinachi Chukwujama --- scripts/install_app_dependencies.sh | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/scripts/install_app_dependencies.sh b/scripts/install_app_dependencies.sh index 82e8dcf5..3d661c0e 100644 --- a/scripts/install_app_dependencies.sh +++ b/scripts/install_app_dependencies.sh @@ -1,17 +1,17 @@ #!/bin/bash -# Check if the script is run as root +# Ensure the script is run as root if [ "$(id -u)" -ne 0 ]; then echo "This script must be run as root. Use sudo." exit 1 fi -# Define the script directory -SCRIPT_DIR="$HOME/scripts" +# Ensure the script is run from the scripts directory directly +SCRIPT_DIR_NAME="scripts" +CURRENT_DIR_NAME=$(basename "$PWD") -# Ensure script directory exists -if [ ! -d "$SCRIPT_DIR" ]; then - echo "Script directory $SCRIPT_DIR does not exist." +if [ "$CURRENT_DIR_NAME" != "$SCRIPT_DIR_NAME" ]; then + echo "This script must be run from the $SCRIPT_DIR_NAME directory." exit 1 fi @@ -24,15 +24,13 @@ SCRIPTS=( ) # Make all scripts executable and execute them -for script in "${SCRIPTS[@]}"; then - SCRIPT_PATH="$SCRIPT_DIR/$script" - - if [ -f "$SCRIPT_PATH" ]; then - chmod +x "$SCRIPT_PATH" - echo "Executing $SCRIPT_PATH..." - "$SCRIPT_PATH" +for script in "${SCRIPTS[@]}"; do + if [ -f "$script" ]; then + chmod +x "$script" + echo "Executing $script..." + ./"$script" else - echo "Script $SCRIPT_PATH does not exist." + echo "Script $script does not exist." exit 1 fi -done \ No newline at end of file +done