mirror of
https://github.com/Websoft9/websoft9.git
synced 2024-11-22 07:30:24 +00:00
install
This commit is contained in:
parent
dfe41c668c
commit
da28c832bf
11 changed files with 165 additions and 71 deletions
1
.github/workflows/upload_artifact.yml
vendored
1
.github/workflows/upload_artifact.yml
vendored
|
@ -33,6 +33,7 @@ jobs:
|
||||||
cp -r scripts websoft9
|
cp -r scripts websoft9
|
||||||
cp -r install websoft9
|
cp -r install websoft9
|
||||||
cp -r docs websoft9
|
cp -r docs websoft9
|
||||||
|
cp -r systemd websoft9
|
||||||
cp *.md websoft9
|
cp *.md websoft9
|
||||||
cp version.json websoft9
|
cp version.json websoft9
|
||||||
zip -r websoft9-$version.zip websoft9
|
zip -r websoft9-$version.zip websoft9
|
||||||
|
|
|
@ -5,7 +5,7 @@ services:
|
||||||
image: websoft9dev/apphub:$APPHUB_VERSION
|
image: websoft9dev/apphub:$APPHUB_VERSION
|
||||||
container_name: websoft9-apphub
|
container_name: websoft9-apphub
|
||||||
ports:
|
ports:
|
||||||
- 127.0.0.1:9001:8080
|
- 9001-9999:8080
|
||||||
restart: always
|
restart: always
|
||||||
volumes:
|
volumes:
|
||||||
- apphub_logs:/websoft9/apphub/logs
|
- apphub_logs:/websoft9/apphub/logs
|
||||||
|
|
|
@ -31,7 +31,7 @@ export PATH
|
||||||
|
|
||||||
|
|
||||||
docker_packages="docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin"
|
docker_packages="docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin"
|
||||||
docker_exist="command -v docker &> /dev/null && systemctl is-active --quiet docker"
|
echo_prefix_docker=$'\n[Docker] - '
|
||||||
|
|
||||||
# Function to check if apt is locked
|
# Function to check if apt is locked
|
||||||
is_apt_locked(){
|
is_apt_locked(){
|
||||||
|
@ -42,8 +42,27 @@ is_apt_locked(){
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
docker_exist() {
|
||||||
|
# 检查 `docker` 命令是否存在
|
||||||
|
if ! command -v docker &> /dev/null; then
|
||||||
|
echo "false"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 检查 Docker 服务是否存在
|
||||||
|
systemctl status docker &> /dev/null
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "false"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "true"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Install_Docker(){
|
Install_Docker(){
|
||||||
echo "Installing Docker for your system..."
|
echo "$echo_prefix_docker Installing Docker for your system"
|
||||||
|
|
||||||
# For redhat family
|
# For redhat family
|
||||||
if [[ -f /etc/redhat-release ]]; then
|
if [[ -f /etc/redhat-release ]]; then
|
||||||
|
@ -58,7 +77,7 @@ Install_Docker(){
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# For Ubuntu, Debian, or Raspbian
|
# For Ubuntu, Debian, or Raspbian
|
||||||
if type apt >/dev/null; then
|
if type apt >/dev/null 2>&1; then
|
||||||
apt update
|
apt update
|
||||||
# Wait for apt to be unlocked
|
# Wait for apt to be unlocked
|
||||||
while is_apt_locked; do
|
while is_apt_locked; do
|
||||||
|
@ -72,7 +91,7 @@ Install_Docker(){
|
||||||
|
|
||||||
Upgrade_Docker(){
|
Upgrade_Docker(){
|
||||||
if eval "$docker_exist"; then
|
if eval "$docker_exist"; then
|
||||||
echo "Upgrading Docker for your system..."
|
echo "$echo_prefix_docker Upgrading Docker for your system..."
|
||||||
dnf --version >/dev/null 2>&1
|
dnf --version >/dev/null 2>&1
|
||||||
dnf_status=$?
|
dnf_status=$?
|
||||||
yum --version >/dev/null 2>&1
|
yum --version >/dev/null 2>&1
|
||||||
|
@ -95,7 +114,7 @@ fi
|
||||||
}
|
}
|
||||||
|
|
||||||
Remove_Podman(){
|
Remove_Podman(){
|
||||||
echo "Try to remove Podman"
|
echo "$echo_prefix_docker Try to remove Podman"
|
||||||
podman pod stop --all
|
podman pod stop --all
|
||||||
# Remove Podman and its dependencies
|
# Remove Podman and its dependencies
|
||||||
if [ -x "$(command -v dnf)" ]; then
|
if [ -x "$(command -v dnf)" ]; then
|
||||||
|
@ -118,7 +137,7 @@ Remove_Podman(){
|
||||||
Set_Docker(){
|
Set_Docker(){
|
||||||
# should have Docker server and Docker cli
|
# should have Docker server and Docker cli
|
||||||
if eval $docker_exist; then
|
if eval $docker_exist; then
|
||||||
echo "Starting to Set docker..."
|
echo "$echo_prefix_docker Starting to Set docker..."
|
||||||
sudo systemctl enable docker
|
sudo systemctl enable docker
|
||||||
sudo systemctl start docker
|
sudo systemctl start docker
|
||||||
if ! docker network inspect websoft9 > /dev/null 2>&1; then
|
if ! docker network inspect websoft9 > /dev/null 2>&1; then
|
||||||
|
|
|
@ -67,6 +67,7 @@ export https_port=443
|
||||||
export cockpit_port=$port
|
export cockpit_port=$port
|
||||||
export force_install=$force
|
export force_install=$force
|
||||||
export install_path="/data/websoft9/source"
|
export install_path="/data/websoft9/source"
|
||||||
|
export systemd_path="/opt/websoft9/systemd"
|
||||||
export source_zip="websoft9-latest.zip"
|
export source_zip="websoft9-latest.zip"
|
||||||
export source_unzip="websoft9"
|
export source_unzip="websoft9"
|
||||||
export source_github_pages="https://websoft9.github.io/websoft9"
|
export source_github_pages="https://websoft9.github.io/websoft9"
|
||||||
|
@ -79,7 +80,9 @@ echo Install from url: $artifact_url
|
||||||
# Define common functions
|
# Define common functions
|
||||||
|
|
||||||
install_tools(){
|
install_tools(){
|
||||||
echo "Starting install necessary tool..."
|
echo_prefix_tools=$'\n[Tools] - '
|
||||||
|
echo "$echo_prefix_tools Starting install necessary tool..."
|
||||||
|
|
||||||
dnf --version >/dev/null 2>&1
|
dnf --version >/dev/null 2>&1
|
||||||
dnf_status=$?
|
dnf_status=$?
|
||||||
yum --version >/dev/null 2>&1
|
yum --version >/dev/null 2>&1
|
||||||
|
@ -106,15 +109,17 @@ install_tools(){
|
||||||
|
|
||||||
|
|
||||||
download_source() {
|
download_source() {
|
||||||
echo "Download Websoft9 source code..."
|
echo_prefix_source=$'\n[Dowload Source] - '
|
||||||
|
echo "$echo_prefix_source Download Websoft9 source code from $artifact_url/$source_zip"
|
||||||
|
|
||||||
rm -rf websoft9-latest.zip*
|
rm -rf websoft9-latest.zip*
|
||||||
if [ -d "$install_path" ]; then
|
if [ -d "$install_path" ]; then
|
||||||
echo "Directory $install_path already exists."
|
echo "Directory $install_path already exists and installation will cover it."
|
||||||
else
|
else
|
||||||
mkdir -p "$install_path"
|
mkdir -p "$install_path"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
wget "$urls/$source_zip"
|
wget "$artifact_url/$source_zip"
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Failed to download source package."
|
echo "Failed to download source package."
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -151,7 +156,9 @@ check_ports() {
|
||||||
}
|
}
|
||||||
|
|
||||||
install_backends() {
|
install_backends() {
|
||||||
echo "Install backend docker services"
|
echo_prefix_backends=$'\n[Backend] - '
|
||||||
|
echo "$echo_prefix_backends Install backend docker services"
|
||||||
|
|
||||||
cd "$install_path/docker"
|
cd "$install_path/docker"
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Failed to change directory."
|
echo "Failed to change directory."
|
||||||
|
@ -179,8 +186,15 @@ install_backends() {
|
||||||
|
|
||||||
|
|
||||||
install_systemd() {
|
install_systemd() {
|
||||||
echo "Install Systemd service"
|
echo_prefix_systemd=$'\n[Systemd] - '
|
||||||
cp "$install_path/systemd/websoft9.service" /lib/systemd/system/
|
echo "$echo_prefix_systemdInstall Systemd service"
|
||||||
|
|
||||||
|
if [ ! -d "$systemd_path" ]; then
|
||||||
|
sudo mkdir -p "$systemd_path"
|
||||||
|
fi
|
||||||
|
|
||||||
|
sudo cp -r $install_path/systemd/* "$systemd_path"
|
||||||
|
sudo cp -f "$systemd_path/websoft9.service" /lib/systemd/system/
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Failed to copy Systemd service file."
|
echo "Failed to copy Systemd service file."
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
@ -26,7 +26,7 @@ while [[ $# -gt 0 ]]; do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# channel,source_github_pages,install_path from install.sh priority
|
||||||
if [ -z "$channel" ]; then
|
if [ -z "$channel" ]; then
|
||||||
channel="release"
|
channel="release"
|
||||||
fi
|
fi
|
||||||
|
@ -44,55 +44,65 @@ echo "Your installation parameters are as follows: "
|
||||||
echo "--channel: $channel"
|
echo "--channel: $channel"
|
||||||
|
|
||||||
artifact_url="https://w9artifact.blob.core.windows.net/$channel/websoft9/plugin"
|
artifact_url="https://w9artifact.blob.core.windows.net/$channel/websoft9/plugin"
|
||||||
echo_prefix_cockpit=$'\n[Plugins] - '
|
echo_prefix_plugins=$'\n[Plugins] - '
|
||||||
mydata=""
|
|
||||||
|
|
||||||
version_json(){
|
versions_local_file="$install_path/version.json"
|
||||||
|
versions_url="$source_github_pages/version.json"
|
||||||
|
file_suffix=".zip"
|
||||||
|
plugin_path="/usr/share/cockpit"
|
||||||
|
|
||||||
if [ -f "$install_path/version.json" ]; then
|
echo "$echo_prefix_plugins Starting dowload plugin and update it"
|
||||||
echo "Find version file on your $install_path "
|
|
||||||
mydata=$(cat "$install_path/version.json")
|
|
||||||
echo $mydata
|
|
||||||
else
|
|
||||||
echo "Get version.json from $source_github_pages/version.json"
|
|
||||||
mydata=$(curl -s "$source_github_pages/version.json")
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "URL does not exist or cannot be accessed."
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
echo "$mydata"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
python3 - << END
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
import queue
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import zipfile
|
||||||
|
import io
|
||||||
|
|
||||||
install_plugins() {
|
def get_plugin_versions(versions_local_file, versions_url, artifact_url, file_suffix, plugin_path):
|
||||||
echo "$echo_prefix_cockpit Start to install plugins"
|
if os.path.exists(versions_local_file):
|
||||||
echo $mydata
|
print("Get version file on your local install"+versions_local_file)
|
||||||
|
with open(versions_local_file) as f:
|
||||||
|
data = json.load(f)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
print("Get version file from URL " + versions_url)
|
||||||
|
response = requests.get(versions_url, timeout=5) # Set timeout to 5 seconds
|
||||||
|
data = json.loads(response.text)
|
||||||
|
except (requests.exceptions.RequestException, json.JSONDecodeError) as e:
|
||||||
|
print("Error occurred while getting version file from URL: ", e)
|
||||||
|
sys.exit(1) # Exit the program if an error occurred
|
||||||
|
|
||||||
# 解析数据文件,获取 plugins 的子元素和对应的版本号
|
plugins = data.get('plugins', {})
|
||||||
plugins=$(echo "$data" | jq -r '.plugins | keys_unsorted[]')
|
|
||||||
versions=$(echo "$data" | jq -r '.plugins | .[]')
|
|
||||||
|
|
||||||
echo $plugins
|
q = queue.Queue()
|
||||||
echo $versions
|
for plugin, version in plugins.items():
|
||||||
|
q.put(f'{artifact_url}/{plugin}/{plugin}-{version}{file_suffix}')
|
||||||
|
|
||||||
# 定义数组变量
|
return q
|
||||||
declare -a artifact_array
|
|
||||||
|
|
||||||
# 构建数组内容
|
# 使用函数
|
||||||
readarray -t plugins_array <<<"$plugins"
|
q = get_plugin_versions("${versions_local_file}", "${versions_url}", "${artifact_url}", "${file_suffix}", "${plugin_path}")
|
||||||
readarray -t versions_array <<<"$versions"
|
|
||||||
|
|
||||||
for ((i=0; i<${#plugins_array[@]}; i++)); do
|
# 下载并解压缩文件
|
||||||
artifact_array+=("$artifact_url/${plugins_array[$i]}-${versions_array[$i]}")
|
while not q.empty():
|
||||||
done
|
try:
|
||||||
|
file_url = q.get()
|
||||||
|
print(f"Downloading {file_url}...")
|
||||||
|
response = requests.get(file_url, stream=True, timeout=120) # Set timeout to 120 seconds
|
||||||
|
|
||||||
# 打印数组元素
|
# Make sure the download was successful
|
||||||
for element in "${artifact_array[@]}"; do
|
response.raise_for_status()
|
||||||
echo "$element"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
version_json
|
with zipfile.ZipFile(io.BytesIO(response.content)) as z:
|
||||||
install_plugins
|
z.extractall("${plugin_path}")
|
||||||
|
print(f"Successfully extracted {file_url} to ${plugin_path}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error occurred while downloading or extracting file: {e}")
|
||||||
|
sys.exit(1) # Exit the program if an error occurred
|
||||||
|
END
|
||||||
|
|
||||||
|
echo "Plugins install successfully..."
|
||||||
|
|
|
@ -3,3 +3,14 @@
|
||||||
This is the Websoft9 system service that run some proxy services on the host machine for Websoft9 to solve the problem that the API cannot handle.
|
This is the Websoft9 system service that run some proxy services on the host machine for Websoft9 to solve the problem that the API cannot handle.
|
||||||
|
|
||||||
- Copy credentials from one other containers to apphub container
|
- Copy credentials from one other containers to apphub container
|
||||||
|
|
||||||
|
## Test it
|
||||||
|
|
||||||
|
```
|
||||||
|
export install_path="/data/websoft9/source"
|
||||||
|
chmod +x $install_path/systemd/send_credentials.sh
|
||||||
|
cp $install_path/systemd/websoft9.service /lib/systemd/system/
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
sudo systemctl enable websoft9.service
|
||||||
|
sudo systemctl start websoft9
|
||||||
|
```
|
|
@ -1,4 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
# Define PATH
|
||||||
|
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||||
|
# Export PATH
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
43
systemd/script/set_hosts.sh
Normal file
43
systemd/script/set_hosts.sh
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Define PATH
|
||||||
|
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||||
|
# Export PATH
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# 容器名称
|
||||||
|
container_name="websoft9-apphub"
|
||||||
|
|
||||||
|
# 最大尝试次数
|
||||||
|
max_attempts=60
|
||||||
|
|
||||||
|
# 获取容器的内网IP
|
||||||
|
attempt=0
|
||||||
|
while [ $attempt -lt $max_attempts ]; do
|
||||||
|
container_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $container_name)
|
||||||
|
|
||||||
|
if [ -n "$container_ip" ]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
attempt=$(( $attempt + 1 ))
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
|
||||||
|
# 检查获取IP是否成功
|
||||||
|
if [ -z "$container_ip" ]; then
|
||||||
|
echo "Failed to get IP for container $container_name after $max_attempts attempts"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 检查 /etc/hosts 文件中是否已经存在一个条目与容器名称相同
|
||||||
|
if grep -q $container_name /etc/hosts; then
|
||||||
|
# 如果存在,使用 sed 命令更新这个条目
|
||||||
|
sudo sed -i "/$container_name/d" /etc/hosts
|
||||||
|
echo "$container_ip $container_name" | sudo tee -a /etc/hosts > /dev/null
|
||||||
|
echo "Container $container_name IP updated to $container_ip in /etc/hosts"
|
||||||
|
else
|
||||||
|
# 如果不存在,添加一个新的条目
|
||||||
|
echo "$container_ip $container_name" | sudo tee -a /etc/hosts > /dev/null
|
||||||
|
echo "Container $container_name IP $container_ip added to /etc/hosts"
|
||||||
|
fi
|
5
systemd/script/start_up.sh
Normal file
5
systemd/script/start_up.sh
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# 在这个脚本中,我们将运行两个脚本
|
||||||
|
/bin/bash send_credentials.sh
|
||||||
|
/bin/bash set_hosts.sh
|
|
@ -1,12 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
# Define PATH
|
|
||||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
|
||||||
# Export PATH
|
|
||||||
export PATH
|
|
||||||
export install_path="/data/websoft9"
|
|
||||||
|
|
||||||
chmod +x $install_path/systemd/send_credentials.sh
|
|
||||||
cp $install_path/systemd/websoft9.service /lib/systemd/system/
|
|
||||||
sudo systemctl daemon-reload
|
|
||||||
sudo systemctl enable websoft9.service
|
|
||||||
sudo systemctl start websoft9
|
|
|
@ -4,8 +4,8 @@ Requires=network.target docker
|
||||||
After=network.target docker
|
After=network.target docker
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
WorkingDirectory=/data/websoft9/systemd
|
WorkingDirectory=/opt/websoft9/systemd
|
||||||
ExecStart=/bin/bash send_credentials.sh
|
ExecStart=/bin/bash /opt/websoft9/systemd/startup.sh
|
||||||
Restart=always
|
Restart=always
|
||||||
Type=simple
|
Type=simple
|
||||||
NotifyAccess=all
|
NotifyAccess=all
|
||||||
|
|
Loading…
Reference in a new issue