From 352ce49693fd56aab05b83939fc1b684b121639f Mon Sep 17 00:00:00 2001 From: Grey Vugrin Date: Mon, 22 Jan 2024 13:57:00 -0800 Subject: [PATCH 1/2] Update permissions for pm2, laravel app-release commands --- laravel-deploy/app-release | 13 ++++++++++++- pm2-deploy/app-release | 15 +++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/laravel-deploy/app-release b/laravel-deploy/app-release index 0835bb2..fd4c30c 100755 --- a/laravel-deploy/app-release +++ b/laravel-deploy/app-release @@ -199,7 +199,18 @@ sudo chmod 777 "$CURRENT/bootstrap" -R sudo mkdir -p "$REPO_ROOT/$LARAVELLOGSFOLDER_LOCATION" ## Change ownership of the logs folder -sudo chown $OWNER_USER:$OWNER_GROUP "$REPO_ROOT/$LARAVELLOGSFOLDER_LOCATION" +# If the logs location has a /, loop through and chown each one +# Prevents issues with paths like Parent/Logs, `chown` will not change the permissions of Parent +if [[ $LARAVELLOGSFOLDER_LOCATION == *\/* ]]; then + IFS='/' read -ra ADDR <<< "$LARAVELLOGSFOLDER_LOCATION" + for i in "${ADDR[@]}"; do + # join the path, but there should be no leading slash if it's the first one + CUR_LOG_PATH="${CUR_LOG_PATH:+$CUR_LOG_PATH/}$i" + sudo chown $OWNER_USER:$OWNER_GROUP "$REPO_ROOT/$CUR_LOG_PATH" + done +else + sudo chown $OWNER_USER:$OWNER_GROUP "$REPO_ROOT/$LARAVELLOGSFOLDER_LOCATION" +fi ## Change back to the commands directory cd $RELEASING_FROM diff --git a/pm2-deploy/app-release b/pm2-deploy/app-release index 5b8aca9..ed5fd61 100755 --- a/pm2-deploy/app-release +++ b/pm2-deploy/app-release @@ -148,11 +148,22 @@ fi REPO_ROOT=$(pwd) -# Add Logs Folder +# Add logs folder sudo mkdir -p "$REPO_ROOT/$APPLOGSFOLDER_LOCATION" ## Change ownership of the logs folder -sudo chown $OWNER_USER:$OWNER_GROUP "$REPO_ROOT/$APPLOGSFOLDER_LOCATION" +# If the logs location has a /, loop through and chown each one +# Prevents issues with paths like Parent/Logs, `chown` will not change the permissions of Parent +if [[ $APPLOGSFOLDER_LOCATION == *\/* ]]; then + IFS='/' read -ra ADDR <<< "$APPLOGSFOLDER_LOCATION" + for i in "${ADDR[@]}"; do + # join the path, but there should be no leading slash if it's the first one + CUR_LOG_PATH="${CUR_LOG_PATH:+$CUR_LOG_PATH/}$i" + sudo chown $OWNER_USER:$OWNER_GROUP "$REPO_ROOT/$CUR_LOG_PATH" + done +else + sudo chown $OWNER_USER:$OWNER_GROUP "$REPO_ROOT/$APPLOGSFOLDER_LOCATION" +fi # Go into the repo's appfolder, where npm is? cd $REPO_ROOT/$APPFOLDER From 7cdb11551f777f31f74aca755980e13f71dfe9e0 Mon Sep 17 00:00:00 2001 From: Grey Vugrin Date: Thu, 25 Jan 2024 12:14:17 -0800 Subject: [PATCH 2/2] Updated log folder creation to handle chmod --- laravel-deploy/app-release | 3 ++- pm2-deploy/app-release | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/laravel-deploy/app-release b/laravel-deploy/app-release index fd4c30c..44a51b3 100755 --- a/laravel-deploy/app-release +++ b/laravel-deploy/app-release @@ -196,7 +196,7 @@ sudo chmod 777 "$CURRENT/storage" -R sudo chmod 777 "$CURRENT/bootstrap" -R ## Make Logs Directory -sudo mkdir -p "$REPO_ROOT/$LARAVELLOGSFOLDER_LOCATION" +sudo mkdir -m 775 -p "$REPO_ROOT/$LARAVELLOGSFOLDER_LOCATION" ## Change ownership of the logs folder # If the logs location has a /, loop through and chown each one @@ -207,6 +207,7 @@ if [[ $LARAVELLOGSFOLDER_LOCATION == *\/* ]]; then # join the path, but there should be no leading slash if it's the first one CUR_LOG_PATH="${CUR_LOG_PATH:+$CUR_LOG_PATH/}$i" sudo chown $OWNER_USER:$OWNER_GROUP "$REPO_ROOT/$CUR_LOG_PATH" + sudo chmod 775 "$REPO_ROOT/$CUR_LOG_PATH" done else sudo chown $OWNER_USER:$OWNER_GROUP "$REPO_ROOT/$LARAVELLOGSFOLDER_LOCATION" diff --git a/pm2-deploy/app-release b/pm2-deploy/app-release index ed5fd61..b7d5da2 100755 --- a/pm2-deploy/app-release +++ b/pm2-deploy/app-release @@ -149,7 +149,7 @@ fi REPO_ROOT=$(pwd) # Add logs folder -sudo mkdir -p "$REPO_ROOT/$APPLOGSFOLDER_LOCATION" +sudo mkdir -m 775 -p "$REPO_ROOT/$APPLOGSFOLDER_LOCATION" ## Change ownership of the logs folder # If the logs location has a /, loop through and chown each one @@ -160,6 +160,7 @@ if [[ $APPLOGSFOLDER_LOCATION == *\/* ]]; then # join the path, but there should be no leading slash if it's the first one CUR_LOG_PATH="${CUR_LOG_PATH:+$CUR_LOG_PATH/}$i" sudo chown $OWNER_USER:$OWNER_GROUP "$REPO_ROOT/$CUR_LOG_PATH" + sudo chmod 775 "$REPO_ROOT/$CUR_LOG_PATH" done else sudo chown $OWNER_USER:$OWNER_GROUP "$REPO_ROOT/$APPLOGSFOLDER_LOCATION"