Skip to content

Commit

Permalink
Add self-updater to the start script
Browse files Browse the repository at this point in the history
  • Loading branch information
ronilaukkarinen committed Sep 12, 2023
1 parent 1e846ac commit 90f6eab
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### [Unreleased]
### 9.3.5: 2023-09-12

* Use semver + date in newtheme.sh start script
* Add self-updater to the start script

### 9.3.4: 2023-09-07

Expand Down
5 changes: 4 additions & 1 deletion bin/newtheme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# Script specific vars
SCRIPT_LABEL='for macOS'
SCRIPT_VERSION='1.1.2 (2023-09-12)'
SCRIPT_VERSION='1.1.3 (2023-09-12)'

# Vars needed for this file to function globally
CURRENTFILE=`basename $0`
Expand All @@ -31,6 +31,9 @@ https://github.com/digitoimistodude/macos-lemp-setup
https://github.com/digitoimistodude/air-light
${TXTRESET}"

# First, let's check updates to self
source ${SCRIPTS_LOCATION}/tasks/self-update.sh

# Import required tasks
source ${SCRIPTS_LOCATION}/tasks/imports.sh

Expand Down
37 changes: 37 additions & 0 deletions bin/tasks/self-update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Check for symlink
echo "${YELLOW}Running self-updater...${TXTRESET}"

if [ $0 != '/usr/local/bin/newtheme' ]; 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}newtheme${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=$(readlink /usr/local/bin/newtheme)

# Get theme bin folder directory from symlink path
THEMEBINFOLDER=$(dirname $SYMLINKPATH)

# Go one step back from bin to get theme root folder
THEMEROOTFOLDER=$(dirname $THEMEBINFOLDER)

# Go to the theme root folder
cd $THEMEROOTFOLDER

# Make sure no file mods are being committed
git config core.fileMode false

# Check for updates
git pull origin master

# If there is something preventing the update, show error message
if [ $? -ne 0 ]; then
echo "${TXTRESET}${WHITE}There was an error updating the start script. You have probably made changes to the air-light theme? Please commit those changes, send a PR or stash them. Please check the error message above and try again."

# If there are no errors, show success message
else
echo "${TXTRESET}${boldgreen}The start script newtheme.sh has been updated successfully to the latest version.${TXTRESET}"
fi

0 comments on commit 90f6eab

Please sign in to comment.