|
|
@ -1,29 +1,29 @@
|
|
|
|
#ft=bash
|
|
|
|
#ft=bash
|
|
|
|
|
|
|
|
|
|
|
|
bail () {
|
|
|
|
bail () (
|
|
|
|
>&2 echo "ERROR: $1"
|
|
|
|
>&2 echo "ERROR: $1"
|
|
|
|
exit 1
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
must_be_root () {
|
|
|
|
must_be_root () (
|
|
|
|
if [ "$(id --user)" != 0 ]; then
|
|
|
|
if [ "$(id --user)" != 0 ]; then
|
|
|
|
bail "must run as root"
|
|
|
|
bail "must run as root"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
set_link () {
|
|
|
|
set_link () (
|
|
|
|
TARGET="$1"
|
|
|
|
TARGET=${1}
|
|
|
|
APP_DIR="$2"
|
|
|
|
APP_DIR=${2}
|
|
|
|
APP_PATH="$3"
|
|
|
|
APP_PATH=${3:-}
|
|
|
|
|
|
|
|
|
|
|
|
pushd "$(dirname "${TARGET}")" >/dev/null || exit 1
|
|
|
|
pushd "$(dirname "${TARGET}")" >/dev/null || exit 1
|
|
|
|
unlink_if_set "${TARGET}"
|
|
|
|
unlink_if_set "${TARGET}"
|
|
|
|
REL_PATH=$(relative_path "$(dirname "${TARGET}")" "${APP_DIR}/current/${APP_PATH}")
|
|
|
|
REL_PATH=$(relative_path "$(dirname "${TARGET}")" "${APP_DIR}/current/${APP_PATH}")
|
|
|
|
ln -s "${REL_PATH}" "$(basename "${TARGET}")"
|
|
|
|
ln -s "${REL_PATH}" "$(basename "${TARGET}")"
|
|
|
|
popd >/dev/null || exit 1
|
|
|
|
popd >/dev/null || exit 1
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
get_os () {
|
|
|
|
get_os () (
|
|
|
|
case $(uname -s) in
|
|
|
|
case $(uname -s) in
|
|
|
|
Linux*) echo linux;;
|
|
|
|
Linux*) echo linux;;
|
|
|
|
Darwin*) echo darwin;;
|
|
|
|
Darwin*) echo darwin;;
|
|
|
@ -36,9 +36,9 @@ get_os () {
|
|
|
|
CYGWIN_NT*) echo windows;;
|
|
|
|
CYGWIN_NT*) echo windows;;
|
|
|
|
*) >&2 echo "unsupported os"; return;
|
|
|
|
*) >&2 echo "unsupported os"; return;
|
|
|
|
esac
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
get_arch () {
|
|
|
|
get_arch () (
|
|
|
|
case $(uname -m) in
|
|
|
|
case $(uname -m) in
|
|
|
|
x86_64*) echo amd64;;
|
|
|
|
x86_64*) echo amd64;;
|
|
|
|
amd64*) echo amd64;;
|
|
|
|
amd64*) echo amd64;;
|
|
|
@ -51,43 +51,43 @@ get_arch () {
|
|
|
|
aarch64*) echo arm64;;
|
|
|
|
aarch64*) echo arm64;;
|
|
|
|
*) >&2 echo "unsupported architecture: $(uname -m)"; exit 1;;
|
|
|
|
*) >&2 echo "unsupported architecture: $(uname -m)"; exit 1;;
|
|
|
|
esac
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
set_current_link () {
|
|
|
|
set_current_link () (
|
|
|
|
prefix="${1}"
|
|
|
|
prefix=${1}
|
|
|
|
version="${2}"
|
|
|
|
version=${2}
|
|
|
|
sudo="${3}"
|
|
|
|
sudo=${3:-}
|
|
|
|
current="${prefix}/current"
|
|
|
|
current="${prefix}/current"
|
|
|
|
if [ -L "${current}" ] ; then
|
|
|
|
if [ -L "${current}" ] ; then
|
|
|
|
$sudo unlink "${current}"
|
|
|
|
$sudo unlink "${current}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
rel="$(relative_path "${prefix}" "${prefix}/${version}")"
|
|
|
|
rel="$(relative_path "${prefix}" "${prefix}/${version}")"
|
|
|
|
$sudo ln -s "$rel" "${current}"
|
|
|
|
$sudo ln -s "$rel" "${current}"
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
unlink_if_set () {
|
|
|
|
unlink_if_set () (
|
|
|
|
dir="$1"
|
|
|
|
dir=$1
|
|
|
|
sudo="$2"
|
|
|
|
sudo=${2:-}
|
|
|
|
if [ -L "${dir}" ]; then
|
|
|
|
if [ -L "${dir}" ]; then
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
${sudo} unlink "${dir}"
|
|
|
|
${sudo} unlink "${dir}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
mkdir_if_missing () {
|
|
|
|
mkdir_if_missing () (
|
|
|
|
dir="$1"
|
|
|
|
dir=${1}
|
|
|
|
sudo=$2
|
|
|
|
sudo=${2:-}
|
|
|
|
if [ ! -d "${dir}" ]; then
|
|
|
|
if [ ! -d "${dir}" ]; then
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
$sudo mkdir -p "${dir}"
|
|
|
|
$sudo mkdir -p "${dir}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
extract_zip () {
|
|
|
|
extract_zip () (
|
|
|
|
url="${1}"
|
|
|
|
url=${1}
|
|
|
|
dest="${2}"
|
|
|
|
dest=${2}
|
|
|
|
args="${3}"
|
|
|
|
args=${3}
|
|
|
|
sudo="${4}"
|
|
|
|
sudo=${4:-}
|
|
|
|
if [ -d "${dest}" ]; then
|
|
|
|
if [ -d "${dest}" ]; then
|
|
|
|
return
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
fi
|
|
|
@ -99,13 +99,13 @@ extract_zip () {
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
$sudo unzip -o "${zipfile}" -d "${dest}" ${args}
|
|
|
|
$sudo unzip -o "${zipfile}" -d "${dest}" ${args}
|
|
|
|
rm -rf "${tmp_dir}"
|
|
|
|
rm -rf "${tmp_dir}"
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
extract_tarball () {
|
|
|
|
extract_tarball () (
|
|
|
|
url="${1}"
|
|
|
|
url=${1}
|
|
|
|
dest="${2}"
|
|
|
|
dest=${2}
|
|
|
|
args="${3}"
|
|
|
|
args=${3}
|
|
|
|
sudo="${4}"
|
|
|
|
sudo=${4:-}
|
|
|
|
if [ -d "${dest}" ]; then
|
|
|
|
if [ -d "${dest}" ]; then
|
|
|
|
return
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
fi
|
|
|
@ -117,9 +117,9 @@ extract_tarball () {
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
$sudo tar xf "${tarball}" --directory "${dest}" ${args}
|
|
|
|
$sudo tar xf "${tarball}" --directory "${dest}" ${args}
|
|
|
|
rm -rf "${tmp_dir}"
|
|
|
|
rm -rf "${tmp_dir}"
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
relative_path() {
|
|
|
|
relative_path() (
|
|
|
|
# both $1 and $2 are absolute paths beginning with /
|
|
|
|
# both $1 and $2 are absolute paths beginning with /
|
|
|
|
# $1 must be a canonical path; that is none of its directory
|
|
|
|
# $1 must be a canonical path; that is none of its directory
|
|
|
|
# components may be ".", ".." or a symbolic link
|
|
|
|
# components may be ".", ".." or a symbolic link
|
|
|
@ -161,4 +161,4 @@ relative_path() {
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
printf '%s' "$result"
|
|
|
|
printf '%s' "$result"
|
|
|
|
}
|
|
|
|
)
|
|
|
|