mirror of
https://github.com/retspen/webvirtcloud
synced 2026-10-18 00:50:07 +00:00
fix(install): modernize Ubuntu and Debian installer script for 24.04 and Debian 12 compatibility
This commit is contained in:
parent
60565b05b3
commit
79c6bd4c62
2 changed files with 68 additions and 46 deletions
15
install.sh
15
install.sh
|
|
@ -10,6 +10,15 @@ if [ "$(id -u)" != "0" ]; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
wget https://raw.githubusercontent.com/retspen/webvirtcloud/master/webvirtcloud.sh
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
chmod 744 webvirtcloud.sh
|
if [ -f "$SCRIPT_DIR/webvirtcloud.sh" ]; then
|
||||||
./webvirtcloud.sh 2>&1 | tee -a /var/log/webvirtcloud-install.log
|
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
|
||||||
|
|
@ -67,7 +67,7 @@ fi
|
||||||
clear
|
clear
|
||||||
|
|
||||||
readonly APP_USER="wvcuser"
|
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_NAME="webvirtcloud"
|
||||||
readonly APP_PATH="/srv/$APP_NAME"
|
readonly APP_PATH="/srv/$APP_NAME"
|
||||||
|
|
||||||
|
|
@ -97,6 +97,18 @@ log () {
|
||||||
fi
|
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 () {
|
install_packages () {
|
||||||
case $distro in
|
case $distro in
|
||||||
ubuntu|debian)
|
ubuntu|debian)
|
||||||
|
|
@ -236,23 +248,21 @@ check_python () {
|
||||||
|
|
||||||
activate_python_environment () {
|
activate_python_environment () {
|
||||||
cd "$APP_PATH" || exit
|
cd "$APP_PATH" || exit
|
||||||
# Check if virtualenv is installed
|
echo "* Creating virtual environment in $APP_PATH/venv"
|
||||||
if ! "$PYTHON" -c 'import virtualenv' >/dev/null 2>&1; then
|
if "$PYTHON" -m venv --help >/dev/null 2>&1; then
|
||||||
echo "Virtualenv is not installed. Please install virtualenv and try again."
|
"$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
|
exit 1
|
||||||
fi
|
fi
|
||||||
# Create a virtual environment
|
|
||||||
echo "* Creating virtual environment in $APP_PATH/venv"
|
|
||||||
virtualenv -p "$PYTHON" --system-site-packages venv
|
|
||||||
# shellcheck disable=SC1091
|
# shellcheck disable=SC1091
|
||||||
source venv/bin/activate
|
source venv/bin/activate
|
||||||
}
|
}
|
||||||
|
|
||||||
generate_secret_key() {
|
generate_secret_key() {
|
||||||
"$PYTHON" - <<END
|
"$PYTHON" -c 'import secrets; print(secrets.token_urlsafe(50))'
|
||||||
import random
|
|
||||||
print(''.join(random.SystemRandom().choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)))
|
|
||||||
END
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -285,7 +295,7 @@ install_webvirtcloud () {
|
||||||
for i in $(hostname -I); do
|
for i in $(hostname -I); do
|
||||||
host_ip+="'http://$i', "
|
host_ip+="'http://$i', "
|
||||||
done
|
done
|
||||||
sed -i "s|^\\(CSRF_TRUSTED_ORIGINS = \\).*|\\1\[ \'http://$fqdn\', $host_ip ]|" /srv/webvirtcloud/webvirtcloud/settings.py
|
sed -i "s|^\\(CSRF_TRUSTED_ORIGINS = \\).*|\\1\[ \'http://$fqdn\', $host_ip ]|" "$APP_PATH/webvirtcloud/settings.py"
|
||||||
|
|
||||||
echo "* Checking up Python3 version."
|
echo "* Checking up Python3 version."
|
||||||
check_python
|
check_python
|
||||||
|
|
@ -297,20 +307,13 @@ install_webvirtcloud () {
|
||||||
pip3 install -U pip
|
pip3 install -U pip
|
||||||
pip3 install -r conf/requirements.txt -q
|
pip3 install -r conf/requirements.txt -q
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
chown -R "$nginx_group":"$nginx_group" "$APP_PATH"
|
chown -R "$nginx_group":"$nginx_group" "$APP_PATH"
|
||||||
|
|
||||||
|
|
||||||
echo "* Django Migrate."
|
echo "* Django Migrate."
|
||||||
log "$PYTHON $APP_PATH/manage.py migrate"
|
log "$PYTHON $APP_PATH/manage.py migrate"
|
||||||
$PYTHON $APP_PATH/manage.py makemigrations
|
|
||||||
$PYTHON $APP_PATH/manage.py migrate
|
|
||||||
|
|
||||||
|
|
||||||
echo "* Django Collect Static"
|
echo "* Django Collect Static"
|
||||||
log "$PYTHON $APP_PATH/manage.py collectstatic --noinput"
|
log "$PYTHON $APP_PATH/manage.py collectstatic --noinput"
|
||||||
$PYTHON $APP_PATH/manage.py collectstatic --noinput
|
|
||||||
|
|
||||||
chown -R "$nginx_group":"$nginx_group" "$APP_PATH"
|
chown -R "$nginx_group":"$nginx_group" "$APP_PATH"
|
||||||
}
|
}
|
||||||
|
|
@ -360,19 +363,23 @@ restart_nginx () {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if [[ -f /etc/lsb-release || -f /etc/debian_version ]]; then
|
if [ -f /etc/os-release ]; then
|
||||||
distro="$(lsb_release -is)"
|
|
||||||
version="$(lsb_release -rs)"
|
|
||||||
codename="$(lsb_release -cs)"
|
|
||||||
elif [ -f /etc/os-release ]; then
|
|
||||||
# shellcheck disable=SC1091
|
# shellcheck disable=SC1091
|
||||||
distro="$(source /etc/os-release && echo "$ID")"
|
distro="$(source /etc/os-release && echo "$ID")"
|
||||||
# shellcheck disable=SC1091
|
# shellcheck disable=SC1091
|
||||||
version="$(source /etc/os-release && echo "$VERSION_ID")"
|
version="$(source /etc/os-release && echo "$VERSION_ID")"
|
||||||
#Order is important here. If /etc/os-release and /etc/centos-release exist, we're on centos 7.
|
# shellcheck disable=SC1091
|
||||||
#If only /etc/centos-release exist, we're on centos6(or earlier). Centos-release is less parsable,
|
codename="$(source /etc/os-release && echo "${VERSION_CODENAME:-$UBUNTU_CODENAME}")"
|
||||||
#so lets assume that it's version 6 (Plus, who would be doing a new install of anything on centos5 at this point..)
|
elif [[ -f /etc/lsb-release || -f /etc/debian_version ]]; then
|
||||||
#/etc/os-release properly detects fedora
|
if command -v lsb_release >/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
|
elif [ -f /etc/centos-release ]; then
|
||||||
distro="centos"
|
distro="centos"
|
||||||
version="8"
|
version="8"
|
||||||
|
|
@ -395,7 +402,7 @@ case $distro in
|
||||||
distro=ubuntu
|
distro=ubuntu
|
||||||
nginx_group=www-data
|
nginx_group=www-data
|
||||||
nginxfile=/etc/nginx/conf.d/$APP_NAME.conf
|
nginxfile=/etc/nginx/conf.d/$APP_NAME.conf
|
||||||
supervisor_service=supervisord
|
supervisor_service=supervisor
|
||||||
supervisor_conf_path=/etc/supervisor/conf.d
|
supervisor_conf_path=/etc/supervisor/conf.d
|
||||||
supervisor_file_name=webvirtcloud.conf
|
supervisor_file_name=webvirtcloud.conf
|
||||||
;;
|
;;
|
||||||
|
|
@ -510,16 +517,17 @@ echo "distro: ${distro}"
|
||||||
echo "========="
|
echo "========="
|
||||||
case $distro in
|
case $distro in
|
||||||
debian)
|
debian)
|
||||||
if [[ "$version" -ge 9 ]]; then
|
debian_major="${version%%.*}"
|
||||||
# Install for Debian 9.x / 10.x / 12.x
|
if [[ -n "$debian_major" && "$debian_major" -ge 9 ]]; then
|
||||||
tzone=\'$(cat /etc/timezone)\'
|
# Install for Debian 9.x / 10.x / 11.x / 12.x
|
||||||
|
tzone=\'$(get_timezone)\'
|
||||||
|
|
||||||
echo -n "* Updating installed packages."
|
echo -n "* Updating installed packages."
|
||||||
log "apt-get update && apt-get -y upgrade" & pid=$!
|
log "apt-get update && apt-get -y upgrade" & pid=$!
|
||||||
progress
|
progress
|
||||||
|
|
||||||
echo "* Installing OS requirements."
|
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
|
install_packages
|
||||||
|
|
||||||
|
|
@ -531,24 +539,26 @@ case $distro in
|
||||||
configure_nginx
|
configure_nginx
|
||||||
|
|
||||||
echo "* Configuring Supervisor."
|
echo "* Configuring Supervisor."
|
||||||
log "pip install supervisor "
|
|
||||||
configure_supervisor
|
configure_supervisor
|
||||||
|
|
||||||
restart_supervisor
|
restart_supervisor
|
||||||
restart_nginx
|
restart_nginx
|
||||||
|
else
|
||||||
|
echo "Unsupported Debian version. Version found: $version"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
ubuntu)
|
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
|
# Install for Ubuntu 18 / 20 / 22 / 24
|
||||||
tzone=\'$(cat /etc/timezone)\'
|
tzone=\'$(get_timezone)\'
|
||||||
|
|
||||||
echo -n "* Updating installed packages."
|
echo -n "* Updating installed packages."
|
||||||
log "apt-get update && apt-get -y upgrade" & pid=$!
|
log "apt-get update && apt-get -y upgrade" & pid=$!
|
||||||
progress
|
progress
|
||||||
|
|
||||||
echo "* Installing OS requirements."
|
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
|
install_packages
|
||||||
|
|
||||||
set_hosts
|
set_hosts
|
||||||
|
|
@ -559,12 +569,13 @@ case $distro in
|
||||||
configure_nginx
|
configure_nginx
|
||||||
|
|
||||||
echo "* Configuring Supervisor."
|
echo "* Configuring Supervisor."
|
||||||
log "pip install supervisor "
|
|
||||||
configure_supervisor
|
configure_supervisor
|
||||||
|
|
||||||
restart_supervisor
|
restart_supervisor
|
||||||
restart_nginx
|
restart_nginx
|
||||||
|
else
|
||||||
|
echo "Unsupported Ubuntu version. Version found: $version"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
centos)
|
centos)
|
||||||
|
|
@ -680,7 +691,9 @@ echo " ***Open http://$fqdn to login to webvirtcloud.***"
|
||||||
echo ""
|
echo ""
|
||||||
echo ""
|
echo ""
|
||||||
echo "* Cleaning up..."
|
echo "* Cleaning up..."
|
||||||
rm -f webvirtcloud.sh
|
if [ ! -d .git ]; then
|
||||||
rm -f install.sh
|
rm -f webvirtcloud.sh
|
||||||
|
rm -f install.sh
|
||||||
|
fi
|
||||||
echo "* Finished!"
|
echo "* Finished!"
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue