Skip to content

Commit

Permalink
Merge pull request #24 from hokus15/develop
Browse files Browse the repository at this point in the history
fix(update-ioconnect): fix update-iotconnect script
  • Loading branch information
hokus15 authored Mar 26, 2024
2 parents 82c8dc3 + f1ca507 commit 2131806
Showing 1 changed file with 56 additions and 12 deletions.
68 changes: 56 additions & 12 deletions scripts/update-iotconnect.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,63 @@
#!/bin/bash

update_app() {
# Get the latest tag
latest_tag=$(curl https://api.github.com/repos/$repo/releases/latest | grep \"tag_name\" | cut -d : -f 2,3 | tr -d \", | xargs)

echo "Updating IOTConnect to '${latest_tag}'..."

# Fectch all tags
git fetch --all --tags --prune
# Reset
git reset --hard
# Check if latest brand exists
if [ "`git branch --list latest`" ];
then
# Move to master to be able to delete 'latest' branch
git checkout master
# Delete 'latest' branch
git branch -D latest;
fi
# Checkout latest tag to 'latest' branch
git checkout tags/"$latest_tag" -b latest

echo "done!"
}

post_update() {
echo "Performing post update actions..."

# Change destination dir owner to pi:pi
sudo chown -R pi:pi "$dest_dir"
# Allow execution for scripts
sudo chmod +x "$dest_dir"/scripts/*.sh

# Update config files
cp "$dest_dir"/iotconnect/logging.live.conf iotconnect/logging.conf
cp "$dest_dir"/iotconnect/iotconnect.config.live.json iotconnect.config.json
sudo cp "$dest_dir"/scripts/*.sh ~
sudo chown -R pi:pi ~/*.sh
sudo chmod +x ~/*.sh

echo "done!"
}

repo="hokus15/IOTConnect"
dest_dir="/opt/IOTConnect"

cd "$dest_dir" || exit

echo 'Stopping IOTConnect service...'
sudo service iotconnect stop
echo 'done!'
cd /opt/IOTConnect
git fetch --tags
tag=$(git tag -l | tail -n 1)
echo "Updating IOTConnect to ${tag}..."
git reset --hard
git checkout master
git branch --delete latest
git checkout "$tag" -b latest
echo 'done!'
cp iotconnect/logging.live.conf iotconnect/logging.conf
sudo chown -R pi /opt/IOTConnect

update_app

post_update

sudo systemctl daemon-reload

echo 'Starting IOTConnect service...'
sudo service iotconnect start
echo 'done!'

echo 'Update complete!'

0 comments on commit 2131806

Please sign in to comment.