change indentation from tabs to spaces and couple other minor suggestions by shfmt

This commit is contained in:
ronivay
2021-08-24 08:57:15 +03:00
parent 03f5ad9d10
commit 8bd090aada
2 changed files with 1021 additions and 1017 deletions

View File

@@ -99,8 +99,11 @@ function selfUpgrade {
runcmd "cd $SCRIPT_DIR && git fetch"
if [[ $(runcmd_stdout "cd $SCRIPT_DIR && git diff --name-only @{upstream}| grep xo-install.sh") ]]; then
printinfo "Newer version of script available, attempting to self upgrade"
runcmd "cd $SCRIPT_DIR && git pull --ff-only" && \
{ printok "Self upgrade done" ; exec "$SCRIPT_DIR/xo-install.sh" "$@"; } || \
runcmd "cd $SCRIPT_DIR && git pull --ff-only" &&
{
printok "Self upgrade done"
exec "$SCRIPT_DIR/xo-install.sh" "$@"
} ||
printfail "Failed to self upgrade. Check logs for more details"
fi
fi
@@ -108,7 +111,6 @@ function selfUpgrade {
}
# log script version (git commit) and configuration variables to logfile
function scriptInfo {
@@ -117,10 +119,10 @@ function scriptInfo {
local SCRIPTVERSION=$(cd "$SCRIPT_DIR" 2>/dev/null && git rev-parse --short HEAD 2>/dev/null)
[ -z "$SCRIPTVERSION" ] && SCRIPTVERSION="undefined"
echo "Running script version $SCRIPTVERSION with config:" >> "$LOGFILE"
echo >> "$LOGFILE"
[ -s "$CONFIG_FILE" ] && grep -Eo '^[A-Z_]+.*' "$CONFIG_FILE" >> "$LOGFILE" || echo "No config file found" >> "$LOGFILE"
echo >> "$LOGFILE"
echo "Running script version $SCRIPTVERSION with config:" >>"$LOGFILE"
echo >>"$LOGFILE"
[ -s "$CONFIG_FILE" ] && grep -Eo '^[A-Z_]+.*' "$CONFIG_FILE" >>"$LOGFILE" || echo "No config file found" >>"$LOGFILE"
echo >>"$LOGFILE"
}
# log actual command and it's stderr/stdout to logfile in one go
@@ -200,7 +202,7 @@ function InstallDependenciesRPM {
fi
# only install yarn repo and package if not found
if [[ -z $(runcmd_stdout "command -v yarn") ]] ; then
if [[ -z $(runcmd_stdout "command -v yarn") ]]; then
echo
printprog "Installing yarn"
runcmd "curl -s -o /etc/yum.repos.d/yarn.repo https://dl.yarnpkg.com/rpm/yarn.repo && yum -y install yarn"
@@ -208,7 +210,7 @@ function InstallDependenciesRPM {
fi
# only install epel-release if doesn't exist
if [[ -z $(runcmd_stdout "rpm -q epel-release") ]] ; then
if [[ -z $(runcmd_stdout "rpm -q epel-release") ]]; then
echo
printprog "Installing epel-repo"
runcmd "yum -y install epel-release"
@@ -216,7 +218,7 @@ function InstallDependenciesRPM {
fi
# only install libvhdi-tools if vhdimount is not present
if [[ -z $(runcmd_stdout "command -v vhdimount") ]] ; then
if [[ -z $(runcmd_stdout "command -v vhdimount") ]]; then
echo
printprog "Installing libvhdi-tools from forensics repository"
runcmd "rpm -ivh https://forensics.cert.org/cert-forensics-tools-release-el8.rpm"
@@ -293,7 +295,6 @@ function InstallDependenciesDeb {
printok "Installing setcap"
fi
# only run automated node install if executable not found
if [[ -z $(runcmd_stdout "command -v node") ]] || [[ -z $(runcmd_stdout "command -v npm") ]]; then
echo
@@ -402,7 +403,7 @@ function InstallAdditionalXOPlugins {
# shellcheck disable=SC1117
local ADDITIONAL_PLUGIN_REGEX="^https?:\/\/.*.git$"
local ADDITIONAL_PLUGIN
IFS=',' read -ra ADDITIONAL_PLUGIN <<< "$ADDITIONAL_PLUGINS"
IFS=',' read -ra ADDITIONAL_PLUGIN <<<"$ADDITIONAL_PLUGINS"
for x in "${ADDITIONAL_PLUGIN[@]}"; do
if ! [[ $x =~ $ADDITIONAL_PLUGIN_REGEX ]]; then
echo
@@ -447,7 +448,7 @@ function InstallXOPlugins {
runcmd "find \"$INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/\" -maxdepth 1 -mindepth 1 -not -name \"xo-server\" -not -name \"xo-web\" -not -name \"xo-server-cloud\" -exec ln -sn {} \"$INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/node_modules/\" \;"
else
local PLUGIN
IFS=',' read -ra PLUGIN <<< "$PLUGINS"
IFS=',' read -ra PLUGIN <<<"$PLUGINS"
for x in "${PLUGIN[@]}"; do
if [[ $(runcmd_stdout "find $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages -type d -name '$x'") ]]; then
runcmd "ln -sn $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/$x $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/node_modules/"
@@ -479,7 +480,7 @@ function InstallXO {
fi
# Create installation directory if doesn't exist already
if [[ ! -d "$INSTALLDIR" ]] ; then
if [[ ! -d "$INSTALLDIR" ]]; then
echo
printinfo "Creating missing basedir to $INSTALLDIR"
runcmd "mkdir -p \"$INSTALLDIR\""
@@ -581,7 +582,10 @@ function InstallXO {
if [[ $(runcmd_stdout "pgrep -f xo-server") ]]; then
echo
printprog "Shutting down xo-server"
runcmd "/bin/systemctl stop xo-server" || { printfail "failed to stop service, exiting..." ; exit 1; }
runcmd "/bin/systemctl stop xo-server" || {
printfail "failed to stop service, exiting..."
exit 1
}
printok "Shutting down xo-server"
fi
@@ -590,14 +594,14 @@ function InstallXO {
echo
if [[ "$FORCE" != "true" ]]; then
printinfo "Updating xen-orchestra from '$OLD_REPO_HASH_SHORT' to '$NEW_REPO_HASH_SHORT'"
echo "Updating xen-orchestra from '$OLD_REPO_HASH_SHORT' to '$NEW_REPO_HASH_SHORT'" >> "$LOGFILE"
echo "Updating xen-orchestra from '$OLD_REPO_HASH_SHORT' to '$NEW_REPO_HASH_SHORT'" >>"$LOGFILE"
else
printinfo "Updating xen-orchestra (forced) from '$OLD_REPO_HASH_SHORT' to '$NEW_REPO_HASH_SHORT'"
echo "Updating xen-orchestra (forced) from '$OLD_REPO_HASH_SHORT' to '$NEW_REPO_HASH_SHORT'" >> "$LOGFILE"
echo "Updating xen-orchestra (forced) from '$OLD_REPO_HASH_SHORT' to '$NEW_REPO_HASH_SHORT'" >>"$LOGFILE"
fi
else
printinfo "Installing xen-orchestra from branch: $BRANCH - commit: $NEW_REPO_HASH_SHORT"
echo "Installing xen-orchestra from branch: $BRANCH - commit: $NEW_REPO_HASH_SHORT" >> "$LOGFILE"
echo "Installing xen-orchestra from branch: $BRANCH - commit: $NEW_REPO_HASH_SHORT" >>"$LOGFILE"
TASK="Installation"
fi
@@ -636,8 +640,11 @@ function InstallXO {
if [[ -n "$NODEBINARY" ]]; then
printprog "Attempting to set cap_net_bind_service permission for $NODEBINARY"
runcmd "setcap 'cap_net_bind_service=+ep' $NODEBINARY" && printok "Attempting to set cap_net_bind_service permission for $NODEBINARY" \
|| { printfail "Attempting to set cap_net_bind_service permission for $NODEBINARY" ; echo " Non-privileged user might not be able to bind to <1024 port. xo-server won't start most likely" ; }
runcmd "setcap 'cap_net_bind_service=+ep' $NODEBINARY" && printok "Attempting to set cap_net_bind_service permission for $NODEBINARY" ||
{
printfail "Attempting to set cap_net_bind_service permission for $NODEBINARY"
echo " Non-privileged user might not be able to bind to <1024 port. xo-server won't start most likely"
}
else
printfail "Can't find node executable, or it's a symlink to non existing file. Not trying to setcap. xo-server won't start most likely"
fi
@@ -660,7 +667,7 @@ function InstallXO {
sleep 2
fi
if [[ "$HTTPS" == "true" ]] ; then
if [[ "$HTTPS" == "true" ]]; then
printinfo "Enabling HTTPS in xo-server configuration file"
# shellcheck disable=SC1117
runcmd "sed -i \"s%# cert = '.\/certificate.pem'%cert = '$PATH_TO_HTTPS_CERT'%\" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.toml"
@@ -675,7 +682,6 @@ function InstallXO {
runcmd "mkdir -p $CONFIGPATH/.config/xo-server"
runcmd "mv -f $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.toml $CONFIGPATH/.config/xo-server/config.toml"
fi
echo
@@ -733,7 +739,7 @@ function InstallXO {
sleep 10
# shellcheck disable=SC1117
local servicestatus="$(runcmd_stdout "journalctl --since '$LOGTIME' -u xo-server | grep 'Web server listening on https\{0,1\}:\/\/.*:$PORT'")"
(( count++ ))
((count++))
done
# if it looks like service started successfully based on logs..
@@ -746,8 +752,8 @@ function InstallXO {
fi
echo
printinfo "$TASK successful. Enabling xo-server service to start on reboot"
echo "" >> "$LOGFILE"
echo "$TASK succesful" >> "$LOGFILE"
echo "" >>"$LOGFILE"
echo "$TASK succesful" >>"$LOGFILE"
runcmd "/bin/systemctl enable xo-server"
echo
# if service startup failed...
@@ -755,10 +761,10 @@ function InstallXO {
echo
printfail "$TASK completed, but looks like there was a problem when starting xo-server/reading journalctl. Please see logs for more details"
# shellcheck disable=SC2129
echo "" >> "$LOGFILE"
echo "$TASK failed" >> "$LOGFILE"
echo "xo-server service log:" >> "$LOGFILE"
echo "" >> "$LOGFILE"
echo "" >>"$LOGFILE"
echo "$TASK failed" >>"$LOGFILE"
echo "xo-server service log:" >>"$LOGFILE"
echo "" >>"$LOGFILE"
runcmd "journalctl --since '$LOGTIME' -u xo-server >> $LOGFILE"
echo
echo "Control xo-server service with systemctl for stop/start/restart etc."
@@ -767,7 +773,6 @@ function InstallXO {
}
# run xen orchestra installation but also cleanup old installations based on value in xo-install.cfg
function UpdateXO {
@@ -837,7 +842,7 @@ function HandleArgs {
done
# can't run more than one task at the same time
if [[ "$((INSTALLARG+UPDATEARG+ROLLBACKARG))" -gt 1 ]]; then
if [[ "$((INSTALLARG + UPDATEARG + ROLLBACKARG))" -gt 1 ]]; then
echo "Define either install/update or rollback"
exit 1
fi
@@ -1073,40 +1078,40 @@ function CheckDiskFree {
# interactive menu for different options
function StartUpScreen {
echo "-----------------------------------------"
echo
echo "Welcome to automated Xen Orchestra install"
echo
echo "Following options will be used for installation:"
echo
echo -e "OS: ${COLOR_WHITE}$OSNAME $OSVERSION ${COLOR_N}"
echo -e "Basedir: ${COLOR_WHITE}$INSTALLDIR ${COLOR_N}"
echo "-----------------------------------------"
echo
echo "Welcome to automated Xen Orchestra install"
echo
echo "Following options will be used for installation:"
echo
echo -e "OS: ${COLOR_WHITE}$OSNAME $OSVERSION ${COLOR_N}"
echo -e "Basedir: ${COLOR_WHITE}$INSTALLDIR ${COLOR_N}"
if [ "$XOUSER" ]; then
if [ "$XOUSER" ]; then
echo -e "User: ${COLOR_WHITE}$XOUSER ${COLOR_N}"
else
else
echo -e "User: ${COLOR_WHITE}root ${COLOR_N}"
fi
fi
echo -e "Port: ${COLOR_WHITE}$PORT${COLOR_N}"
echo -e "HTTPS: ${COLOR_WHITE}${HTTPS}${COLOR_N}"
echo -e "Git Branch for source: ${COLOR_WHITE}$BRANCH${COLOR_N}"
echo -e "Following plugins will be installed: ${COLOR_WHITE}$PLUGINS${COLOR_N}"
echo -e "Number of previous installations to preserve: ${COLOR_WHITE}$PRESERVE${COLOR_N}"
echo -e "Node.js and yarn auto update: ${COLOR_WHITE}$AUTOUPDATE${COLOR_N}"
echo
echo -e "Errorlog is stored to ${COLOR_WHITE}$LOGFILE${COLOR_N} for debug purposes"
echo
echo -e "Xen Orchestra configuration will be stored to ${COLOR_WHITE}$CONFIGPATH/.config/xo-server/config.toml${COLOR_N}, if you don't want it to be replaced with every update, set ${COLOR_WHITE}CONFIGUPDATE${COLOR_N} to false in ${COLOR_WHITE}xo-install.cfg${COLOR_N}"
echo "-----------------------------------------"
echo -e "Port: ${COLOR_WHITE}$PORT${COLOR_N}"
echo -e "HTTPS: ${COLOR_WHITE}${HTTPS}${COLOR_N}"
echo -e "Git Branch for source: ${COLOR_WHITE}$BRANCH${COLOR_N}"
echo -e "Following plugins will be installed: ${COLOR_WHITE}$PLUGINS${COLOR_N}"
echo -e "Number of previous installations to preserve: ${COLOR_WHITE}$PRESERVE${COLOR_N}"
echo -e "Node.js and yarn auto update: ${COLOR_WHITE}$AUTOUPDATE${COLOR_N}"
echo
echo -e "Errorlog is stored to ${COLOR_WHITE}$LOGFILE${COLOR_N} for debug purposes"
echo
echo -e "Xen Orchestra configuration will be stored to ${COLOR_WHITE}$CONFIGPATH/.config/xo-server/config.toml${COLOR_N}, if you don't want it to be replaced with every update, set ${COLOR_WHITE}CONFIGUPDATE${COLOR_N} to false in ${COLOR_WHITE}xo-install.cfg${COLOR_N}"
echo "-----------------------------------------"
echo
echo -e "${COLOR_WHITE}1. Install${COLOR_N}"
echo -e "${COLOR_WHITE}2. Update${COLOR_N}"
echo -e "${COLOR_WHITE}3. Rollback${COLOR_N}"
echo -e "${COLOR_WHITE}4. Exit${COLOR_N}"
echo
read -r -p ": " option
echo
echo -e "${COLOR_WHITE}1. Install${COLOR_N}"
echo -e "${COLOR_WHITE}2. Update${COLOR_N}"
echo -e "${COLOR_WHITE}3. Rollback${COLOR_N}"
echo -e "${COLOR_WHITE}4. Exit${COLOR_N}"
echo
read -r -p ": " option
case $option in
1)
@@ -1116,8 +1121,11 @@ read -r -p ": " option
case $answer in
y)
echo "Stopping xo-server..."
runcmd "/bin/systemctl stop xo-server" \
|| { printfail "failed to stop service, exiting..." ; exit 1; }
runcmd "/bin/systemctl stop xo-server" ||
{
printfail "failed to stop service, exiting..."
exit 1
}
;;
n)
exit 0
@@ -1159,7 +1167,7 @@ read -r -p ": " option
echo
exit 0
;;
esac
esac
}
@@ -1169,7 +1177,6 @@ if [[ $# == "0" ]]; then
INTERACTIVE="true"
fi
# these functions check specific requirements and are run everytime
selfUpgrade "$@"
scriptInfo

View File

@@ -24,7 +24,6 @@ function OSCheck {
echo "Please report any issues to this github project"
echo
}
function NetworkChoose {
@@ -33,16 +32,15 @@ function NetworkChoose {
# get network name/uuid of all available networks configured in the pool
# shellcheck disable=SC1117
IFS=$'\n' read -r -d '' -a networks <<< "$(xe network-list | grep "uuid\|name-label" | cut -d':' -f2 | sed 's/^ //' | paste - -)"
IFS=$'\n' read -r -d '' -a networks <<<"$(xe network-list | grep "uuid\|name-label" | cut -d':' -f2 | sed 's/^ //' | paste - -)"
echo
echo "Which network should the VM use?"
echo
local PS3="Pick a number. CTRL+C to exit: "
select network in "${networks[@]}"
do
select network in "${networks[@]}"; do
# get only the network uuid from array which we need later on when adding vif
read -r -a network_split <<< "$network"
read -r -a network_split <<<"$network"
networkuuid=${network_split[0]}
# print a menu where to choose network from
@@ -63,7 +61,7 @@ function StorageChoose {
# get storage name/uuid of all available storages with content-type=user which should match all usable storage repositories
# shellcheck disable=SC1117
IFS=$'\n' read -r -d '' -a storages <<< "$(xe sr-list content-type=user | grep "uuid\|name-description" | cut -d':' -f2 | sed 's/^ //' | paste - -)"
IFS=$'\n' read -r -d '' -a storages <<<"$(xe sr-list content-type=user | grep "uuid\|name-description" | cut -d':' -f2 | sed 's/^ //' | paste - -)"
# bail out if no storage repositories are found
if [[ ${#storages[@]} -eq 0 ]]; then
@@ -76,10 +74,9 @@ function StorageChoose {
echo "default will attempt to use pool default SR"
echo
local PS3="Pick a number. CTRL+C to exit: "
select storage in "${storages[@]}" "default"
do
select storage in "${storages[@]}" "default"; do
# get only the storage repository uuid which we need later on when importing image
read -r -a storage_split <<< "$storage"
read -r -a storage_split <<<"$storage"
storageuuid=${storage_split[0]}
# print a menu where to choose storage from
@@ -195,7 +192,7 @@ function VMImport {
echo "Waiting for VM to start and announce it got IP-address"
sleep 30
ip=$(xe vm-param-get uuid="$uuid" param-name=networks param-key=0/ip 2>/dev/null)
(( count++ ))
((count++))
done
# network details are needed in xenstore only during first startup so remove them at this point since VM should be running