From bdee68638ef276d3ad53ec84868c95fe1b058884 Mon Sep 17 00:00:00 2001 From: Roni Laukkarinen Date: Tue, 16 Apr 2024 18:37:56 +0300 Subject: [PATCH] Add self-updater, 2.4.0 --- CHANGELOG.md | 4 ++++ bin/macos.sh | 5 +++- bin/tasks/self-update.sh | 51 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 bin/tasks/self-update.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 18ce9fc..4c0e164 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### 2.4.0: 2024-04-16 + +* Add self-updater + ### 2.3.9: 2024-04-15 Please note: This version contains breaking change, if you are using older macos-lemp-setup and still have PHP 7.4 installed. diff --git a/bin/macos.sh b/bin/macos.sh index 69b7d00..75507c8 100755 --- a/bin/macos.sh +++ b/bin/macos.sh @@ -4,7 +4,7 @@ # Script specific vars SCRIPT_LABEL='for macOS' -SCRIPT_VERSION='1.1.3 (2024-04-15)' +SCRIPT_VERSION='1.1.4 (2024-04-16)' # Vars needed for this file to function globally CURRENTFILE=`basename $0` @@ -31,6 +31,9 @@ echo "${WHITE}Using this start script requires you have dev server installed and https://github.com/digitoimistodude/macos-lemp-setup ${TXTRESET}" +# First, let's check updates to self +source ${SCRIPTS_LOCATION}/tasks/self-update.sh + # Import required tasks source ${SCRIPTS_LOCATION}/tasks/imports.sh diff --git a/bin/tasks/self-update.sh b/bin/tasks/self-update.sh new file mode 100644 index 0000000..1465a01 --- /dev/null +++ b/bin/tasks/self-update.sh @@ -0,0 +1,51 @@ +# Temp colors +export YELLOW=$(tput setaf 3) +export GREEN=$(tput setaf 2) +export RED=$(tput setaf 1) +export TXTRESET=$(tput sgr0) + +# Check for symlink +echo "${YELLOW}Running self-updater...${TXTRESET}" + +if [ $0 != '/usr/local/bin/createproject' ]; then +echo "${TXTRESET}${WHITE}Please do NOT run this script with ${RED}sh $CURRENTFILE${WHITE} or ${RED}bash $CURRENTFILE${WHITE} or ${RED}./$CURRENTFILE${WHITE}. +Run this script globally instead by simply typing: ${GREEN}createproject{TXTRESET}. If this doesn't work, please run first setup from the bin folder first." +echo "" +exit +fi + +# Check for updates +# Get symlink path from /usr/local/bin/newtheme +SYMLINKPATH=$(sudo readlink /usr/local/bin/createproject) + +# Get project bin folder directory from symlink path +PROJECTBINFOLDER=$(sudo dirname $SYMLINKPATH) + +# Go one step back from bin to get theme root folder +PROJECTROOTFOLDER=$(sudo dirname $PROJECTBINFOLDER) + +# Go to the theme root folder +cd $PROJECTROOTFOLDER + +# Make sure no file mods are being committed +git config core.fileMode false --replace-all + +# Check for updates +git pull origin master + +# Ensure permissions are intact +sudo chmod +x /usr/local/bin/createproject + +# If there is something preventing the update, show error message +if [ $? -ne 0 ]; then +echo "" +echo "${TXTRESET}${RED}There was an error updating the start script. You have probably made changes to the dudestack files? Please commit those changes, send a PR or stash them. Please check the error message above and try again.${TXTRESET}" +echo "" + +# Stop script +exit 1 + +# If there are no errors, add line break +else +echo "" +fi