Skip to content

Instantly share code, notes, and snippets.

@charlesmarshall
Created September 10, 2014 14:16
Show Gist options
  • Save charlesmarshall/832f212d4251ef2d6844 to your computer and use it in GitHub Desktop.
Save charlesmarshall/832f212d4251ef2d6844 to your computer and use it in GitHub Desktop.
replace fleet with other version
#!/bin/bash
fleet_location=""
fleetctl_location=""
version=""
delete_existing_dl(){
rm -Rf ./fleet-v${1}*
}
download(){
wget https://github.com/coreos/fleet/releases/download/v${1}/fleet-v${1}-linux-amd64.tar.gz
}
extract(){
tar xvzf fleet-v${1}-linux-amd64.tar.gz 2> /dev/null
rm fleet-v${1}-linux-amd64.tar.gz
}
which_fleet(){
fleet_location=$(which fleet)
fleetctl_location=$(which fleetctl)
}
fleet_version(){
if [[ ! -z $fleetctl_location ]]; then
version=$(fleetctl --version | sed -E 's#fleetctl version ##')
fi
}
fleet_link(){
sudo rm ${fleet_location}
sudo rm ${fleet_location}d
path="$(pwd)/fleet-v${1}-linux-amd64/fleet"
if [[ ! -f $path ]]; then
path="$(pwd)/fleet-v${1}-linux-amd64/fleetd"
fi
sudo ln -s ${path} ${fleet_location}
sudo ln -s ${path} ${fleet_location}d
}
fleetctl_link(){
sudo rm ${fleetctl_location}
path="$(pwd)/fleet-v${1}-linux-amd64/fleetctl"
sudo ln -s ${path} ${fleetctl_location}
}
# find versions & location of fleet
which_fleet
fleet_version
if [[ -z $version ]]; then
echo "Fleet not installed, installing"
download $1
extract $1
# coreos locations
fleetctl_location="/usr/bin/fleetctl"
fleet_location="/usr/bin/fleet"
fleet_link $1
fleetctl_link $1
else
echo "Fleet: ${fleet_location}"
echo "Fleetctl: ${fleetctl_location}"
echo "Version: ${version}"
read -p "Replace ${version} with ${1}? " replace
if [[ "$replace" == "y" ]]; then
delete_existing_dl $1
download $1
extract $1
fleet_link $1
fleetctl_link $1
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment