-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
58 lines (46 loc) · 2.22 KB
/
install.sh
File metadata and controls
58 lines (46 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env -S bash -euo pipefail
# -------------------------------------------------------------------------------------------------------------------- #
# BASH: INSTALLING AND UPDATING SCRIPTS
# -------------------------------------------------------------------------------------------------------------------- #
# @package Bash
# @author Kai Kimera <mail@kaikim.ru>
# @license MIT
# @version 0.1.0
# @link https://kaikim.ru/
# -------------------------------------------------------------------------------------------------------------------- #
(( EUID != 0 )) && { echo >&2 'This script should be run as root!'; exit 1; }
# -------------------------------------------------------------------------------------------------------------------- #
# CONFIGURATION
# -------------------------------------------------------------------------------------------------------------------- #
# Parameters.
DIR="${1:?}"; readonly DIR
NAME="${2:?}"; readonly NAME
TAG="${3:?}"; readonly TAG
# Variables.
ORG='pkgstore'
TS="$( date '+%s' )"
# -------------------------------------------------------------------------------------------------------------------- #
# -----------------------------------------------------< SCRIPT >----------------------------------------------------- #
# -------------------------------------------------------------------------------------------------------------------- #
function downloading() {
local dir; dir="${NAME}.${TS}.tmp"
local ref; ref='tags'; [[ "${TAG}" == 'main' ]] && ref='heads'
local url; url="https://github.com/${ORG}/${NAME}/archive/refs/${ref}/${TAG}.tar.gz"
mkdir -p "${dir}" && { cd "${dir}" || exit 1; } && curl -fLo "${NAME}-${TAG}.tar.gz" "${url}"
}
function unpacking() {
tar -xzf "${NAME}-${TAG}.tar.gz" && { cd "${NAME}-${TAG}" || exit 1; }
}
function installing() {
local f; f=(app.* job.*)
[[ -d "${DIR}" ]] && tar -cJf "${DIR}.${TS}.tar.xz" -C "${DIR%/*}" "${DIR##*/}"
for i in "${f[@]}"; do
[[ -f "${i}" ]] || continue
install -m '0644' -Dt "${DIR}" "${i}"
[[ "${i}" == *.sh ]] && chmod +x "${DIR}/${i}"
[[ "${i}" == job.* ]] && ln -sf "${DIR}/${i}" "/etc/cron.d/${i//./_}"
done
}
function main() {
downloading && unpacking && installing
}; main "$@"