Skip to content

Commit

Permalink
Merge pull request #2094 from jooskim/ui-installer-improvement
Browse files Browse the repository at this point in the history
Improve UI installer
  • Loading branch information
jooskim authored Aug 31, 2016
2 parents 1e96aa9 + 4abaeda commit 7ed76a8
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 81 deletions.
120 changes: 73 additions & 47 deletions ui/installer/VCSA/install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash -e
#!/bin/bash
# Copyright 2016 VMware, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,9 +14,19 @@
# limitations under the License.
#

cleanup () {
unset VCENTER_ADMIN_USERNAME
unset VCENTER_ADMIN_PASSWORD
unset BASH_ENABLED_ON_VCSA
if [[ -f tmp.txt ]] ; then
rm tmp.txt
fi
}

if [[ ! -f "configs" ]] ; then
echo "Error! Configs file is missing. Please try downloading the VIC UI installer again"
echo ""
cleanup
exit 1
fi

Expand All @@ -27,6 +37,7 @@ done < $CONFIGS_FILE

if [[ $VCENTER_IP == "" ]] ; then
echo "Error! vCenter IP cannot be empty. Please provide a valid IP in the configs file"
cleanup
exit 1
fi

Expand All @@ -35,23 +46,33 @@ echo -n "Enter your vCenter Administrator Password: "
read -s VCENTER_ADMIN_PASSWORD
echo ""

read -p "Are you running vCenter 5.5? (y/n): " IS_VCENTER_5_5
if [[ $(echo $IS_VCENTER_5_5 | grep -i "y") ]] ; then
IS_VCENTER_5_5=1
WEBCLIENT_PLUGINS_FOLDER="/var/lib/vmware/vsphere-client/vc-packages/vsphere-client-serenity/"
else
WEBCLIENT_PLUGINS_FOLDER="/etc/vmware/vsphere-client/vc-packages/vsphere-client-serenity/"
fi
BASH_ENABLED_ON_VCSA=1

echo "----------------------------------------"
echo "Checking if VCSA has Bash shell enabled..."
echo "Please enter the root password"
echo "----------------------------------------"
if [[ $VIC_UI_HOST_URL == "NOURL" ]] ; then
read -p "Are you running vCenter 5.5? (y/n): " IS_VCENTER_5_5
if [[ $(echo $IS_VCENTER_5_5 | grep -i "y") ]] ; then
IS_VCENTER_5_5=1
WEBCLIENT_PLUGINS_FOLDER="/var/lib/vmware/vsphere-client/vc-packages/vsphere-client-serenity/"
else
WEBCLIENT_PLUGINS_FOLDER="/etc/vmware/vsphere-client/vc-packages/vsphere-client-serenity/"
fi

if [[ $(ssh root@$VCENTER_IP -t "scp" 2> /dev/null 2>&1 | grep -i "unknown command") ]] ; then
BASH_ENABLED_ON_VCSA=0
else
BASH_ENABLED_ON_VCSA=1
echo "----------------------------------------"
echo "Checking if VCSA has Bash shell enabled..."
echo "Please enter the root password"
echo "----------------------------------------"

ssh root@$VCENTER_IP -t "scp" > tmp.txt 2>&1
if [[ $(cat tmp.txt | grep -i "unknown command") ]] ; then
BASH_ENABLED_ON_VCSA=0
elif [[ $(cat tmp.txt | grep -i "Permission denied (publickey,password).") ]] ; then
echo "----------------------------------------"
echo "Error! Root password is incorrect"
cleanup
exit 1
elif [[ $SIMULATE_NO_BASH_SUPPORT -eq 1 ]] ; then
BASH_ENABLED_ON_VCSA=0
fi
fi

OS=$(uname)
Expand All @@ -78,9 +99,9 @@ fi

if [[ $VIC_UI_HOST_URL != 'NOURL' ]] ; then
if [[ ${VIC_UI_HOST_URL:0:5} == 'https' ]] ; then
COMMONFLAGS="${COMMONFLAGS} --serverThumbprint ${VIC_UI_HOST_THUMBPRINT}"
COMMONFLAGS="${COMMONFLAGS} --server-thumbprint ${VIC_UI_HOST_THUMBPRINT}"
elif [[ ${VIC_UI_HOST_URL:0:5} == 'HTTPS' ]] ; then
COMMONFLAGS="${COMMONFLAGS} --serverThumbprint ${VIC_UI_HOST_THUMBPRINT}"
COMMONFLAGS="${COMMONFLAGS} --server-thumbprint ${VIC_UI_HOST_THUMBPRINT}"
fi

if [[ ${VIC_UI_HOST_URL: -1: 1} != "/" ]] ; then
Expand All @@ -91,17 +112,12 @@ fi
check_prerequisite () {
if [[ ! -d ../vsphere-client-serenity ]] ; then
echo "Error! VIC UI plugin bundle was not found. Please try downloading the VIC UI installer again"
cleanup
exit 1
fi
}

parse_and_register_plugins () {
if [[ $BASH_ENABLED_ON_VCSA -eq 0 ]] ; then
if [[ -f extension_already_registered ]] ; then
return 0
fi
fi

for d in ../vsphere-client-serenity/* ; do
if [[ -d $d ]] ; then
echo "Reading plugin-package.xml..."
Expand All @@ -118,11 +134,12 @@ parse_and_register_plugins () {
if [[ $plugin_url != 'NOURL' ]] ; then
if [[ ! -f "../vsphere-client-serenity/${key}-${version}.zip" ]] ; then
echo "File ${key}-${version}.zip does not exist!"
cleanup
exit 1
fi
local plugin_url="$plugin_url$key-$version.zip"
fi

local plugin_flags="--key $key --name $name --version $version --summary $summary --company $company --url $plugin_url"
echo "----------------------------------------"
echo "Registering vCenter Server Extension..."
Expand All @@ -137,19 +154,20 @@ parse_and_register_plugins () {
$PLUGIN_MANAGER_BIN install $COMMONFLAGS $plugin_flags

if [[ $? > 0 ]] ; then
echo "-------------------------------------------------------------"
echo "Error! Could not register plugin with vCenter Server. Please see the message above"
cleanup
exit 1
fi
fi
done

touch extension_already_registered
}

rename_package_folder () {
mv $1 $2
if [[ $? > 0 ]] ; then
echo "Error! Could not rename folder"
cleanup
exit 1
fi
}
Expand All @@ -168,7 +186,9 @@ upload_packages () {
echo "-------------------------------------------------------------"
scp -qr $PLUGIN_BUNDLES root@$VCENTER_IP:/tmp/
if [[ $? > 0 ]] ; then
echo "-------------------------------------------------------------"
echo "Error! Could not upload the VIC plugins to the target VCSA"
cleanup
exit 1
fi
else
Expand Down Expand Up @@ -215,39 +235,45 @@ update_ownership () {

ssh -t root@$VCENTER_IP $SSH_COMMANDS_STR
if [[ $? > 0 ]] ; then
echo "-------------------------------------------------------------"
echo "Error! Failed to update the ownership of folders. Please manually set them to vsphere-client:users"
cleanup
exit 1
fi
}

cleanup () {
unset VCENTER_ADMIN_USERNAME
unset VCENTER_ADMIN_PASSWORD
unset BASH_ENABLED_ON_VCSA
verify_plugin_url () {
local PLUGIN_BASENAME=$(find ../vsphere-client-serenity/ -name '*.zip' -print0 | xargs -0 basename)
local CURL_RESPONSE=$(curl -v --head $VIC_UI_HOST_URL$PLUGIN_BASENAME -k 2>&1)
local RESPONSE_STATUS=$(echo $CURL_RESPONSE | grep -E "HTTP\/.*\s4\d{2}\s.*")

if [[ $(echo $CURL_RESPONSE | grep -i "could not resolve host") ]] ; then
echo "-------------------------------------------------------------"
echo "Error! Could not resolve the host provided. Please make sure the URL is correct"
cleanup
exit 1

elif [[ ! $(echo $RESPONSE_STATUS | wc -w) -eq 0 ]] ; then
echo "-------------------------------------------------------------"
echo "Error! Plugin was not found in the web server. Please make sure you have uploaded \"$PLUGIN_BASENAME\" to \"$VIC_UI_HOST_URL\", and retry installing the plugin"
cleanup
exit 1
fi

}

# Check if plugin is located properly
check_prerequisite

# Read from each plugin bundle the plugin-package.xml file and register a vCenter Server Extension based off of it
# Also, rename the folders such that they follow the convention of $PLUGIN_KEY-$PLUGIN_VERSION
parse_and_register_plugins

# if VIC_UI_HOST_URL is NOURL
if [[ $VIC_UI_HOST_URL == "NOURL" ]] ; then
# Upload the folders to VCSA's vSphere Web Client plugins cache folder
parse_and_register_plugins
upload_packages
# Chown the uploaded folders from root to vsphere-client
update_ownership
else
verify_plugin_url
parse_and_register_plugins
fi

cleanup
rm extension_already_registered

if [[ $? > 0 ]] ; then
echo "--------------------------------------------------------------"
echo "Error! There was a problem removing a temporary file. Please manually remove extension_already_registered if it exists"
else
echo "--------------------------------------------------------------"
echo "VIC UI registration was successful"
fi
echo "--------------------------------------------------------------"
echo "VIC UI registration was successful"
47 changes: 14 additions & 33 deletions ui/installer/VCSA/uninstall.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash -e
#!/bin/bash
# Copyright 2016 VMware, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -35,14 +35,6 @@ echo -n "Enter your vCenter Administrator Password: "
read -s VCENTER_ADMIN_PASSWORD
echo ""

read -p "Are you running vCenter 5.5? (y/n): " IS_VCENTER_5_5
if [[ $(echo $IS_VCENTER_5_5 | grep -i "y") ]] ; then
IS_VCENTER_5_5=1
WEBCLIENT_PLUGINS_FOLDER="/var/lib/vmware/vsphere-client/vc-packages/vsphere-client-serenity/"
else
WEBCLIENT_PLUGINS_FOLDER="/etc/vmware/vsphere-client/vc-packages/vsphere-client-serenity/"
fi

OS=$(uname)
PLUGIN_BUNDLES=''
VCENTER_SDK_URL="https://${VCENTER_IP}/sdk/"
Expand All @@ -55,6 +47,13 @@ else
PLUGIN_MANAGER_BIN="../../vic-ui-linux"
fi

check_prerequisite () {
if [[ ! -d ../vsphere-client-serenity ]] ; then
echo "Error! VIC UI plugin bundle was not found. Please try downloading the VIC UI installer again"
exit 1
fi
}

parse_and_unregister_plugins () {
for d in ../vsphere-client-serenity/* ; do
if [[ -d $d ]] ; then
Expand All @@ -63,31 +62,20 @@ parse_and_unregister_plugins () {
while IFS='' read -r p_line; do
eval "local $p_line"
done < $d/vc_extension_flags

local plugin_flags="--key $key"
echo "-------------------------------------------------------------"
echo "Unregistering vCenter Server Extension..."
echo "-------------------------------------------------------------"
$PLUGIN_MANAGER_BIN remove $COMMONFLAGS $plugin_flags

if [[ $? > 0 ]] ; then
echo "Error! Could not unregister plugin with vCenter Server. Please see the message above."
echo "-------------------------------------------------------------"
echo "Error! Could not unregister plugin from vCenter Server. Please see the message above."
exit 1
fi

if [[ $PLUGIN_FOLDERS -eq "" ]] ; then
PLUGIN_FOLDERS="$key-*"
else
PLUGIN_FOLDERS="$PLUGIN_FOLDERS $key-*"
fi
fi
done

echo "-------------------------------------------------------------"
echo "Deleting plugin contents..."
echo "Please enter the root password for your machine running VCSA"
echo "-------------------------------------------------------------"
ssh -t root@$VCENTER_IP "cd $WEBCLIENT_PLUGINS_FOLDER; rm -rf $PLUGIN_FOLDERS"
}

rename_package_folder () {
Expand All @@ -98,15 +86,8 @@ rename_package_folder () {
fi
}

# Read from each plugin bundle the plugin-package.xml file and register a vCenter Server Extension based off of it
# Also, rename the folders such that they follow the convention of $PLUGIN_KEY-$PLUGIN_VERSION
check_prerequisite
parse_and_unregister_plugins

if [[ $? > 0 ]] ; then
echo "--------------------------------------------------------------"
echo "There was a problem in the VIC UI unregistration process"
exit 1
else
echo "--------------------------------------------------------------"
echo "VIC UI unregistration was successful"
fi
echo "--------------------------------------------------------------"
echo "VIC UI unregistration was successful"
1 change: 1 addition & 0 deletions ui/installer/vCenterForWindows/configs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ SET sftp_username=
SET sftp_password=

REM Location of C:\ProgramData\VMware\vCenterServer\cfg\vsphere-client\vc-packages\vsphere-serenity relative to the root of SFTP connection
REM Note: If you are running vCenter 5.5 Windows, the location should point to C:\ProgramData\VMware\vSphere Web Client\vc-packages\vsphere-serenity
SET target_vc_packages_path=/vsphere-client/vc-packages/vsphere-client-serenity/
3 changes: 2 additions & 1 deletion ui/installer/vCenterForWindows/install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ IF [%1] == [--force] (

IF /I %vic_ui_host_url% NEQ NOURL (
IF /I %vic_ui_host_url:~0,5%==https (
SET vcenter_reg_common_flags=%vcenter_reg_common_flags% --serverThumbprint %vic_ui_host_thumbprint%
SET vcenter_reg_common_flags=%vcenter_reg_common_flags% --server-thumbprint %vic_ui_host_thumbprint%
)

IF %vic_ui_host_url:~-1,1% NEQ / (
Expand All @@ -56,6 +56,7 @@ IF /I %vic_ui_host_url% NEQ NOURL (
"%utils_path%winscp.com" /command "open -hostkey=* sftp://%sftp_username%:%sftp_password%@%target_vcenter_ip%" "put -filemask=|*.zip ..\vsphere-client-serenity\* %target_vc_packages_path%" "exit"
) ELSE (
ECHO SFTP not enabled. You have to manually copy the com.vmware.vicui.* folder in \ui\vsphere-client-serenity to %VMWARE_CFG_DIR%\vsphere-client\vc-packages\vsphere-client-serenity
ECHO Note: If you are running vCenter 5.5 Windows, copy the folder to %PROGRAMDATA%\VMware\vSphere Web Client\vc-packages\vsphere-client-serenity
)
)

Expand Down

0 comments on commit 7ed76a8

Please sign in to comment.