From 2433a7db990adf077b6985876f13faf8664c93fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=B4=D8=B1=D9=83=D8=A9=20=D8=AE=D8=A8=D9=8A=D8=B1=20?= =?UTF-8?q?=D8=A7=D9=84=D9=85=D8=AD=D8=AF=D9=88=D8=AF=D8=A9?= Date: Sun, 18 Aug 2024 16:31:01 +0300 Subject: [PATCH] Create pull_code.sh --- scripts/pull_code.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 scripts/pull_code.sh diff --git a/scripts/pull_code.sh b/scripts/pull_code.sh new file mode 100644 index 000000000..7e898332a --- /dev/null +++ b/scripts/pull_code.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# Author: Moutaz Muhammad + +set -euo pipefail + +# Validate input parameters +if [ "$#" -lt 5 ]; then + echo "** [ERROR] Usage: $0 " + exit 1 +fi + +PROJECT_USER="$1" +PROJECT_PATH="$2" +PROJECT_SERVICE="$3" +STAGE="$4" +FOLDER="$5" +BRANCH="$6" + +# Stash changes before pulling +sudo -u "$PROJECT_USER" bash -c "cd '$PROJECT_PATH/$STAGE/$FOLDER' && git stash && git stash clear && git pull origin '$BRANCH'" +if [ $? -eq 0 ]; then + echo "** [INFO] Git pull origin $BRANCH command executed successfully." +else + echo "** [ERROR] Git pull origin $BRANCH command failed." + exit 1 +fi + +# Restart the project service +sudo systemctl restart "$PROJECT_SERVICE" +if [ $? -eq 0 ]; then + echo "** [INFO] $BRANCH service has been restarted." +else + echo "** [ERROR] Failed to restart $BRANCH service." + exit 1 +fi