Skip to content

Commit

Permalink
Script to download and install latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
ecarrara committed Aug 17, 2023
1 parent 4587e77 commit a09a0df
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ If you are on OS X or Linux, you can use the installation script to fetch the
latest release:

```bash
curl https://raw.githubusercontent.com/ecarrara/obsidian-garden/main/install.toml | sh
curl https://raw.githubusercontent.com/ecarrara/obsidian-garden/main/install.sh | sh
```

## Getting Started
Expand Down
77 changes: 77 additions & 0 deletions install.sh
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."

0 comments on commit a09a0df

Please sign in to comment.