-
Notifications
You must be signed in to change notification settings - Fork 1
/
install
executable file
·67 lines (52 loc) · 2.33 KB
/
install
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
59
60
61
62
63
64
65
66
67
#!/usr/bin/env bash
# SPDX-License-Identifier: MIT
#
# Copyright (c) 2023 QuickVM, LLC <[email protected]> All Rights Reserved.
set -e
OS_ARCH=$(arch)
OS_TYPE=$(uname)
[[ "${OS_TYPE}" == "Linux" ]] || { echo "Only Linux is supported!"; exit 1; }
[[ "${UID}" == 0 ]] || { echo "Please run this as root!"; exit 1; }
case "${OS_ARCH}" in
aarch64) ARCH="arm64" ;;
armv5*) ARCH="armv5" ;;
armv6*) ARCH="armv6" ;;
armv7*) ARCH="armv7" ;;
i386) ARCH="386" ;;
i686) ARCH="386" ;;
x86_64) ARCH="amd64" ;;
x86) ARCH="386" ;;
*) ARCH="unknown" ;;
esac
[[ "${ARCH}" != "unknown" ]] || { echo "Unknown CPU arch!"; exit 1; }
export OSARCH="$(echo ${OS_TYPE}|sed -e 's/Linux/linux/g')-${ARCH}"
: ${UNIT_FILES:=./units}
: ${UNIT_DIR:=/etc/systemd/system}
: ${BIN_FILES:=./bin}
: ${BIN_DIR:=/usr/local/bin}
: ${DEFINEDPATH:=/etc/defined} # Cuztomize this at your own risk. dnclient expects it's config to be in /etc/defined!
: ${DN_VERSION:="latest"}
DN_DOWNLOAD_URL=$(curl -sL https://api.defined.net/v1/downloads | jq --arg osarch "${OSARCH}" --arg version "${DN_VERSION}" -r '.data.dnclient|.[ $version ]|.[ $osarch ]')
mkdir -p "${DEFINEDPATH}"
[[ -d ${DEFINEDPATH} ]] || { echo "The ${DEFINEDPATH} directory does not exist! Please create it!"; exit 1; }
[[ -d ${UNIT_FILES} ]] || { echo "The ${UNIT_FILES} directory cannot be found! Please run this from the repo root directory!"; exit 1; }
[[ -d ${BIN_FILES} ]] || { echo "The ${BIN_FILES} directory cannot be found! Please run this from the repo root directory!"; exit 1; }
# Download and install dnclient
if [[ -f ${BIN_DIR}/dnclient ]]; then
echo ""
echo "${BIN_DIR}/dnclient is already installed!"
echo "Stop dnclient and remove ${BIN_DIR}/dnclient to reinstall."
echo "Skipping dnclient download and install..."
else
curl -sSL ${DN_DOWNLOAD_URL} -o ${BIN_DIR}/dnclient && chmod +x ${BIN_DIR}/dnclient
fi
# Install systemd service units
export BIN_DIR=${BIN_DIR}
install -m 0644 <(envsubst < ${UNIT_FILES}/dnclient.service) ${UNIT_DIR}/dnclient.service
install -m 0644 <(envsubst < ${UNIT_FILES}/dnctl.service) ${UNIT_DIR}/dnctl.service
# Install dnctl
install -m 0750 ${BIN_FILES}/dnctl ${BIN_DIR}/dnctl
systemctl daemon-reload
echo ""
echo "Great job, the Defined.net systemd units and dnctl are now installed! Create /etc/defined/dnctl and run dnctl enable and dnctl start!"
echo ""