-
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.
Script to download and install latest version
- Loading branch information
Showing
2 changed files
with
78 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/bin/bash | ||
set -eu | ||
|
||
PROGRAM_NAME=obsidian-garden | ||
BASE_URL=https://github.com/ecarrara/obsidian-garden/releases/latest/download | ||
|
||
message () { | ||
case $1 in | ||
error) tput setaf 1 2>/dev/null ;; | ||
success) tput setaf 2 2>/dev/null ;; | ||
warning) tput setaf 3 2>/dev/null ;; | ||
info) tput setaf 4 2>/dev/null ;; | ||
esac | ||
|
||
echo $2 | ||
|
||
tput sgr0 2>/dev/null | ||
} | ||
|
||
exists () { | ||
command -v "$1" 1>/dev/null 2>&1 | ||
} | ||
|
||
download () { | ||
url="$1" | ||
destination="$2" | ||
sudo="${3-}" | ||
|
||
if exists curl; then | ||
cmd="curl --silent --fail --location --output $destination $url" | ||
elif has wget; then | ||
cmd="wget --quiet --output-document $destination $url" | ||
else | ||
message error "Unable to found curl or wget, exiting..." | ||
return 2 | ||
fi | ||
|
||
message info "Downloading $url to $destination" | ||
$sudo $cmd | ||
} | ||
|
||
detect_platform () { | ||
platform=$(uname -s | tr '[:upper:]' '[:lower:]') | ||
case "$platform" in | ||
linux) platform="linux" ;; | ||
darwin) platform="macos" ;; | ||
esac | ||
echo -n "$platform" | ||
} | ||
|
||
detect_arch () { | ||
arch=$(uname -m | tr '[:upper:]' '[:lower:]') | ||
case "$arch" in | ||
x86_64) arch="amd64" ;; | ||
esac | ||
echo -n "$arch" | ||
} | ||
|
||
|
||
PLATFORM=$(detect_platform) | ||
ARCH=$(detect_arch) | ||
|
||
if [ -z "${INSTALL_DIR-}" ]; then | ||
INSTALL_DIR=/usr/local/bin | ||
fi | ||
|
||
URL=${BASE_URL}/${PROGRAM_NAME}-${PLATFORM}-${ARCH} | ||
TARGET=${INSTALL_DIR}/${PROGRAM_NAME} | ||
|
||
if [ -w "$INSTALL_DIR" ]; then | ||
download $URL $TARGET | ||
else | ||
message warning "$INSTALL_DIR is not writable, sudo is required." | ||
download $URL $TARGET sudo | ||
fi | ||
|
||
message success "$PROGRAM_NAME installed." |