@@ -33,9 +33,134 @@ export PATH
33
33
# $ sudo bash install.sh --domain_names "test1.websoft9.com,test2.websoft9.com"
34
34
# ==============================================================================
35
35
36
+ # 设置参数的默认值
37
+ dist=" community"
38
+ version=" latest"
39
+ appname=" wordpress"
40
+ appid=" mywp"
41
+ domain_names=" "
42
+ proxy_enabled=true
36
43
44
+ # 获取参数值
45
+ while [[ $# -gt 0 ]]; do
46
+ case $1 in
47
+ --dist)
48
+ shift
49
+ if [[ $1 == --* ]]; then
50
+ echo " Missing value for --dist"
51
+ exit 1
52
+ fi
53
+ dist=" $1 "
54
+ shift
55
+ ;;
56
+ --version)
57
+ shift
58
+ if [[ $1 == --* ]]; then
59
+ echo " Missing value for --version"
60
+ exit 1
61
+ fi
62
+ version=" $1 "
63
+ shift
64
+ ;;
65
+ --appname)
66
+ shift
67
+ if [[ $1 == --* ]]; then
68
+ echo " Missing value for --appname"
69
+ exit 1
70
+ fi
71
+ appname=" $1 "
72
+ shift
73
+ ;;
74
+ --appid)
75
+ shift
76
+ if [[ $1 == --* ]]; then
77
+ echo " Missing value for --appid"
78
+ exit 1
79
+ fi
80
+ appid=" $1 "
81
+ shift
82
+ ;;
83
+ --domain_names)
84
+ shift
85
+ if [[ $1 == --* ]]; then
86
+ echo " Missing value for --domain_names"
87
+ exit 1
88
+ fi
89
+ domain_names=" $1 "
90
+ shift
91
+ ;;
92
+ * )
93
+ echo " Unknown parameter: $1 "
94
+ exit 1
95
+ ;;
96
+ esac
97
+ done
37
98
38
- # Get Internet IP by path/scripts/get_ip.sh
39
- # if have W9_URL, then proxy_enabled=true
40
- # Get the installed application status
41
- # if active, docker compose ps
99
+ have_websoft9=$( docker compose ls | grep websoft9)
100
+ if [ -z " $have_websoft9 " ]; then
101
+ echo " You must install websoft9 service first"
102
+ exit 1
103
+ fi
104
+
105
+ echo " Start to get ip from script"
106
+ get_ip_path=$( find / -name get_ip.sh 2> /dev/null)
107
+ public_ip=$( bash " $get_ip_path " )
108
+ if [ -z " $domain_names " ]; then
109
+ domain_names=" $public_ip "
110
+ fi
111
+
112
+ rm -rf /tmp/library && sudo docker cp websoft9-apphub:/websoft9/library /tmp
113
+ filename=" /tmp/library/apps/${appname} /.env"
114
+ if ! grep -q " W9_URL" " $filename " ; then
115
+ proxy_enabled=false
116
+ else
117
+ echo " W9_URL found in $filename ."
118
+ fi
119
+
120
+ settings=$( grep " ^W9_.*_SET=" " $filename " | awk -F ' =' ' {print $1, $2}' | \
121
+ while read -r key value; do
122
+ jq -n --arg key " $key " --arg value " $value " ' {($key): $value}'
123
+ done | jq -s add | jq -c .)
124
+
125
+ echo " Start to install $appname "
126
+ api_url=" $public_ip /api/apps/install"
127
+ api_key=$( sudo docker exec -i websoft9-apphub apphub getconfig --section api_key --key key)
128
+ request_param=$( jq -n \
129
+ --arg app_name " $appname " \
130
+ --arg dist " $dist " \
131
+ --arg version " $version " \
132
+ --arg app_id " $appid " \
133
+ --argjson proxy_enabled " $proxy_enabled " \
134
+ --arg domain_names " $domain_names " \
135
+ --argjson settings " $settings " \
136
+ ' {
137
+ "app_name": $app_name,
138
+ "edition": {
139
+ "dist": $dist,
140
+ "version": $version
141
+ },
142
+ "app_id": $app_id,
143
+ "proxy_enabled": $proxy_enabled,
144
+ "domain_names": [$domain_names],
145
+ "settings": $settings
146
+ }' )
147
+
148
+ echo " ####################################################"
149
+ echo $request_param
150
+ response=$( curl -s -w " %{http_code}" -X POST " $api_url " \
151
+ -H " Content-Type: application/json" \
152
+ -H " x-api-key: $api_key " \
153
+ -d " $request_param " )
154
+ echo " --------------------------------------------------"
155
+ echo " $response "
156
+ echo " ---------------------------------------------------"
157
+ http_code=$( echo " $response " | tail -n1)
158
+ response_body=$( echo " $response " | head -n -1)
159
+
160
+ if [ " $http_code " -eq 200 ]; then
161
+ sudo docker ps -a | grep " $appid "
162
+ else
163
+ error_message=$( echo " $response_body " | jq -r ' .message' )
164
+ error_details=$( echo " $response_body " | jq -r ' .details' )
165
+ echo " Error: $error_message , Details: $error_details "
166
+ fi
0 commit comments