From 1dfd130c31ab6d4b66317df859c5d84a65690007 Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Thu, 10 Nov 2016 16:18:13 +0800 Subject: [PATCH] fixes #995, fixes #1047 --- tools/ova/script/config.sh | 20 ++++++++++++-------- tools/ova/script/firstboot.sh | 11 ++++++++++- tools/ova/script/subsequentboot.sh | 2 +- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/tools/ova/script/config.sh b/tools/ova/script/config.sh index 1081b0d31..884835a51 100755 --- a/tools/ova/script/config.sh +++ b/tools/ova/script/config.sh @@ -3,7 +3,6 @@ set -e attrs=( harbor_admin_password - auth_mode ldap_url ldap_searchdn ldap_search_pwd @@ -37,13 +36,18 @@ function format { } #Modify hostname -ip=$(ip addr show eth0|grep "inet "|tr -s ' '|cut -d ' ' -f 3|cut -d '/' -f 1) -if [ -n "$ip" ] +hostname=$(hostname --fqdn) || true +if [ -z "$hostname" ] then - echo "Read IP address: [ IP - $ip ]" - sed -i -r s/"hostname = .*"/"hostname = $ip"/ $cfg + hostname=$(ip addr show eth0|grep "inet "|tr -s ' '|cut -d ' ' -f 3|cut -d '/' -f 1) +fi + +if [ -n "$hostname" ] +then + echo "Read hostname/IP: [ hostname/IP - $hostname ]" + sed -i -r s/"hostname\s*=\s*.*"/"hostname = $hostname"/ $cfg else - echo "Failed to get the IP address" + echo "Failed to get the hostname/IP" exit 1 fi @@ -57,7 +61,7 @@ if [ -n "$ssl_cert" ] && [ -n "$ssl_cert_key" ] then echo "ssl_cert and ssl_cert_key are set, using HTTPS protocol" protocol=https - sed -i -r s%"#?ui_url_protocol = .*"%"ui_url_protocol = $protocol"% $cfg + sed -i -r s%"#?ui_url_protocol\s*=\s*.*"%"ui_url_protocol = $protocol"% $cfg echo $ssl_cert > /data/server.crt format /data/server.crt echo $ssl_cert_key > /data/server.key @@ -83,6 +87,6 @@ do bs=$(echo $value | base64) #value={base64}$bs fi - sed -i -r s%"#?$attr = .*"%"$attr = $value"% $cfg + sed -i -r s%"#?$attr\s*=\s*.*"%"$attr = $value"% $cfg fi done \ No newline at end of file diff --git a/tools/ova/script/firstboot.sh b/tools/ova/script/firstboot.sh index f60e4168e..a59da1d3d 100755 --- a/tools/ova/script/firstboot.sh +++ b/tools/ova/script/firstboot.sh @@ -34,9 +34,18 @@ tar -zxvf $base_dir/../harbor-offline-installer*.tgz -C $base_dir/../ echo "Loading images..." load -#Configure Harbor echo "Configuring Harbor..." chmod 600 $base_dir/../harbor/harbor.cfg + +#Configure authentication mode +echo "Read attribute using ovfenv: [ auth_mode ]" +auth_mode=$(ovfenv -k auth_mode) +if [ -n "$auth_mode" ] +then + sed -i -r s%"#?auth_mode\s*=\s*.*"%"auth_mode = $auth_mode"% $base_dir/../harbor/harbor.cfg +fi + +#Configure other attrs configure #Start Harbor diff --git a/tools/ova/script/subsequentboot.sh b/tools/ova/script/subsequentboot.sh index 9cf9a8c0f..25fd2b116 100755 --- a/tools/ova/script/subsequentboot.sh +++ b/tools/ova/script/subsequentboot.sh @@ -15,7 +15,7 @@ addIptableRules #Stop Harbor echo "Shutting down Harbor..." -down +down || true #Garbage collection value=$(ovfenv -k gc_enabled)