Last active
February 27, 2022 13:25
-
-
Save rhld16/cec05093d9927084097f3b0e731206ef to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env bash | |
# bash script to install zoffline | |
zofflineGitUrl="https://github.com/zoffline/zwift-offline.git" | |
zOfflineArchiveUrl="https://github.com/zoffline/zwift-offline/archive/refs/heads/master.zip" | |
pipPackages="flask flask_sqlalchemy flask-login pyjwt gevent protobuf protobuf3_to_dict requests" | |
optionalStravaPackages="stravalib" | |
optionalGarminPackages="garmin-uploader cryptography" | |
optionalDiscordPackages="discord" | |
ask() { | |
local prompt default reply | |
if [[ ${2:-} = 'Y' ]]; then | |
prompt='Y/n' | |
default='Y' | |
elif [[ ${2:-} = 'N' ]]; then | |
prompt='y/N' | |
default='N' | |
else | |
prompt='y/n' | |
default='' | |
fi | |
while true; do | |
echo -n "$1 [$prompt] " | |
read -r reply </dev/tty | |
if [[ -z $reply ]]; then | |
reply=$default | |
fi | |
case "$reply" in | |
Y*|y*) return 0 ;; | |
N*|n*) return 1 ;; | |
esac | |
done | |
} | |
echo "This script will install a zwift-offline server in the current directory." | |
if ask "Do you want to install strava packages?" N; then | |
pipPackages="$pipPackages $optionalStravaPackages" | |
fi | |
if ask "Do you want to install garmin packages?" N; then | |
pipPackages="$pipPackages $optionalGarminPackages" | |
fi | |
if ask "Do you want to install discord packages?" N; then | |
pipPackages="$pipPackages $optionalDiscordPackages" | |
fi | |
echo "Downloading zoffline..." | |
if [ -x "$(command -v git)" ]; then | |
git clone --quiet $zofflineGitUrl | |
else | |
if [ ! -d "zwift-offline" ]; then | |
echo "git not found, downloading zwift-offline from $zOfflineArchiveUrl" | |
if [ -x "$(command -v curl)" ]; then | |
curl -L $zOfflineArchiveUrl -o zwift-offline.zip | |
elif [ -x "$(command -v wget)" ]; then | |
wget $zOfflineArchiveUrl -O zwift-offline.zip | |
else | |
echo "curl or wget is not installed. Please install one of them and try again." | |
exit 1 | |
fi | |
unzip -q zwift-offline.zip | |
mv zwift-offline-master zwift-offline | |
rm zwift-offline.zip | |
fi | |
fi | |
if [ -x "$(command -v virtualenv)" ]; then | |
echo "Creating virtualenv in zwift-offline..." | |
virtualenv -p python3 zwift-offline/venv | |
echo "Installing pip packages: $pipPackages" | |
zwift-offline/venv/bin/pip3 install -q $pipPackages | |
runCommand="venv/bin/python3 standalone.py" | |
else | |
echo "virtualenv is not installed, installing pip packages globally: $pipPackages" | |
pip3 install -q $pipPackages | |
runCommand="python3 standalone.py" | |
fi | |
echo "zwift-offline installed! Use '$runCommand' to run the server." | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment