Skip to content

Commit

Permalink
feat: add install and config scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
y-eight committed Jun 6, 2024
1 parent d55eefc commit ffcc16a
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 0 deletions.
15 changes: 15 additions & 0 deletions scripts/README.md
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!
32 changes: 32 additions & 0 deletions scripts/get_config.sh
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"
34 changes: 34 additions & 0 deletions scripts/install_binary.sh
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'"
62 changes: 62 additions & 0 deletions scripts/install_distribution.sh
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

0 comments on commit ffcc16a

Please sign in to comment.