Last active
July 13, 2018 09:17
-
-
Save shokinn/9eb8b9e39e8a73e4ad085cd9c75a3b4f to your computer and use it in GitHub Desktop.
Concourse/Fly update/install scripts
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
#!/bin/bash | |
# | |
# App update script | |
# by Philip "ShokiNN'" Henning <mail@philip-henning.com> | |
# | |
# License: MIT | |
# Copyright 2018 Philip Henning | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
# | |
# Check if script runs as root | |
if [ $UID != 0 ]; then | |
echo "You have to run this script as root or with sudo." | |
exit 1 | |
fi | |
app="Concourse" | |
dir='/usr/local/bin' | |
bin='concourse' | |
url='https://api.github.com/repos/concourse/concourse/releases/latest' | |
# Check if the app is installed, and when yes compare versions. | |
if [[ ! -f $dir/$bin ]]; then | |
read -p "Do you want to install $app? (Y/N): " install | |
while true; do | |
case $install in | |
[Yy]*) | |
break | |
;; | |
[Nn]*) | |
exit 0 | |
;; | |
*) | |
echo "Please answer yes or no." | |
;; | |
esac | |
done | |
elif [[ -f $dir/$bin ]]; then | |
# Get installed version number | |
lcl_version=$($bin -v) | |
# Get stable release version number | |
rmt_version=$(curl -s $url | grep "^[[:space:]]*\"tag_name.*v.*$" | awk '{split($0,a,"\""); print a[4]}' | cut -c 2-) | |
# Check if version numbers differs | |
if [ "$lcl_version" != "$rmt_version" ]; then | |
echo "You local version number differs from the latest $app version:" | |
echo "Local $app Version: $lcl_version" | |
echo "Remote $app Version: $rmt_version" | |
read -p "Do you want to update $app? (Y/N): " update | |
while true; do | |
case $update in | |
[Yy]*) | |
break | |
;; | |
[Nn]*) | |
exit 0 | |
;; | |
*) | |
echo "Please answer yes or no." | |
;; | |
esac | |
done | |
else | |
echo "You're up to date." | |
exit 0 | |
fi | |
fi | |
# Delete dir if exists | |
if [ -d /tmp/$bin-update ]; then | |
rm -rf /tmp/$bin-update | |
fi | |
# Check if download folder exists | |
if [ ! -d /tmp/$bin-update ]; then | |
mkdir /tmp/$bin-update | |
fi | |
# Change to the download directory | |
cd /tmp/$bin-update | |
# Download the latest stable release | |
curl -s $url \ | |
| grep "browser_download_url.*"$bin"_linux_amd64\"$" \ | |
| cut -d : -f 2,3 \ | |
| cut -c 2- \ | |
| tr -d \" \ | |
| wget -i - | |
# Check if the app is running | |
if [[ ( $(systemctl is-active concourse-worker.service) == "active" ) || ( $(systemctl is-active concourse-web.service) == "active" ) ]]; then | |
while true; do | |
read -p "Do you want to stop the $app server and install the update? (Y/N): " install_update | |
case $install_update in | |
[Yy]*) | |
systemctl stop concourse-worker.service | |
systemctl stop concourse-web.service | |
break | |
;; | |
[Nn]*) | |
exit 1 | |
;; | |
*) | |
echo "Please answer yes or no." | |
;; | |
esac | |
done | |
fi | |
# Install App | |
mv /tmp/$bin-update/*_linux_amd64 $dir/$bin | |
chmod +x $dir/$bin | |
cd .. | |
rm -rf /tmp/$bin-update | |
# Start the Services | |
while true; do | |
read -p "Do you want to start the $app server? (Y/N): " start_server | |
case $start_server in | |
[Yy]*) | |
systemctl start concourse-worker.service | |
systemctl start concourse-web.service | |
break | |
;; | |
[Nn]*) | |
break | |
;; | |
*) | |
echo "Please answer yes or no." | |
;; | |
esac | |
done | |
exit 0 |
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
#!/bin/bash | |
# | |
# App update script | |
# by Philip "ShokiNN'" Henning <mail@philip-henning.com> | |
# | |
# License: MIT | |
# Copyright 2018 Philip Henning | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
# | |
# Check if script runs as root | |
if [ $UID != 0 ]; then | |
echo "You have to run this script as root or with sudo." | |
exit 1 | |
fi | |
app="fly" | |
dir='/usr/local/bin' | |
bin='fly' | |
url='https://api.github.com/repos/concourse/concourse/releases/latest' | |
# Check if the app is installed, and when yes compare versions. | |
if [[ ! -f $dir/$bin ]]; then | |
read -p "Do you want to install $app? (Y/N): " install | |
while true; do | |
case $install in | |
[Yy]*) | |
break | |
;; | |
[Nn]*) | |
exit 0 | |
;; | |
*) | |
echo "Please answer yes or no." | |
;; | |
esac | |
done | |
elif [[ -f $dir/$bin ]]; then | |
# Get installed version number | |
lcl_version=$($bin -v) | |
# Get stable release version number | |
rmt_version=$(curl -s $url | grep "^[[:space:]]*\"tag_name.*v.*$" | awk '{split($0,a,"\""); print a[4]}' | cut -c 2-) | |
# Check if version numbers differs | |
if [ "$lcl_version" != "$rmt_version" ]; then | |
echo "You local version number differs from the latest $app version:" | |
echo "Local $app Version: $lcl_version" | |
echo "Remote $app Version: $rmt_version" | |
read -p "Do you want to update $app? (Y/N): " update | |
while true; do | |
case $update in | |
[Yy]*) | |
break | |
;; | |
[Nn]*) | |
exit 0 | |
;; | |
*) | |
echo "Please answer yes or no." | |
;; | |
esac | |
done | |
else | |
echo "You're up to date." | |
exit 0 | |
fi | |
fi | |
# Delete dir if exists | |
if [ -d /tmp/$bin-update ]; then | |
rm -rf /tmp/$bin-update | |
fi | |
# Check if download folder exists | |
if [ ! -d /tmp/$bin-update ]; then | |
mkdir /tmp/$bin-update | |
fi | |
# Change to the download directory | |
cd /tmp/$bin-update | |
# Download the latest stable release | |
curl -s $url \ | |
| grep "browser_download_url.*"$bin"_linux_amd64\"$" \ | |
| cut -d : -f 2,3 \ | |
| cut -c 2- \ | |
| tr -d \" \ | |
| wget -i - | |
# Install App | |
mv /tmp/$bin-update/*_linux_amd64 $dir/$bin | |
chmod +x $dir/$bin | |
cd .. | |
rm -rf /tmp/$bin-update | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment