handle output information in functions rather than individual echo's

This commit is contained in:
ronivay
2020-05-31 12:03:04 +03:00
parent c1042e8950
commit 8a1bbd53e1

View File

@@ -61,7 +61,8 @@ fi
# create logpath if doesn't exist
if [[ ! -d $LOGPATH ]]; then
mkdir -p $LOGPATH
cmdlog "mkdir -p $LOGPATH"
mkdir -p $LOGPATH >> $LOGFILE 2>&1
fi
function CheckUser {
@@ -69,7 +70,7 @@ function CheckUser {
# Make sure the script is ran as root
if [[ ! "$(id -u)" == "0" ]]; then
echo -e "${FAIL} This script needs to be ran as root"
printfail "This script needs to be ran as root"
exit 0
fi
@@ -80,14 +81,30 @@ function cmdlog {
echo >> $LOGFILE
}
function printprog {
echo -ne "${PROGRESS} $@"
}
function printok {
echo -e "\r${OK} $@"
}
function printfail {
echo -e "${FAIL} $@"
}
function printinfo {
echo -e "${INFO} $@"
}
function ErrorHandling {
echo
echo -e "${FAIL} Something went wrong, exiting. Check $LOGFILE for more details and use rollback feature if needed"
printfail "Something went wrong, exiting. Check $LOGFILE for more details and use rollback feature if needed"
if [[ -d $INSTALLDIR/xo-builds/xen-orchestra-$TIME ]]; then
echo
echo -e "${FAIL} Removing $INSTALLDIR/xo-builds/xen-orchestra-$TIME because of failed installation."
prinfail "Removing $INSTALLDIR/xo-builds/xen-orchestra-$TIME because of failed installation."
cmdlog "rm -rf $INSTALLDIR/xo-builds/xen-orchestra-$TIME"
rm -rf $INSTALLDIR/xo-builds/xen-orchestra-$TIME >> $LOGFILE 2>&1
fi
@@ -110,47 +127,47 @@ function InstallDependenciesCentOS {
# install packages
echo
echo -ne "${PROGRESS} Installing build dependencies, redis server, python, git, nfs-utils, cifs-utils"
printprog "Installing build dependencies, redis server, python, git, nfs-utils, cifs-utils"
cmdlog "yum -y install gcc gcc-c++ make openssl-devel redis libpng-devel $PYTHON git nfs-utils cifs-utils lvm2"
yum -y install gcc gcc-c++ make openssl-devel redis libpng-devel $PYTHON git nfs-utils cifs-utils lvm2 >>$LOGFILE 2>&1
echo -e "\r${OK} Installing build dependencies, redis server, python, git, nfs-utils, cifs-utils"
printok "Installing build dependencies, redis server, python, git, nfs-utils, cifs-utils"
# only run automated node install if executable not found
cmdlog "which node"
if [[ -z $(which node 2>>$LOGFILE) ]]; then
echo
echo -ne "${PROGRESS} Installing node.js"
printprog "Installing node.js"
cmdlog "curl -s -L https://rpm.nodesource.com/setup_12.x | bash -"
curl -s -L https://rpm.nodesource.com/setup_12.x | bash - >>$LOGFILE 2>&1
echo -e "\r${OK} Installing node.js"
printok "Installing node.js"
fi
# only install yarn repo and package if not found
cmdlog "which yarn"
if [[ -z $(which yarn 2>>$LOGFILE) ]] ; then
echo
echo -ne "${PROGRESS} Installing yarn"
printprog "Installing yarn"
cmdlog "curl -s -o /etc/yum.repos.d/yarn.repo https://dl.yarnpkg.com/rpm/yarn.repo && yum -y install yarn"
curl -s -o /etc/yum.repos.d/yarn.repo https://dl.yarnpkg.com/rpm/yarn.repo >>$LOGFILE 2>&1 && \
yum -y install yarn >>$LOGFILE 2>&1
echo -e "\r${OK} Installing yarn"
printok "Installing yarn"
fi
# only install epel-release if doesn't exist
cmdlog "rpm -q epel-release"
if [[ -z $(rpm -q epel-release 2>>$LOGFILE) ]] ; then
echo
echo -ne "${PROGRESS} Installing epel-repo"
printprog "Installing epel-repo"
cmdlog "yum -y install epel-release"
yum -y install epel-release >>$LOGFILE 2>&1
echo -e "\r${OK} Installing epel-repo"
printok "Installing epel-repo"
fi
# only install libvhdi-tools if vhdimount is not present
cmdlog "which vhdimount"
if [[ -z $(which vhdimount 2>>$LOGFILE) ]] ; then
echo
echo -ne "${PROGRESS} Installing libvhdi-tools from forensics repository"
printprog "Installing libvhdi-tools from forensics repository"
if [[ $OSVERSION == "7" ]]; then
cmdlog "rpm -ivh https://forensics.cert.org/cert-forensics-tools-release-el7.rpm"
rpm -ivh https://forensics.cert.org/cert-forensics-tools-release-el7.rpm >>$LOGFILE 2>&1
@@ -163,20 +180,20 @@ function InstallDependenciesCentOS {
sed -i 's/enabled=1/enabled=0/g' /etc/yum.repos.d/cert-forensics-tools.repo >>$LOGFILE 2>&1
cmdlog "yum --enablerepo=forensics install -y libvhdi-tools"
yum --enablerepo=forensics install -y libvhdi-tools >>$LOGFILE 2>&1
echo -e "\r${OK} Installing libvhdi-tools from forensics repository"
printok "Installing libvhdi-tools from forensics repository"
fi
echo
echo -ne "${PROGRESS} Enabling and starting redis service"
printprog "Enabling and starting redis service"
cmdlog "/bin/systemctl enable redis && /bin/systemctl start redis"
/bin/systemctl enable redis >>$LOGFILE 2>&1 && /bin/systemctl start redis >>$LOGFILE 2>&1
echo -e "\r${OK} Enabling and starting redis service"
printok "Enabling and starting redis service"
echo
echo -ne "${PROGRESS} Enabling and starting rpcbind service"
printprog "Enabling and starting rpcbind service"
cmdlog "/bin/systemctl enable rpcbind && /bin/systemctl start rpcbind"
/bin/systemctl enable rpcbind >>$LOGFILE 2>&1 && /bin/systemctl start rpcbind >>$LOGFILE 2>&1
echo -e "\r${OK} Enabling and starting rpcbind service"
printok "Enabling and starting rpcbind service"
}
@@ -189,18 +206,18 @@ function InstallDependenciesDebian {
# Install necessary dependencies for XO build
if [[ $OSVERSION =~ (16|18|20) ]]; then
echo -ne "${PROGRESS} OS Ubuntu so making sure universe repository is enabled"
printprog "OS Ubuntu so making sure universe repository is enabled"
cmdlog "add-apt-repository universe"
add-apt-repository universe >>$LOGFILE 2>&1
echo -e "\r${OK} OS Ubuntu so making sure universe repository is enabled"
printok "OS Ubuntu so making sure universe repository is enabled"
echo
fi
echo
echo -ne "${PROGRESS} Running apt-get update"
printprog "Running apt-get update"
cmdlog "apt-get update"
apt-get update >>$LOGFILE 2>&1
echo -e "\r${OK} Running apt-get update"
printok "Running apt-get update"
#determine which python package is needed. Ubuntu 20 requires python2-minimal, 16 and 18 are python-minimal
if [[ $OSVERSION == "20" ]]; then
@@ -211,41 +228,41 @@ function InstallDependenciesDebian {
# install packages
echo
echo -ne "${PROGRESS} Installing build dependencies, redis server, git, libvhdi-utils, python-minimal, lvm2, nfs-common, cifs-utils, curl"
printprog "Installing build dependencies, redis server, git, libvhdi-utils, python-minimal, lvm2, nfs-common, cifs-utils, curl"
cmdlog "apt-get install -y build-essential redis-server libpng-dev git libvhdi-utils $PYTHON lvm2 nfs-common cifs-utils curl"
apt-get install -y build-essential redis-server libpng-dev git libvhdi-utils $PYTHON lvm2 nfs-common cifs-utils curl >>$LOGFILE 2>&1
echo -e "\r${OK} Installing build dependencies, redis server, python, git, libvhdi-utils, lvm2, nfs-common, cifs-utils, curl"
printok "Installing build dependencies, redis server, python, git, libvhdi-utils, lvm2, nfs-common, cifs-utils, curl"
# Install apt-transport-https and ca-certificates because of yarn https repo url
echo
echo -ne "${PROGRESS} Installing apt-transport-https and ca-certificates packages to support https repos"
printprog "Installing apt-transport-https and ca-certificates packages to support https repos"
cmdlog "apt-get install -y apt-transport-https ca-certificates"
apt-get install -y apt-transport-https ca-certificates >>$LOGFILE 2>&1
echo -e "\r${OK} Installing apt-transport-https and ca-certificates packages to support https repos"
printok "Installing apt-transport-https and ca-certificates packages to support https repos"
if [[ $OSVERSION == "10" ]]; then
echo
echo -ne "${PROGRESS} Debian 10, so installing gnupg also"
printprog "Debian 10, so installing gnupg also"
cmdlog "apt-get install gnupg -y"
apt-get install gnupg -y >>$LOGFILE 2>&1
echo -e "\r${OK} Debian 10, so installing gnupg also"
printok "Debian 10, so installing gnupg also"
fi
# install setcap for non-root port binding if missing
cmdlog "which setcap"
if [[ -z $(which setcap 2>>$LOGFILE) ]]; then
echo
echo -ne "${PROGRESS} Installing setcap"
printprog "Installing setcap"
cmdlog "apt-get install -y libcap2-bin"
apt-get install -y libcap2-bin >>$LOGFILE 2>&1
echo -e "\r${OK} Installing setcap"
printok "Installing setcap"
fi
# only install yarn repo and package if not found
cmdlog "which yarn"
if [[ -z $(which yarn 2>>$LOGFILE) ]]; then
echo
echo -ne "${PROGRESS} Installing yarn"
printprog "Installing yarn"
cmdlog "curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -"
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - >>$LOGFILE 2>&1
cmdlog "echo \"deb https://dl.yarnpkg.com/debian/ stable main\" | tee /etc/apt/sources.list.d/yarn.list"
@@ -254,7 +271,7 @@ function InstallDependenciesDebian {
apt-get update >>$LOGFILE 2>&1
cmdlog "apt-get install -y yarn"
apt-get install -y yarn >>$LOGFILE 2>&1
echo -e "\r${OK} Installing yarn"
printok "Installing yarn"
fi
@@ -263,12 +280,12 @@ function InstallDependenciesDebian {
cmdlog "which npm"
if [[ -z $(which node 2>>$LOGFILE) ]] || [[ -z $(which npm 2>>$LOGFILE) ]]; then
echo
echo -ne "${PROGRESS} Installing node.js"
printprog "Installing node.js"
cmdlog "curl -sL https://deb.nodesource.com/setup_12.x | bash -"
curl -sL https://deb.nodesource.com/setup_12.x | bash - >>$LOGFILE 2>&1
cmdlog "apt-get install -y nodejs"
apt-get install -y nodejs >>$LOGFILE 2>&1
echo -e "\r${OK} Installing node.js"
printok "Installing node.js"
fi
# if we run Debian 10 and have default nodejs v10 installed, then replace it with node 12.x
@@ -276,26 +293,26 @@ function InstallDependenciesDebian {
NODEV=$(node -v 2>/dev/null| grep -Eo '[0-9.]+' | cut -d'.' -f1)
if [[ -n $NODEV ]] && [[ $NODEV < 12 ]]; then
echo
echo -ne "${PROGRESS} Installing node.js"
printprog "Installing node.js"
cmdlog "curl -sL https://deb.nodesource.com/setup_12.x | bash -"
curl -sL https://deb.nodesource.com/setup_12.x | bash - >>$LOGFILE 2>&1
cmdlog "apt-get install -y nodejs"
apt-get install -y nodejs >>$LOGFILE 2>&1
echo -e "\r${OK} Installing node.js"
printok "Installing node.js"
fi
fi
echo
echo -ne "${PROGRESS} Enabling and starting redis service"
printprog "Enabling and starting redis service"
cmdlog "/bin/systemctl enable redis-server && /bin/systemctl start redis-server"
/bin/systemctl enable redis-server >>$LOGFILE 2>&1 && /bin/systemctl start redis-server >>$LOGFILE 2>&1
echo -e "\r${OK} Enabling and starting redis service"
printok "Enabling and starting redis service"
echo
echo -ne "${PROGRESS} Enabling and starting rpcbind service"
printprog "Enabling and starting rpcbind service"
cmdlog "/bin/systemctl enable rpcbind && /bin/systemctl start rpcbind"
/bin/systemctl enable rpcbind >>$LOGFILE 2>&1 && /bin/systemctl start rpcbind >>$LOGFILE 2>&1
echo -e "\r${OK} Enabling and starting rpcbind service"
printok "Enabling and starting rpcbind service"
}
@@ -305,16 +322,16 @@ function UpdateNodeYarn {
if [ $OSNAME == "CentOS" ]; then
echo
echo -ne "${PROGRESS} Checking updates for nodejs and yarn"
printprog "Checking updates for nodejs and yarn"
cmdlog "yum update -y nodejs yarn"
yum update -y nodejs yarn >>$LOGFILE 2>&1
echo -e "\r${OK} Checking updates for nodejs and yarn"
printok "Checking updates for nodejs and yarn"
else
echo
echo -ne "${PROGRESS} Checking updates for nodejs and yarn"
printprog "Checking updates for nodejs and yarn"
cmdlog "apt-get install -y --only-upgrade nodejs yarn"
apt-get install -y --only-upgrade nodejs yarn >>$LOGFILE 2>&1
echo -e "\r${OK} Checking updates for nodejs and yarn"
printok "Checking updates for nodejs and yarn"
fi
fi
@@ -330,12 +347,12 @@ function InstallXOPlugins {
if [[ "$PLUGINS" == "all" ]]; then
echo
echo -ne "${PROGRESS} Installing plugins"
printprog "Installing plugins"
cmdlog "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/\""
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
echo
echo -ne "${PROGRESS} Installing plugins"
printprog "Installing plugins"
local PLUGINSARRAY=($(echo "$PLUGINS" | tr ',' ' '))
for x in "${PLUGINSARRAY[@]}"; do
if [[ $(find $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages -type d -name "$x") ]]; then
@@ -347,10 +364,10 @@ function InstallXOPlugins {
cmdlog "cd $INSTALLDIR/xo-builds/xen-orchestra-$TIME && yarn >/dev/null && yarn build"
cd $INSTALLDIR/xo-builds/xen-orchestra-$TIME && yarn >/dev/null && yarn build >>$LOGFILE 2>&1
echo -e "\r${OK} Installing plugins"
printok "Installing plugins"
else
echo
echo -e "${INFO} No plugins to install"
printinfo "No plugins to install"
fi
}
@@ -366,10 +383,10 @@ function InstallXO {
if [[ "$XOUSER" != "root" ]]; then
if [[ -z $(getent passwd $XOUSER) ]]; then
echo
echo -ne "${PROGRESS} Creating missing $XOUSER user"
printprog "Creating missing $XOUSER user"
cmdlog "useradd -s /sbin/nologin $XOUSER"
useradd -s /sbin/nologin $XOUSER >>$LOGFILE 2>&1
echo -e "\r${OK} Creating missing $XOUSER user"
printok "Creating missing $XOUSER user"
sleep 2
fi
fi
@@ -377,23 +394,23 @@ function InstallXO {
# Create installation directory if doesn't exist already
if [[ ! -d "$INSTALLDIR" ]] ; then
echo
echo -ne "${PROGRESS} Creating missing basedir to $INSTALLDIR"
printprog "Creating missing basedir to $INSTALLDIR"
cmdlog "mkdir -p \"$INSTALLDIR\""
mkdir -p "$INSTALLDIR"
echo -e "\r${OK} Creating missing basedir to $INSTALLDIR"
printok "Creating missing basedir to $INSTALLDIR"
fi
# Create missing xo-builds directory if doesn't exist already
if [[ ! -d "$INSTALLDIR/xo-builds" ]]; then
echo
echo -ne "${PROGRESS} Creating missing xo-builds directory to $INSTALLDIR/xo-builds"
printprog "Creating missing xo-builds directory to $INSTALLDIR/xo-builds"
cmdlog "mkdir \"$INSTALLDIR/xo-builds\""
mkdir "$INSTALLDIR/xo-builds"
echo -e "\r${OK} Creating missing xo-builds directory to $INSTALLDIR/xo-builds"
printok "Creating missing xo-builds directory to $INSTALLDIR/xo-builds"
fi
echo
echo -e "${INFO} Fetching Xen Orchestra source code"
printinfo "Fetching Xen Orchestra source code"
if [[ ! -d "$XO_SRC_DIR" ]]; then
cmdlog "mkdir -p \"$XO_SRC_DIR\""
mkdir -p "$XO_SRC_DIR"
@@ -410,7 +427,7 @@ function InstallXO {
# Deploy the latest xen-orchestra source to the new install directory.
echo
echo -ne "${INFO} Creating install directory: $INSTALLDIR/xo-builds/xen-orchestra-$TIME"
printinfo "Creating install directory: $INSTALLDIR/xo-builds/xen-orchestra-$TIME"
cmdlog "rm -rf \"$INSTALLDIR/xo-builds/xen-orchestra-$TIME\""
rm -rf "$INSTALLDIR/xo-builds/xen-orchestra-$TIME" >>$LOGFILE 2>&1
cmdlog "cp -r \"$XO_SRC_DIR" "$INSTALLDIR/xo-builds/xen-orchestra-$TIME\""
@@ -422,7 +439,7 @@ function InstallXO {
TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
echo
echo -e "${INFO} Checking out latest tagged release '$TAG'"
printinfo "Checking out latest tagged release '$TAG'"
cmdlog "git checkout $TAG"
git checkout $TAG >>$LOGFILE 2>&1
@@ -430,7 +447,7 @@ function InstallXO {
cd $(dirname $0)
elif [[ "$BRANCH" != "master" ]]; then
echo
echo -e "${INFO} Checking out source code from branch '$BRANCH'"
printinfo "Checking out source code from branch '$BRANCH'"
cmdlog "cd $INSTALLDIR/xo-builds/xen-orchestra-$TIME"
cd $INSTALLDIR/xo-builds/xen-orchestra-$TIME >>$LOGFILE 2>&1
@@ -475,8 +492,8 @@ function InstallXO {
# proceed with the build.
if [[ "$NEW_REPO_HASH" == "$OLD_REPO_HASH" ]]; then
echo
echo -e "${INFO} No changes to xen-orchestra since previous install. Skipping xo-server and xo-web build."
echo -e "${INFO} Cleaning up install directory: $INSTALLDIR/xo-builds/xen-orchestra-$TIME"
printinfo "No changes to xen-orchestra since previous install. Skipping xo-server and xo-web build."
printinfo "Cleaning up install directory: $INSTALLDIR/xo-builds/xen-orchestra-$TIME"
cmdlog "rm -rf $INSTALLDIR/xo-builds/xen-orchestra-$TIME"
rm -rf $INSTALLDIR/xo-builds/xen-orchestra-$TIME >>$LOGFILE 2>&1
return 0
@@ -486,40 +503,40 @@ function InstallXO {
# sure there's no already-running xo-server process.
if [[ $(pgrep -f xo-server) ]]; then
echo
echo -ne "${PROGRESS} Shutting down xo-server"
printprog "Shutting down xo-server"
cmdlog "/bin/systemctl stop xo-server"
/bin/systemctl stop xo-server || { echo -e "${FAIL} failed to stop service, exiting..." ; exit 1; }
echo -e "\r${OK} Shutting down xo-server"
/bin/systemctl stop xo-server || { printfail "failed to stop service, exiting..." ; exit 1; }
printok "Shutting down xo-server"
fi
# If this isn't a fresh install, then list the upgrade the user is making.
if [[ -n "$OLD_REPO_HASH" ]]; then
echo
echo -e "${INFO} Updating xen-orchestra from '$OLD_REPO_HASH_SHORT' to '$NEW_REPO_HASH_SHORT'"
printinfo "Updating xen-orchestra from '$OLD_REPO_HASH_SHORT' to '$NEW_REPO_HASH_SHORT'"
fi
echo
echo
echo -e "${INFO} xo-server and xo-web build quite a while. Grab a cup of coffee and lay back"
printinfo "xo-server and xo-web build quite a while. Grab a cup of coffee and lay back"
echo
echo -ne "${PROGRESS} Running installation"
printprog "Running installation"
cmdlog "cd $INSTALLDIR/xo-builds/xen-orchestra-$TIME && yarn && yarn build"
cd $INSTALLDIR/xo-builds/xen-orchestra-$TIME >>$LOGFILE 2>&1 && yarn >>$LOGFILE 2>&1 && yarn build >>$LOGFILE 2>&1
echo -e "\r${OK} Running installation"
printok "Running installation"
# Install plugins
InstallXOPlugins
echo
echo -e "${INFO} Fixing binary path in systemd service configuration file"
printinfo "Fixing binary path in systemd service configuration file"
cmdlog "sed -i \"s#ExecStart=.*#ExecStart=$INSTALLDIR\/xo-server\/bin\/xo-server#\" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/xo-server.service"
sed -i "s#ExecStart=.*#ExecStart=$INSTALLDIR\/xo-server\/bin\/xo-server#" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/xo-server.service
echo -e "${INFO} Adding WorkingDirectory parameter to systemd service configuration file"
printinfo "Adding WorkingDirectory parameter to systemd service configuration file"
cmdlog "sed -i \"/ExecStart=.*/a WorkingDirectory=$INSTALLDIR/xo-server\" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/xo-server.service"
sed -i "/ExecStart=.*/a WorkingDirectory=$INSTALLDIR/xo-server" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/xo-server.service >>$LOGFILE 2>&1
if [[ "$XOUSER" != "root" ]]; then
echo -e "${INFO} Adding user to systemd config"
printinfo "Adding user to systemd config"
cmdlog "sed -i \"/SyslogIdentifier=.*/a User=$XOUSER\" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/xo-server.service"
sed -i "/SyslogIdentifier=.*/a User=$XOUSER" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/xo-server.service >>$LOGFILE 2>&1
@@ -530,19 +547,19 @@ function InstallXO {
fi
if [[ -n $NODEBINARY ]]; then
echo -ne "${PROGRESS} Attempting to set cap_net_bind_service permission for $NODEBINARY"
printprog "Attempting to set cap_net_bind_service permission for $NODEBINARY"
cmdlog "setcap 'cap_net_bind_service=+ep' $NODEBINARY"
setcap 'cap_net_bind_service=+ep' $NODEBINARY >>$LOGFILE 2>&1 \
&& echo -e "\r${OK} Attempting to set cap_net_bind_service permission for $NODEBINARY" || { echo -e "\r${FAIL} 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" ; }
&& 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
echo -e "${FAIL} 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"
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
fi
fi
if [[ ! -f $CONFIGPATH/.config/xo-server/config.toml ]] || [[ "$CONFIGUPDATE" == "true" ]]; then
echo -e ${INFO} "Fixing relative path to xo-web installation in xo-server configuration file"
printinfo "Fixing relative path to xo-web installation in xo-server configuration file"
INSTALLDIRESC=$(echo $INSTALLDIR | sed 's/\//\\\//g')
cmdlog "sed -i \"s/#'\/any\/url' = '\/path\/to\/directory'/'\/' = '$INSTALLDIRESC\/xo-web\/dist\/'/\" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.toml"
@@ -550,14 +567,14 @@ function InstallXO {
sleep 2
if [[ $PORT != "80" ]]; then
echo -e "${INFO} Changing port in xo-server configuration file"
printinfo "Changing port in xo-server configuration file"
cmdlog "sed -i \"s/port = 80/port = $PORT/\" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.toml"
sed -i "s/port = 80/port = $PORT/" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.toml >>$LOGFILE 2>&1
sleep 2
fi
if [[ "$HTTPS" == "true" ]] ; then
echo -e "${INFO} Enabling HTTPS in xo-server configuration file"
printinfo "Enabling HTTPS in xo-server configuration file"
cmdlog "sed -i \"s%# cert = '.\/certificate.pem'%cert = '$PATH_TO_HTTPS_CERT'%\" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.toml"
sed -i "s%# cert = '.\/certificate.pem'%cert = '$PATH_TO_HTTPS_CERT'%" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.toml >>$LOGFILE 2>&1
cmdlog \"sed -i "s%# key = '.\/key.pem'%key = '$PATH_TO_HTTPS_KEY'%\" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.toml"
@@ -567,7 +584,7 @@ function InstallXO {
sleep 2
fi
echo -e "${INFO} Activating modified configuration file"
printinfo "Activating modified configuration file"
cmdlog "mkdir -p $CONFIGPATH/.config/xo-server"
mkdir -p $CONFIGPATH/.config/xo-server
cmdlog "mv -f $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.toml $CONFIGPATH/.config/xo-server/config.toml"
@@ -577,11 +594,11 @@ function InstallXO {
fi
echo
echo -e "${INFO} Symlinking fresh xo-server install/update to $INSTALLDIR/xo-server"
printinfo "Symlinking fresh xo-server install/update to $INSTALLDIR/xo-server"
cmdlog "ln -sfn $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server $INSTALLDIR/xo-server"
ln -sfn $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server $INSTALLDIR/xo-server >>$LOGFILE 2>&1
sleep 2
echo -e "${INFO} Symlinking fresh xo-web install/update to $INSTALLDIR/xo-web"
printinfo "Symlinking fresh xo-web install/update to $INSTALLDIR/xo-web"
cmdlog "ln -sfn $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-web $INSTALLDIR/xo-web"
ln -sfn $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-web $INSTALLDIR/xo-web >>$LOGFILE 2>&1
@@ -608,19 +625,19 @@ function InstallXO {
fi
echo
echo -e "${INFO} Replacing systemd service configuration file"
printinfo "Replacing systemd service configuration file"
cmdlog "/bin/cp -f $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/xo-server.service /etc/systemd/system/xo-server.service"
/bin/cp -f $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/xo-server.service /etc/systemd/system/xo-server.service >>$LOGFILE 2>&1
sleep 2
echo -e "${INFO} Reloading systemd configuration"
printinfo "Reloading systemd configuration"
echo
cmdlog "/bin/systemctl daemon-reload"
/bin/systemctl daemon-reload >>$LOGFILE 2>&1
sleep 2
echo
echo -e "${INFO} Starting xo-server..."
printinfo "Starting xo-server..."
cmdlog "/bin/systemctl start xo-server"
/bin/systemctl start xo-server >>$LOGFILE 2>&1
@@ -640,12 +657,13 @@ function InstallXO {
echo -e " ${COLOR_GREEN}WebUI started in port $PORT. Make sure you have firewall rules in place to allow access.${COLOR_N}"
echo -e " ${COLOR_GREEN}Default username: admin@admin.net password: admin${COLOR_N}"
echo
echo -e "${INFO} Installation successful. Enabling xo-server to start on reboot"
printinfo "Installation successful. Enabling xo-server to start on reboot"
cmdlog "/bin/systemctl enable xo-server"
echo
/bin/systemctl enable xo-server >>$LOGFILE 2>&1
else
echo
echo -e "${FAIL} Looks like there was a problem when starting xo-server/reading journalctl. Please see logs for more details"
printfail "Looks like there was a problem when starting xo-server/reading journalctl. Please see logs for more details"
journalctl -u xo-server -n 50 >> $LOGFILE
exit 1
fi
@@ -661,12 +679,12 @@ function UpdateXO {
# remove old builds. leave as many as defined in PRESERVE variable
echo
echo -ne "${PROGRESS} Removing old installations. Leaving $PRESERVE latest"
printprog "Removing old installations. Leaving $PRESERVE latest"
cmdlog "find $INSTALLDIR/xo-builds/ -maxdepth 1 -type d -name \"xen-orchestra*\" -printf \"%T@ %p\\n\" | sort -n | cut -d' ' -f2- | head -n -$PRESERVE | xargs -r rm -r"
find $INSTALLDIR/xo-builds/ -maxdepth 1 -type d -name "xen-orchestra*" -printf "%T@ %p\n" | sort -n | cut -d' ' -f2- | head -n -$PRESERVE | xargs -r rm -r >>$LOGFILE 2>&1
echo -e "\r${OK} Removing old installations. Leaving $PRESERVE latest"
printok "Removing old installations. Leaving $PRESERVE latest"
else
echo -e "${INFO} PRESERVE variable is set to 0. This needs to be at least 1. Not doing a cleanup"
printinfo "PRESERVE variable is set to 0. This needs to be at least 1. Not doing a cleanup"
fi
}
@@ -709,7 +727,7 @@ function RollBackInstallation {
INSTALLATIONS=($(find $INSTALLDIR/xo-builds/ -maxdepth 1 -type d -name "xen-orchestra-*" 2>/dev/null))
if [[ $(echo ${#INSTALLATIONS[@]}) -le 1 ]]; then
echo -e "${INFO} One or less installations exist, nothing to change"
printinfo "One or less installations exist, nothing to change"
exit 0
fi
@@ -720,27 +738,27 @@ function RollBackInstallation {
case $INSTALLATION in
*xen-orchestra*)
echo
echo -e "${INFO} Setting $INSTALLDIR/xo-server symlink to $INSTALLATION/packages/xo-server"
printinfo "Setting $INSTALLDIR/xo-server symlink to $INSTALLATION/packages/xo-server"
cmdlog "ln -sfn $INSTALLATION/packages/xo-server $INSTALLDIR/xo-server"
ln -sfn $INSTALLATION/packages/xo-server $INSTALLDIR/xo-server >>$LOGFILE 2>&1
echo -e "${INFO} Setting $INSTALLDIR/xo-web symlink to $INSTALLATION/packages/xo-web"
printinfo "Setting $INSTALLDIR/xo-web symlink to $INSTALLATION/packages/xo-web"
cmdlog "ln -sfn $INSTALLATION/packages/xo-web $INSTALLDIR/xo-web"
ln -sfn $INSTALLATION/packages/xo-web $INSTALLDIR/xo-web >>$LOGFILE 2>&1
echo
echo -e "${INFO} Replacing xo.server.service systemd configuration file"
printinfo "Replacing xo.server.service systemd configuration file"
cmdlog "/bin/cp -f $INSTALLATION/packages/xo-server/xo-server.service /etc/systemd/system/xo-server.service"
/bin/cp -f $INSTALLATION/packages/xo-server/xo-server.service /etc/systemd/system/xo-server.service >>$LOGFILE 2>&1
cmdlog "/bin/systemctl daemon-reload"
/bin/systemctl daemon-reload >>$LOGFILE 2>&1
echo
echo -e "${INFO} Restarting xo-server..."
printinfo "Restarting xo-server..."
cmdlog "/bin/systemctl restart xo-server"
/bin/systemctl restart xo-server >>$LOGFILE 2>&1
echo
break
;;
*)
echo -e "${FAIL} Try again"
printfail "Try again"
;;
esac
done
@@ -753,21 +771,21 @@ function CheckOS {
OSVERSION=$(grep -Eo "[0-9]" /etc/centos-release | head -1)
OSNAME="CentOS"
if [[ ! $OSVERSION =~ ^(7|8) ]]; then
echo -e "${FAIL} Only CentOS 7/8 supported"
printfail "Only CentOS 7/8 supported"
exit 0
fi
elif [[ -f /etc/os-release ]]; then
OSVERSION=$(grep ^VERSION_ID /etc/os-release | cut -d'=' -f2 | grep -Eo "[0-9]{1,2}" | head -1)
OSNAME=$(grep ^NAME /etc/os-release | cut -d'=' -f2 | sed 's/"//g' | awk '{print $1}')
if [[ $OSNAME == "Debian" ]] && [[ ! $OSVERSION =~ ^(8|9|10)$ ]]; then
echo -e "${FAIL} Only Debian 8/9/10 supported"
printfail "Only Debian 8/9/10 supported"
exit 0
elif [[ $OSNAME == "Ubuntu" ]] && [[ ! $OSVERSION =~ ^(16|18|20)$ ]]; then
echo -e "${FAIL} Only Ubuntu 16/18/20 supported"
printfail "Only Ubuntu 16/18/20 supported"
exit 0
fi
else
echo -e "${FAIL} Only CentOS 7 / Ubuntu 16/18 and Debian 8/9 supported"
printfail "Only CentOS 7 / Ubuntu 16/18 and Debian 8/9 supported"
exit 0
fi
@@ -776,7 +794,7 @@ function CheckOS {
function CheckSystemd {
if [[ -z $(which systemctl) ]]; then
echo -e "${FAIL} This tool is designed to work with systemd enabled systems only"
printfail "This tool is designed to work with systemd enabled systems only"
exit 0
fi
}
@@ -785,7 +803,7 @@ function CheckDocker {
if [[ -z $(which docker) ]]; then
echo
echo -e "${FAIL} Docker needs to be installed for this to work"
printfail "Docker needs to be installed for this to work"
exit 0
fi
@@ -797,12 +815,12 @@ function CheckCertificate {
local KEY="$(openssl rsa -modulus -noout -in "$PATH_TO_HTTPS_KEY" | openssl md5)"
if [[ "$CERT" != "$KEY" ]]; then
echo
echo -e "${INFO} $PATH_TO_HTTPS_CERT:"
echo -e "${INFO} $CERT"
echo -e "${INFO} $PATH_TO_HTTPS_KEY:"
echo -e "${INFO} $KEY"
printinfo "$PATH_TO_HTTPS_CERT:"
printinfo "$CERT"
printinfo "$PATH_TO_HTTPS_KEY:"
printinfo "$KEY"
echo
echo -e "{$FAIL} MD5 of your TLS key and certificate dont match. Please check files and try again."
printfail "MD5 of your TLS key and certificate dont match. Please check files and try again."
exit 1
fi
fi
@@ -826,10 +844,10 @@ function PullDockerImage {
docker pull ronivay/xen-orchestra
echo
echo
echo -e "${INFO} Image pulled. Run container:"
printinfo "Image pulled. Run container:"
echo " docker run -itd -p 80:80 ronivay/xen-orchestra"
echo
echo -e "${INFO} If you want to persist xen-orchestra and redis data, use volume flags like:"
printinfo "If you want to persist xen-orchestra and redis data, use volume flags like:"
echo " docker run -itd -p 80:80 -v /path/to/data/xo-server:/var/lib/xo-server -v /path/to/data/redis:/var/lib/redis ronivay/xen-orchestra"
}
@@ -880,7 +898,7 @@ read -p ": " option
y)
echo "Stopping xo-server..."
cmdlog "/bin/systemctl stop xo-server"
/bin/systemctl stop xo-server >>$LOGFILE 2>&1 || { echo -e "${FAIL} failed to stop service, exiting..." ; exit 1; }
/bin/systemctl stop xo-server >>$LOGFILE 2>&1 || { printfail "failed to stop service, exiting..." ; exit 1; }
;;
n)
exit 0