From 51f5758aee584863544700ceec4dd90d03edaa27 Mon Sep 17 00:00:00 2001 From: Buddy Sandidge Date: Fri, 18 Jun 2021 16:45:40 -0700 Subject: [PATCH] Add gitea install script --- base/.local/share/buddy-up/includes/utils.sh | 4 +- install-scripts/.local/bin/install-gitea-home | 36 ++++++++++++++++++ .../.local/bin/install-gitea-system | 38 +++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100755 install-scripts/.local/bin/install-gitea-home create mode 100755 install-scripts/.local/bin/install-gitea-system diff --git a/base/.local/share/buddy-up/includes/utils.sh b/base/.local/share/buddy-up/includes/utils.sh index a13f831..25c7259 100644 --- a/base/.local/share/buddy-up/includes/utils.sh +++ b/base/.local/share/buddy-up/includes/utils.sh @@ -55,8 +55,10 @@ set_current_link () { unlink_if_set () { dir="$1" + sudo="$2" if [ -L "${dir}" ]; then - unlink "${dir}" + # shellcheck disable=SC2086 + ${sudo} unlink "${dir}" fi } diff --git a/install-scripts/.local/bin/install-gitea-home b/install-scripts/.local/bin/install-gitea-home new file mode 100755 index 0000000..95a40be --- /dev/null +++ b/install-scripts/.local/bin/install-gitea-home @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +# shellcheck disable=SC1090 +source "${XDG_DATA_HOME}/buddy-up/includes/utils.sh" + +function get_os () { + case $(uname -s) in + Linux*) echo linux;; + Darwin*) echo darwin-10.12;; + *) >&2 echo "unsupported os: $(uname -s)"; exit 1;; + esac +} + +APP=gitea +DEST="${XDG_DATA_HOME}/apps/releases/${APP}" +CURRENT="${DEST}/current" +VERSION=${VERSION:-1.14.3} +URL=https://dl.gitea.io/gitea/${VERSION}/gitea-${VERSION}-$(get_os)-$(get_arch).xz + +if [ ! -d "${DEST}/${VERSION}" ]; then + tmp_dir="$(mktemp -d)" + file=${tmp_dir}/gitea + curl --silent --retry 5 --location --output "${file}.xz" "${URL}" + xz --decompress "${file}.xz" + chmod 755 "${file}" + mkdir -p "${DEST}/${VERSION}" + mv "${file}" "${DEST}/${VERSION}/${APP}" + + rm -rf "${tmp_dir}" +fi +set_current_link "${DEST}" "${VERSION}" + +unlink_if_set "${XDG_BIN_HOME}/${APP}" +cd "${XDG_BIN_HOME}" || exit 1 +ln -s "$(relative_path "${XDG_BIN_HOME}" "${CURRENT}/${APP}")" "${APP}" +cd - &> /dev/null || exit 1 diff --git a/install-scripts/.local/bin/install-gitea-system b/install-scripts/.local/bin/install-gitea-system new file mode 100755 index 0000000..e8abe22 --- /dev/null +++ b/install-scripts/.local/bin/install-gitea-system @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +# shellcheck disable=SC1090 +source "${XDG_DATA_HOME}/buddy-up/includes/utils.sh" + +function get_os () { + case $(uname -s) in + Linux*) echo linux;; + Darwin*) echo darwin-10.12;; + *) >&2 echo "unsupported os: $(uname -s)"; exit 1;; + esac +} + +APP=gitea +DEST="/usr/local/apps/${APP}" +CURRENT="${DEST}/current" +VERSION=${VERSION:-1.14.3} +URL=https://dl.gitea.io/gitea/${VERSION}/gitea-${VERSION}-$(get_os)-$(get_arch).xz +BIN_DIR=/usr/local/bin + +if [ ! -d "${DEST}/${VERSION}" ]; then + tmp_dir="$(mktemp -d)" + file=${tmp_dir}/gitea + curl --silent --retry 10 --location --output "${file}.xz" "${URL}" + xz --decompress "${file}.xz" + chmod 755 "${file}" + sudo chown root:root "${file}" + sudo mkdir -p "${DEST}/${VERSION}" + sudo mv "${file}" "${DEST}/${VERSION}/${APP}" + + rm -rf "${tmp_dir}" +fi +set_current_link "${DEST}" "${VERSION}" "sudo" + +unlink_if_set "${BIN_DIR}/${APP}" "sudo" +cd "${BIN_DIR}" || exit 1 +sudo ln -s "$(relative_path "${BIN_DIR}" "${CURRENT}/${APP}")" "${APP}" +cd - &> /dev/null || exit 1