opengist-install.bash
· 1.6 KiB · Bash
Raw
#!/usr/bin/bash
# Description:
# This script is for installing opengist. To use it, you need to execute it with a version as an argument
#
# For example:
#
# opengist-install 1.18.2
# functions
# example: rm / || die 'It didn't work!' 2
die() {
local message=$1
local code=$2
echo -e "Error: $1"
exit $2
}
version=$1
url="https://github.com/thomiceli/opengist/releases/download/v$version/opengist$version-linux-amd64.tar.gz"
tar_file=${url##*/}
binary="opengist$version-linux-amd64"
# check if version was provided
if [[ -z $version ]]; then
die "You didn't provide a version to install. Please, provide one similar to: a.b.c" 1
fi
# create user
if ! id -u opengist; then
useradd -mr -d /var/lib/opengist opengist
## create config dir
mkdir -p /etc/opengist
fi
# download
curl -LO "$url"
# extract binary
tar -xavf "$tar_file" -C /usr/local/bin --strip-components=1 --transform="s@\$@1.8.2-linux-amd64@" opengist/opengist
# extract config
tar -xavf "$tar_file" -C /etc/opengist --strip-components=1 opengist/config.yml
# symlink
cd /usr/local/bin
ln -s $binary opengist
cd -
# fix perms
chown -R opengist:opengist /etc/opengist
chmod 2770 $_
chmod 660 $_/*
chmod -R o-rwx /var/lib/opengist
# create systemd service
cat << EOF > /etc/systemd/system/opengist.service
[Unit]
Description=opengist Server
After=network.target
[Service]
Type=simple
User=opengist
Group=opengist
ExecStart=/usr/local/bin/opengist --config /etc/opengist/config.yml
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
# activate service
systemctl daemon-reload
systemctl enable --now opengist
| 1 | #!/usr/bin/bash |
| 2 | |
| 3 | # Description: |
| 4 | # This script is for installing opengist. To use it, you need to execute it with a version as an argument |
| 5 | # |
| 6 | # For example: |
| 7 | # |
| 8 | # opengist-install 1.18.2 |
| 9 | |
| 10 | # functions |
| 11 | # example: rm / || die 'It didn't work!' 2 |
| 12 | die() { |
| 13 | local message=$1 |
| 14 | local code=$2 |
| 15 | |
| 16 | echo -e "Error: $1" |
| 17 | exit $2 |
| 18 | } |
| 19 | |
| 20 | |
| 21 | version=$1 |
| 22 | url="https://github.com/thomiceli/opengist/releases/download/v$version/opengist$version-linux-amd64.tar.gz" |
| 23 | tar_file=${url##*/} |
| 24 | binary="opengist$version-linux-amd64" |
| 25 | |
| 26 | # check if version was provided |
| 27 | if [[ -z $version ]]; then |
| 28 | die "You didn't provide a version to install. Please, provide one similar to: a.b.c" 1 |
| 29 | fi |
| 30 | |
| 31 | # create user |
| 32 | if ! id -u opengist; then |
| 33 | useradd -mr -d /var/lib/opengist opengist |
| 34 | |
| 35 | ## create config dir |
| 36 | mkdir -p /etc/opengist |
| 37 | fi |
| 38 | |
| 39 | # download |
| 40 | curl -LO "$url" |
| 41 | |
| 42 | # extract binary |
| 43 | tar -xavf "$tar_file" -C /usr/local/bin --strip-components=1 --transform="s@\$@1.8.2-linux-amd64@" opengist/opengist |
| 44 | |
| 45 | # extract config |
| 46 | tar -xavf "$tar_file" -C /etc/opengist --strip-components=1 opengist/config.yml |
| 47 | |
| 48 | # symlink |
| 49 | cd /usr/local/bin |
| 50 | ln -s $binary opengist |
| 51 | cd - |
| 52 | |
| 53 | # fix perms |
| 54 | chown -R opengist:opengist /etc/opengist |
| 55 | chmod 2770 $_ |
| 56 | chmod 660 $_/* |
| 57 | chmod -R o-rwx /var/lib/opengist |
| 58 | |
| 59 | # create systemd service |
| 60 | cat << EOF > /etc/systemd/system/opengist.service |
| 61 | [Unit] |
| 62 | Description=opengist Server |
| 63 | After=network.target |
| 64 | |
| 65 | [Service] |
| 66 | Type=simple |
| 67 | User=opengist |
| 68 | Group=opengist |
| 69 | ExecStart=/usr/local/bin/opengist --config /etc/opengist/config.yml |
| 70 | Restart=on-failure |
| 71 | |
| 72 | [Install] |
| 73 | WantedBy=multi-user.target |
| 74 | EOF |
| 75 | |
| 76 | # activate service |
| 77 | systemctl daemon-reload |
| 78 | systemctl enable --now opengist |