websoft9/install/install_plugins.sh

95 lines
2.2 KiB
Bash
Raw Normal View History

2023-09-19 10:12:37 +00:00
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
2023-09-19 09:44:20 +00:00
2023-09-19 11:55:23 +00:00
2023-09-25 09:53:21 +00:00
# Command-line options
# ==========================================================
#
# --channel <release|dev>
# Use the --channel option to install a release(production) or dev distribution. default is release, for example:
#
# $ sudo sh install.sh --channel release
#
# ==============================================================================
# get input and define vars
while [[ $# -gt 0 ]]; do
case $1 in
--channel)
channel="$2"
shift 2
;;
*)
shift
;;
esac
done
2023-09-19 09:44:20 +00:00
2023-09-25 09:53:21 +00:00
if [ -z "$channel" ]; then
channel="release"
fi
2023-09-19 09:44:20 +00:00
2023-09-25 09:53:21 +00:00
if [ -z "$source_github_pages" ]; then
source_github_pages="https://websoft9.github.io/websoft9"
fi
2023-09-19 09:44:20 +00:00
2023-09-25 09:53:21 +00:00
if [ -z "$install_path" ]; then
install_path="/data/websoft9/source"
fi
2023-09-19 09:44:20 +00:00
2023-09-25 09:53:21 +00:00
echo "Your installation parameters are as follows: "
echo "--channel: $channel"
2023-09-19 09:44:20 +00:00
2023-09-25 09:53:21 +00:00
artifact_url="https://w9artifact.blob.core.windows.net/$channel/websoft9/plugin"
echo_prefix_cockpit=$'\n[Plugins] - '
2023-09-19 09:44:20 +00:00
2023-09-25 09:53:21 +00:00
version_json(){
2023-09-19 09:44:20 +00:00
2023-09-25 09:53:21 +00:00
if [ -f "$install_path/version.json" ]; then
echo "Find version file on your $install_path "
else
echo "Get version.json from $source_github_pages "
mydata=$(curl -s "$url")
if [ $? -ne 0 ]; then
echo "URL does not exist or cannot be accessed."
exit 1
else
echo "$mydata"
fi
fi
mydata=$(cat "$install_path/version.json")
echo $mydata
2023-09-19 09:44:20 +00:00
}
2023-09-25 09:53:21 +00:00
install_plugins() {
echo "$echo_prefix_cockpit Start to install plugins"
data=$(version_json)
2023-09-19 09:44:20 +00:00
2023-09-25 09:53:21 +00:00
# 解析数据文件,获取 plugins 的子元素和对应的版本号
plugins=$(echo "$data" | jq -r '.plugins | keys_unsorted[]')
versions=$(echo "$data" | jq -r '.plugins | .[]')
2023-09-19 09:44:20 +00:00
2023-09-25 09:53:21 +00:00
# 定义数组变量
declare -a artifact_array
2023-09-19 09:44:20 +00:00
2023-09-25 09:53:21 +00:00
# 构建数组内容
readarray -t plugins_array <<<"$plugins"
readarray -t versions_array <<<"$versions"
2023-09-19 09:44:20 +00:00
2023-09-25 09:53:21 +00:00
for ((i=0; i<${#plugins_array[@]}; i++)); do
artifact_array+=("$artifact_url/${plugins_array[$i]}-${versions_array[$i]}")
done
2023-09-19 09:44:20 +00:00
2023-09-25 09:53:21 +00:00
# 打印数组元素
for element in "${artifact_array[@]}"; do
echo "$element"
done
2023-09-19 09:44:20 +00:00
}
2023-09-25 09:53:21 +00:00
install_plugins