generated from solvaholic/template
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Teach install.sh to validate octodns_ref
and exit early if octodns-sync is already installed. See #57
- Loading branch information
1 parent
34df422
commit a3a3885
Showing
1 changed file
with
45 additions
and
7 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,18 +1,56 @@ | ||
#!/bin/bash | ||
# Install octodns and dependencies | ||
|
||
# Exit early if octodns is already installed | ||
if command -v octodns-sync; then | ||
# Hello reader! | ||
# This works as a cheap, relatively safe way to respond to #57 | ||
# If you'd like to improve it, please raise an issue or PR | ||
echo "FAIL: It looks like octodns is already installed." | ||
exit 1 | ||
fi | ||
|
||
# Set some variables | ||
_ver="$OCTODNS_REF" | ||
_src="$(mktemp -d)" | ||
_api="repos/octodns/octodns/git/matching-refs" | ||
_via="" | ||
|
||
if [[ "$_ver" = v* ]]; then | ||
# Assume input 'version' is an available release | ||
curl -O "https://raw.githubusercontent.com/octodns/octodns/$_ver/requirements.txt" | ||
pip install "octodns==${_ver#v}" -r requirements.txt | ||
# Is _ver a valid pip version or Git ref? | ||
if pip download -q "octodns==${_ver#v}"; then | ||
# _ver is a PyPI version | ||
_via=pip | ||
elif gh api --silent "$_api/tags/$_ver"; then | ||
# _ver is a tag in octodns/octodns | ||
_via=git | ||
elif gh api --silent "$_api/heads/$_ver"; then | ||
# _ver is a branch in octodns/octodns | ||
_via=git | ||
else | ||
# Assume input 'version' is a Git ref in octodns/octodns | ||
# _ver is not a branch, tag, or PyPI version | ||
echo "FAIL: Didn't find an octodns PyPI version or Git ref '$_ver'." | ||
exit 1 | ||
fi | ||
|
||
# Install octodns | ||
if [ "$_via" = "pip" ]; then | ||
# Use pip to install octodns | ||
_req="https://raw.githubusercontent.com/octodns/octodns/v${_ver#v}/requirements.txt" | ||
if curl --output "$_src/requirements.txt" "$_req"; then | ||
pip install "octodns==${_ver#v}" -r "$_src/requirements.txt" | ||
else | ||
echo "FAIL: Error downloading requirements.txt from octodns/octodns" | ||
fi | ||
elif [ "$_via" = "git" ]; then | ||
# Use Git and then pip to install octodns | ||
if git clone --single-branch --branch "$_ver" --no-tags \ | ||
https://github.com/octodns/octodns.git octodns-src; then | ||
pip install ./octodns-src -r ./octodns-src/requirements.txt | ||
https://github.com/octodns/octodns.git "$_src"; then | ||
pip install "$_src" -r "$_src/requirements.txt" | ||
else | ||
echo "FAIL: Error cloning octodns/octodns." | ||
exit 1 | ||
fi | ||
else | ||
echo "FAIL: How did this happen?" | ||
exit 1 | ||
fi |