-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from hokus15/develop
fix(update-ioconnect): fix update-iotconnect script
- Loading branch information
Showing
1 changed file
with
56 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!' |