Skip to content

Commit 232d97d

Browse files
committed
feat: "Implement new devops script and update install configurations"
- A new script `devops.sh` has been added to the `hack/scripts/devops/` directory. It includes functions for logs including helper functions `info()`, `warn()`, and `fatal()`. - The new script also includes functionality to set up environment variables, verify architecture, create temporary directories, and verify, download, and install binaries. - Major functionality noted in the new file includes the `download_and_verify()` function, which verifies architecture, downloads binaries and sets up permissions, and the `install_zentao_devops()` function, which prepares and executes the devops installation command. - The `install.sh` script has been updated. The SCRIPT_COMMIT_SHA and SCRIPT_DATA have been updated. - An additional option `SKIP_DEVOPS_INIT` has been added to the `install.sh` script allowing users to skip devops initialization. Signed-off-by: ysicing <[email protected]>
1 parent af154e4 commit 232d97d

File tree

2 files changed

+230
-2
lines changed

2 files changed

+230
-2
lines changed

hack/scripts/devops/devops.sh

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
#!/bin/sh
2+
# Copyright (c) 2021-2023 北京渠成软件有限公司(Beijing Qucheng Software Co., Ltd. www.qucheng.com) All rights reserved.
3+
# Use of this source code is covered by the following dual licenses:
4+
# (1) Z PUBLIC LICENSE 1.2 (ZPL 1.2)
5+
# (2) Affero General Public License 3.0 (AGPL 3.0)
6+
# license that can be found in the LICENSE file.
7+
8+
# Source code is available at https://github.com/easysoft/quickon_cli
9+
10+
# SCRIPT_COMMIT_SHA="a77fcbaf862d7b2d1eb8b08c5920adde14edc4ca"
11+
# SCRIPT_DATA="Wed May 29 17:29:14 CST 2024"
12+
13+
# Usage:
14+
# curl ... | ENV_VAR=... sh -
15+
# or
16+
# ENV_VAR=... ./install.sh
17+
#
18+
# Example:
19+
# Installing DevOPS with ZenTao:
20+
# curl ... | DEVOPS_TYPE="" sh -
21+
# - DEVOPS_TYPE
22+
# Install Type when install Zentao DevOPS.
23+
# Defaults to '', support 'max', 'biz', 'ipd'
24+
# - DEVOPS_VERSION
25+
# Install Version when install Zentao DevOPS.
26+
# Defaults to ''
27+
# - INSTALL_DOMAIN
28+
# If not set default use gen default domain
29+
# - SKIP_DEVOPS_INIT
30+
# Allow skip devops init
31+
# Defaults to 'true'
32+
# - DEBUG
33+
# If set, print debug information
34+
35+
set -e
36+
set -o noglob
37+
38+
[ -n "${DEBUG:+1}" ] && set -x
39+
40+
# --- helper functions for logs ---
41+
info()
42+
{
43+
echo '[INFO] ' "$@"
44+
}
45+
warn()
46+
{
47+
echo '[WARN] ' "$@" >&2
48+
}
49+
fatal()
50+
{
51+
echo '[ERROR] ' "$@" >&2
52+
exit 1
53+
}
54+
55+
COS_URL=https://pkg.zentao.net/cli/devops
56+
57+
# --- define needed environment variables ---
58+
setup_env() {
59+
# --- use sudo if we are not already root ---
60+
SUDO=sudo
61+
if [ $(id -u) -eq 0 ]; then
62+
SUDO=
63+
fi
64+
BIN_DIR=/usr/local/bin
65+
if ! $SUDO sh -c "touch ${BIN_DIR}/z-ro-test && rm -rf ${BIN_DIR}/z-ro-test"; then
66+
if [ -d /opt/bin ]; then
67+
BIN_DIR=/opt/bin
68+
fi
69+
fi
70+
}
71+
72+
# --- verify an executable z binary is installed ---
73+
verify_z_is_executable() {
74+
if [ ! -x ${BIN_DIR}/z ]; then
75+
fatal "Executable z binary not found at ${BIN_DIR}/z"
76+
fi
77+
}
78+
79+
# --- verify existence of network downloader executable ---
80+
verify_downloader() {
81+
# Return failure if it doesn't exist or is no executable
82+
[ -x "$(command -v $1)" ] || return 1
83+
84+
# Set verified executable as our downloader program and return success
85+
DOWNLOADER=$1
86+
return 0
87+
}
88+
89+
# --- create temporary directory and cleanup when done ---
90+
setup_tmp() {
91+
TMP_DIR=$(mktemp -d -t z-install.XXXXXXXXXX)
92+
TMP_HASH=${TMP_DIR}/z.hash
93+
TMP_BIN=${TMP_DIR}/z.bin
94+
cleanup() {
95+
code=$?
96+
set +e
97+
trap - EXIT
98+
rm -rf ${TMP_DIR}
99+
exit $code
100+
}
101+
trap cleanup INT EXIT
102+
}
103+
104+
setup_quickon() {
105+
[ -d "/opt/quickon/backup" ] || (
106+
mkdir -p /opt/quickon/backup
107+
chmod 777 /opt/quickon/backup
108+
)
109+
}
110+
111+
# --- use desired qcadmin version if defined or find version from channel ---
112+
get_release_version() {
113+
if [ -z "$VERSION" ]; then
114+
VERSION="stable"
115+
fi
116+
info "Using ${VERSION} as release"
117+
}
118+
119+
# --- set arch and suffix, fatal if architecture not supported ---
120+
setup_verify_arch() {
121+
if [ -z "$ARCH" ]; then
122+
ARCH=$(uname -m)
123+
fi
124+
case $ARCH in
125+
amd64|x86_64)
126+
ARCH=amd64
127+
SUFFIX=${ARCH}
128+
;;
129+
arm64|aarch64)
130+
ARCH=arm64
131+
SUFFIX=${ARCH}
132+
;;
133+
arm*)
134+
ARCH=arm
135+
SUFFIX=${ARCH}hf
136+
;;
137+
*)
138+
fatal "Unsupported architecture $ARCH"
139+
esac
140+
}
141+
142+
143+
# --- download from url ---
144+
download() {
145+
[ $# -eq 2 ] || fatal 'download needs exactly 2 arguments'
146+
147+
case $DOWNLOADER in
148+
curl)
149+
curl -o $1 -sfL $2
150+
;;
151+
wget)
152+
wget -qO $1 $2
153+
;;
154+
*)
155+
fatal "Incorrect executable '$DOWNLOADER'"
156+
;;
157+
esac
158+
159+
# Abort if download command failed
160+
[ $? -eq 0 ] || fatal 'Download failed'
161+
}
162+
163+
# --- download binary from cos url ---
164+
download_binary() {
165+
BIN_URL=${COS_URL}/${VERSION}/qcadmin_linux_${SUFFIX}
166+
info "Downloading binary"
167+
download ${TMP_BIN} ${BIN_URL}
168+
}
169+
170+
# --- setup permissions and move binary to system directory ---
171+
setup_binary() {
172+
chmod 755 ${TMP_BIN}
173+
info "Installing z to ${BIN_DIR}/z"
174+
$SUDO chown root:root ${TMP_BIN}
175+
$SUDO mv -f ${TMP_BIN} ${BIN_DIR}/qcadmin
176+
[ -f "${BIN_DIR}/z" ] && (
177+
$SUDO rm -f ${BIN_DIR}/z
178+
)
179+
info "Create soft link ${BIN_DIR}/z"
180+
$SUDO ln -s ${BIN_DIR}/qcadmin ${BIN_DIR}/z
181+
info "Installation is complete. Use z --help"
182+
}
183+
184+
# --- download and verify qcadmin ---
185+
download_and_verify() {
186+
setup_verify_arch
187+
verify_downloader curl || verify_downloader wget || fatal 'Can not find curl or wget for downloading files'
188+
setup_tmp
189+
setup_quickon
190+
get_release_version
191+
# Skip download if qcadmin binary exists, support upgrade
192+
download_binary
193+
setup_binary
194+
}
195+
196+
# --- install zentao devops
197+
install_zentao_devops() {
198+
INSTALL_COMMAND="${BIN_DIR}/z init --provider devops"
199+
if [ -n "${INSTALL_DOMAIN}" ]; then
200+
INSTALL_COMMAND="${BIN_DIR}/z init --provider devops --domain ${INSTALL_DOMAIN}"
201+
fi
202+
if [ -n "${DEVOPS_TYPE}" ]; then
203+
INSTALL_COMMAND="${INSTALL_COMMAND} --type ${DEVOPS_TYPE}"
204+
fi
205+
if [ -n "${DEVOPS_VERSION}" ]; then
206+
INSTALL_COMMAND="${INSTALL_COMMAND} --version ${DEVOPS_VERSION}"
207+
fi
208+
if [ "${SKIP_DEVOPS_INIT}" = "false" ]; then
209+
INSTALL_COMMAND="${INSTALL_COMMAND} --skip-devops-init false"
210+
fi
211+
if [ -n "${DEBUG}" ]; then
212+
INSTALL_COMMAND="${INSTALL_COMMAND} --debug"
213+
fi
214+
eval "$INSTALL_COMMAND"
215+
}
216+
217+
# --- run the install process --
218+
{
219+
setup_env
220+
download_and_verify
221+
install_zentao_devops
222+
}

hack/scripts/devops/install.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
# Source code is available at https://github.com/easysoft/quickon_cli
99

10-
# SCRIPT_COMMIT_SHA="a77fcbaf862d7b2d1eb8b08c5920adde14edc4ca"
11-
# SCRIPT_DATA="Wed May 29 17:29:14 CST 2024"
10+
# SCRIPT_COMMIT_SHA="af154e4cc02d141c4c97c873a117fa670d833a01"
11+
# SCRIPT_DATA="Fri May 31 13:22:17 CST 2024"
1212

1313
# Usage:
1414
# curl ... | ENV_VAR=... sh -
@@ -26,6 +26,9 @@
2626
# Defaults to ''
2727
# - INSTALL_DOMAIN
2828
# If not set default use gen default domain
29+
# - SKIP_DEVOPS_INIT
30+
# Allow skip devops init
31+
# Defaults to 'true'
2932
# - DEBUG
3033
# If set, print debug information
3134

@@ -202,6 +205,9 @@ install_zentao_devops() {
202205
if [ -n "${DEVOPS_VERSION}" ]; then
203206
INSTALL_COMMAND="${INSTALL_COMMAND} --version ${DEVOPS_VERSION}"
204207
fi
208+
if [ "${SKIP_DEVOPS_INIT}" = "false" ]; then
209+
INSTALL_COMMAND="${INSTALL_COMMAND} --skip-devops-init false"
210+
fi
205211
if [ -n "${DEBUG}" ]; then
206212
INSTALL_COMMAND="${INSTALL_COMMAND} --debug"
207213
fi

0 commit comments

Comments
 (0)