opengist-install.bash
· 1.1 KiB · Bash
Raw
#!/usr/bin/bash
version=${1:-1.8.2}
url="https://github.com/thomiceli/opengist/releases/download/v$version/opengist$version-linux-amd64.tar.gz"
tar_file=${url##*/}
binary="opengist$version-linux-amd64"
# create user
if ! id -u opengist; then
useradd -mr -d /var/lib/opengist opengist
## create config dir
mkdir -p /etc/opengist
## fix perms
chown -R opengist:opengist /etc/opengist
chmod 2770 $_
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 -
# create systemd service
cat << EOF > /etc/systemd/system/opengist.service
[Unit]
Description=opengist Server
After=network.target
Requires=nginx.service
[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 | version=${1:-1.8.2} |
| 4 | url="https://github.com/thomiceli/opengist/releases/download/v$version/opengist$version-linux-amd64.tar.gz" |
| 5 | tar_file=${url##*/} |
| 6 | binary="opengist$version-linux-amd64" |
| 7 | |
| 8 | # create user |
| 9 | if ! id -u opengist; then |
| 10 | useradd -mr -d /var/lib/opengist opengist |
| 11 | |
| 12 | ## create config dir |
| 13 | mkdir -p /etc/opengist |
| 14 | |
| 15 | ## fix perms |
| 16 | chown -R opengist:opengist /etc/opengist |
| 17 | chmod 2770 $_ |
| 18 | fi |
| 19 | |
| 20 | # download |
| 21 | curl -LO "$url" |
| 22 | |
| 23 | # extract binary |
| 24 | tar -xavf "$tar_file" -C /usr/local/bin --strip-components=1 --transform="s@\$@1.8.2-linux-amd64@" opengist/opengist |
| 25 | |
| 26 | # extract config |
| 27 | tar -xavf "$tar_file" -C /etc/opengist --strip-components=1 opengist/config.yml |
| 28 | |
| 29 | # symlink |
| 30 | cd /usr/local/bin |
| 31 | ln -s $binary opengist |
| 32 | cd - |
| 33 | |
| 34 | # create systemd service |
| 35 | cat << EOF > /etc/systemd/system/opengist.service |
| 36 | [Unit] |
| 37 | Description=opengist Server |
| 38 | After=network.target |
| 39 | Requires=nginx.service |
| 40 | |
| 41 | [Service] |
| 42 | Type=simple |
| 43 | User=opengist |
| 44 | Group=opengist |
| 45 | ExecStart=/usr/local/bin/opengist --config /etc/opengist/config.yml |
| 46 | Restart=on-failure |
| 47 | |
| 48 | [Install] |
| 49 | WantedBy=multi-user.target |
| 50 | EOF |
| 51 | |
| 52 | # activate service |
| 53 | systemctl daemon-reload |
| 54 | systemctl enable --now opengist |