-
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.
feat: add install and config scripts
- Loading branch information
Showing
4 changed files
with
143 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Scripts | ||
|
||
## Download and Installation | ||
|
||
Use the `install_binary.sh` or `install_distribution.sh` scripts to download and install the sparrow binary on a machine. | ||
|
||
`install_binary.sh` will download and extract the packed binary from GitHub. | ||
|
||
`install_distribution.sh` will detect the systems distribution and installs the right version of the sparrow with the common package manager. | ||
|
||
## Config | ||
|
||
Use the `get_config.sh` script to download a remote startup configuration file. | ||
Pass the sparrow name, the url where the config is located and the token that is needed for authentication. | ||
The token will be used in the config for the sparrow registration and check configuration as well! |
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,32 @@ | ||
|
||
#!/bin/bash | ||
|
||
# Check if two arguments are passed | ||
if [ "$#" -ne 3 ]; then | ||
echo "Usage: $0 <DNS_NAME> <REPO_URL> <TOKEN>" | ||
exit 1 | ||
fi | ||
|
||
DNS_NAME=$1 | ||
REPO_URL=$2 | ||
TOKEN=$3 | ||
|
||
# Download the file | ||
HTTP_RESPONSE=$(curl -s -w "%{http_code}" --header "PRIVATE-TOKEN: $TOKEN" -o .sparrow.yaml "$REPO_URL") | ||
|
||
# Check if the download was successful | ||
if [ "$HTTP_RESPONSE" -ne 200 ]; then | ||
echo "Failed to download .sparrow.yaml, HTTP response code: $HTTP_RESPONSE" | ||
exit 1 | ||
fi | ||
|
||
# Replace <TOKEN> and <DNS_NAME> with the provided arguments | ||
sed -i "s/<DNS_NAME>/$DNS_NAME/g" .sparrow.yaml | ||
sed -i "s/<TOKEN>/$TOKEN/g" .sparrow.yaml | ||
|
||
echo "Downloaded and modified .sparrow.yaml configuration file" | ||
|
||
# Move the modified cfg.yaml to the home directory as .sparrow.yaml | ||
mv .sparrow.yaml $HOME/.sparrow.yaml | ||
|
||
echo "Moved .sparrow.yaml to HOME: $HOME/.sparrow.yaml" |
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,34 @@ | ||
#!/bin/bash | ||
|
||
# Get the system architecture | ||
ARCH=$(uname -m) | ||
|
||
# Map the system architecture to the corresponding one used by the GitHub repository | ||
case $ARCH in | ||
"x86_64") | ||
ARCH="amd64" | ||
;; | ||
"aarch64") | ||
ARCH="arm64" | ||
;; | ||
*) | ||
echo "Unsupported architecture: $ARCH" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
# Get the latest release version and trim the leading 'v' | ||
VERSION=$(curl -s https://api.github.com/repos/caas-team/sparrow/releases/latest | grep 'tag_name' | cut -d\" -f4 | tr -d v) | ||
|
||
# Construct the download URL | ||
URL="https://github.com/caas-team/sparrow/releases/download/v${VERSION}/sparrow_${VERSION}_linux_${ARCH}.tar.gz" | ||
|
||
# Download the binary | ||
curl -L $URL -o "sparrow_${VERSION}_linux_${ARCH}.tar.gz" | ||
|
||
echo "Downloaded sparrow for $ARCH, version $VERSION" | ||
|
||
# Unpack the binary | ||
tar -xzf "sparrow_${VERSION}_linux_${ARCH}.tar.gz" | ||
|
||
echo "Unpacked 'sparrow'" |
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,62 @@ | ||
#!/bin/bash | ||
|
||
# Get the system architecture | ||
ARCH=$(uname -m) | ||
|
||
# Map the system architecture to the corresponding one used by the GitHub repository | ||
case $ARCH in | ||
"x86_64") | ||
ARCH="amd64" | ||
;; | ||
"aarch64") | ||
ARCH="arm64" | ||
;; | ||
*) | ||
echo "Unsupported architecture: $ARCH" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
# Get the latest release version and trim the leading 'v' | ||
VERSION=$(curl -s https://api.github.com/repos/caas-team/sparrow/releases/latest | grep 'tag_name' | cut -d\" -f4 | tr -d v) | ||
|
||
# Get the distribution of the system | ||
DISTRIBUTION=$(lsb_release -is | tr '[:upper:]' '[:lower:]') | ||
|
||
# Map the distribution to the corresponding package extension | ||
case $DISTRIBUTION in | ||
"debian"|"ubuntu") | ||
EXT="deb" | ||
;; | ||
"fedora"|"centos"|"rhel") | ||
EXT="rpm" | ||
;; | ||
"alpine") | ||
EXT="apk" | ||
;; | ||
*) | ||
echo "Unsupported distribution: $DISTRIBUTION" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
# Construct the download URL | ||
URL="https://github.com/caas-team/sparrow/releases/download/v${VERSION}/sparrow_${VERSION}_linux_${ARCH}.${EXT}" | ||
|
||
# Download the binary | ||
curl -L $URL -o "sparrow_${VERSION}_linux_${ARCH}.${EXT}" | ||
|
||
echo "Downloaded sparrow for $ARCH, version $VERSION" | ||
|
||
# Unpack and install the binary | ||
case $EXT in | ||
"deb") | ||
sudo dpkg -i "sparrow_${VERSION}_linux_${ARCH}.${EXT}" | ||
;; | ||
"rpm") | ||
sudo rpm -i "sparrow_${VERSION}_linux_${ARCH}.${EXT}" | ||
;; | ||
"apk") | ||
sudo apk add "sparrow_${VERSION}_linux_${ARCH}.${EXT}" | ||
;; | ||
esac |