diff --git a/install.sh b/install.sh index e42588d..7ddf176 100644 --- a/install.sh +++ b/install.sh @@ -10,6 +10,15 @@ if [ "$(id -u)" != "0" ]; then fi fi -wget https://raw.githubusercontent.com/retspen/webvirtcloud/master/webvirtcloud.sh -chmod 744 webvirtcloud.sh -./webvirtcloud.sh 2>&1 | tee -a /var/log/webvirtcloud-install.log \ No newline at end of file +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +if [ -f "$SCRIPT_DIR/webvirtcloud.sh" ]; then + INSTALLER="$SCRIPT_DIR/webvirtcloud.sh" +elif [ -f "./webvirtcloud.sh" ]; then + INSTALLER="./webvirtcloud.sh" +else + INSTALLER="./webvirtcloud.sh" + wget -O "$INSTALLER" "${WEBVIRTCLOUD_SCRIPT_URL:-https://raw.githubusercontent.com/catborise/webvirtcloud/master/webvirtcloud.sh}" +fi + +chmod 744 "$INSTALLER" +"$INSTALLER" "$@" 2>&1 | tee -a /var/log/webvirtcloud-install.log \ No newline at end of file diff --git a/webvirtcloud.sh b/webvirtcloud.sh index dbcae12..9317ee9 100755 --- a/webvirtcloud.sh +++ b/webvirtcloud.sh @@ -67,7 +67,7 @@ fi clear readonly APP_USER="wvcuser" -readonly APP_REPO_URL="https://github.com/retspen/webvirtcloud.git" +readonly APP_REPO_URL="${APP_REPO_URL:-https://github.com/catborise/webvirtcloud.git}" readonly APP_NAME="webvirtcloud" readonly APP_PATH="/srv/$APP_NAME" @@ -97,6 +97,18 @@ log () { fi } +get_timezone () { + if [ -f /etc/timezone ]; then + cat /etc/timezone + elif command -v timedatectl >/dev/null 2>&1 && timedatectl 2>/dev/null | grep -q "Time zone"; then + timedatectl | grep "Time zone" | awk '{print $3}' + elif [ -L /etc/localtime ]; then + readlink /etc/localtime | sed -n 's#.*/zoneinfo/##p' + else + echo "UTC" + fi +} + install_packages () { case $distro in ubuntu|debian) @@ -236,23 +248,21 @@ check_python () { activate_python_environment () { cd "$APP_PATH" || exit - # Check if virtualenv is installed - if ! "$PYTHON" -c 'import virtualenv' >/dev/null 2>&1; then - echo "Virtualenv is not installed. Please install virtualenv and try again." + echo "* Creating virtual environment in $APP_PATH/venv" + if "$PYTHON" -m venv --help >/dev/null 2>&1; then + "$PYTHON" -m venv --system-site-packages venv + elif command -v virtualenv >/dev/null 2>&1; then + virtualenv -p "$PYTHON" --system-site-packages venv + else + echo "Neither python3 -m venv nor virtualenv is installed. Please install python3-venv or virtualenv." exit 1 fi - # Create a virtual environment - echo "* Creating virtual environment in $APP_PATH/venv" - virtualenv -p "$PYTHON" --system-site-packages venv # shellcheck disable=SC1091 source venv/bin/activate } generate_secret_key() { - "$PYTHON" - </dev/null 2>&1; then + distro="$(lsb_release -is)" + version="$(lsb_release -rs)" + codename="$(lsb_release -cs)" + elif [ -f /etc/debian_version ]; then + distro="debian" + version="$(cat /etc/debian_version)" + codename="" + fi elif [ -f /etc/centos-release ]; then distro="centos" version="8" @@ -395,7 +402,7 @@ case $distro in distro=ubuntu nginx_group=www-data nginxfile=/etc/nginx/conf.d/$APP_NAME.conf - supervisor_service=supervisord + supervisor_service=supervisor supervisor_conf_path=/etc/supervisor/conf.d supervisor_file_name=webvirtcloud.conf ;; @@ -510,16 +517,17 @@ echo "distro: ${distro}" echo "=========" case $distro in debian) - if [[ "$version" -ge 9 ]]; then - # Install for Debian 9.x / 10.x / 12.x - tzone=\'$(cat /etc/timezone)\' + debian_major="${version%%.*}" + if [[ -n "$debian_major" && "$debian_major" -ge 9 ]]; then + # Install for Debian 9.x / 10.x / 11.x / 12.x + tzone=\'$(get_timezone)\' echo -n "* Updating installed packages." log "apt-get update && apt-get -y upgrade" & pid=$! progress echo "* Installing OS requirements." - PACKAGES="git virtualenv python3-virtualenv python3-pip python3-dev python3-lxml libvirt-dev zlib1g-dev libxslt1-dev libsasl2-dev libldap2-dev nginx smbios-utils libsasl2-modules gcc pkg-config python3-guestfs uuid" + PACKAGES="git python3-venv python3-virtualenv python3-pip python3-dev python3-lxml libvirt-dev zlib1g-dev libxslt1-dev libsasl2-dev libldap2-dev nginx supervisor smbios-utils libsasl2-modules gcc pkg-config python3-guestfs uuid" install_packages @@ -531,24 +539,26 @@ case $distro in configure_nginx echo "* Configuring Supervisor." - log "pip install supervisor " configure_supervisor restart_supervisor restart_nginx + else + echo "Unsupported Debian version. Version found: $version" + exit 1 fi ;; ubuntu) - if [ "$version" == "18.04" ] || [ "$version" == "20.04" ] || [ "$version" == "22.04" ] || [ "$version" == "24.04" ]; then + if [[ "$version" =~ ^(18|20|22|24) ]]; then # Install for Ubuntu 18 / 20 / 22 / 24 - tzone=\'$(cat /etc/timezone)\' + tzone=\'$(get_timezone)\' echo -n "* Updating installed packages." log "apt-get update && apt-get -y upgrade" & pid=$! progress echo "* Installing OS requirements." - PACKAGES="git virtualenv python3-virtualenv python3-pip python3-dev python3-lxml libvirt-dev zlib1g-dev libxslt1-dev libsasl2-dev libldap2-dev nginx libsasl2-modules gcc pkg-config python3-guestfs" + PACKAGES="git python3-venv python3-virtualenv python3-pip python3-dev python3-lxml libvirt-dev zlib1g-dev libxslt1-dev libsasl2-dev libldap2-dev nginx supervisor libsasl2-modules gcc pkg-config python3-guestfs" install_packages set_hosts @@ -559,12 +569,13 @@ case $distro in configure_nginx echo "* Configuring Supervisor." - log "pip install supervisor " configure_supervisor restart_supervisor restart_nginx - + else + echo "Unsupported Ubuntu version. Version found: $version" + exit 1 fi ;; centos) @@ -680,7 +691,9 @@ echo " ***Open http://$fqdn to login to webvirtcloud.***" echo "" echo "" echo "* Cleaning up..." -rm -f webvirtcloud.sh -rm -f install.sh +if [ ! -d .git ]; then + rm -f webvirtcloud.sh + rm -f install.sh +fi echo "* Finished!" sleep 1