From adb4e730efe8952e3f1644c659f4a17910617766 Mon Sep 17 00:00:00 2001 From: qiaofeng1227 <76487013@qq.com> Date: Thu, 7 Dec 2023 15:11:44 +0800 Subject: [PATCH] install_app.sh --- scripts/install_app.sh | 133 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 129 insertions(+), 4 deletions(-) diff --git a/scripts/install_app.sh b/scripts/install_app.sh index 33cdd90d..7c2d42e6 100644 --- a/scripts/install_app.sh +++ b/scripts/install_app.sh @@ -33,9 +33,134 @@ export PATH # $ sudo bash install.sh --domain_names "test1.websoft9.com,test2.websoft9.com" # ============================================================================== +# 设置参数的默认值 +dist="community" +version="latest" +appname="wordpress" +appid="mywp" +domain_names="" +proxy_enabled=true +# 获取参数值 +while [[ $# -gt 0 ]]; do + case $1 in + --dist) + shift + if [[ $1 == --* ]]; then + echo "Missing value for --dist" + exit 1 + fi + dist="$1" + shift + ;; + --version) + shift + if [[ $1 == --* ]]; then + echo "Missing value for --version" + exit 1 + fi + version="$1" + shift + ;; + --appname) + shift + if [[ $1 == --* ]]; then + echo "Missing value for --appname" + exit 1 + fi + appname="$1" + shift + ;; + --appid) + shift + if [[ $1 == --* ]]; then + echo "Missing value for --appid" + exit 1 + fi + appid="$1" + shift + ;; + --domain_names) + shift + if [[ $1 == --* ]]; then + echo "Missing value for --domain_names" + exit 1 + fi + domain_names="$1" + shift + ;; + *) + echo "Unknown parameter: $1" + exit 1 + ;; + esac +done -# Get Internet IP by path/scripts/get_ip.sh -# if have W9_URL, then proxy_enabled=true -# Get the installed application status -# if active, docker compose ps \ No newline at end of file +have_websoft9=$(docker compose ls | grep websoft9) +if [ -z "$have_websoft9" ]; then + echo "You must install websoft9 service first" + exit 1 +fi + +echo "Start to get ip from script" +get_ip_path=$(find / -name get_ip.sh 2>/dev/null) +public_ip=$(bash "$get_ip_path") +if [ -z "$domain_names" ]; then + domain_names="$public_ip" +fi + +rm -rf /tmp/library && sudo docker cp websoft9-apphub:/websoft9/library /tmp +filename="/tmp/library/apps/${appname}/.env" +if ! grep -q "W9_URL" "$filename"; then + proxy_enabled=false +else + echo "W9_URL found in $filename." +fi + +settings=$(grep "^W9_.*_SET=" "$filename" | awk -F '=' '{print $1, $2}' | \ +while read -r key value; do + jq -n --arg key "$key" --arg value "$value" '{($key): $value}' +done | jq -s add | jq -c .) + +echo "Start to install $appname" +api_url="$public_ip/api/apps/install" +api_key=$(sudo docker exec -i websoft9-apphub apphub getconfig --section api_key --key key) +request_param=$(jq -n \ + --arg app_name "$appname" \ + --arg dist "$dist" \ + --arg version "$version" \ + --arg app_id "$appid" \ + --argjson proxy_enabled "$proxy_enabled" \ + --arg domain_names "$domain_names" \ + --argjson settings "$settings" \ + '{ + "app_name": $app_name, + "edition": { + "dist": $dist, + "version": $version + }, + "app_id": $app_id, + "proxy_enabled": $proxy_enabled, + "domain_names": [$domain_names], + "settings": $settings + }') + +echo "####################################################" +echo $request_param +response=$(curl -s -w "%{http_code}" -X POST "$api_url" \ + -H "Content-Type: application/json" \ + -H "x-api-key: $api_key" \ + -d "$request_param") +echo "--------------------------------------------------" +echo "$response" +echo "---------------------------------------------------" +http_code=$(echo "$response" | tail -n1) +response_body=$(echo "$response" | head -n -1) + +if [ "$http_code" -eq 200 ]; then + sudo docker ps -a |grep "$appid" +else + error_message=$(echo "$response_body" | jq -r '.message') + error_details=$(echo "$response_body" | jq -r '.details') + echo "Error: $error_message, Details: $error_details" +fi \ No newline at end of file