diff --git a/dist/functions.setup-appliance.sh b/dist/functions.setup-appliance.sh index 7ab6d132bb28..8f1fa28a3d46 100755 --- a/dist/functions.setup-appliance.sh +++ b/dist/functions.setup-appliance.sh @@ -238,24 +238,31 @@ function prepare_database_setup { RAILS_ENV=production bin/rails db:migrate:status > /dev/null 2>&1 if [[ $? > 0 ]];then - if ! [[ "$(lsb_release -si)" =~ ^(Debian|Ubuntu)$ ]];then - echo "Initialize MySQL databases (first time only)" - DATADIR_FILE=$(grep datadir -rl /etc/my.cnf*) - echo " - reconfiguring datadir in $DATADIR_FILE" - sed -i -E '0,/(#\s*)?datadir/ s!#\s*datadir\s*=\s*/var/lib/mysql$!datadir = /srv/obs/MySQL!' $DATADIR_FILE - echo " - installing to new datadir" - mysql_install_db - echo " - changing ownership for new datadir" - chown mysql:mysql -R /srv/obs/MySQL - MYSQL_LOG=$(grep log-error /etc/my.cnf.d/*.cnf|perl -p -e 's/.*:log-error=(.*)/$1/') - if [ -n "$MYSQL_LOG" ];then - echo " - prepare log file $MYSQL_LOG" - LOG_DIR=`dirname $MYSQL_LOG` - if [ ! -d $LOG_DIR ];then - mkdir -p $LOG_DIR - chown mysql:mysql $LOG_DIR - fi - fi + . /etc/os-release + for d in $ID_LIKE $ID;do + case $d in + ubuntu|debian) ;; + *) + echo "Initialize MySQL databases (first time only)" + DATADIR_FILE=$(grep datadir -rl /etc/my.cnf*) + echo " - reconfiguring datadir in $DATADIR_FILE" + sed -i -E '0,/(#\s*)?datadir/ s!#\s*datadir\s*=\s*/var/lib/mysql$!datadir = /srv/obs/MySQL!' $DATADIR_FILE + echo " - installing to new datadir" + mysql_install_db + echo " - changing ownership for new datadir" + chown mysql:mysql -R /srv/obs/MySQL + MYSQL_LOG=$(grep log-error /etc/my.cnf.d/*.cnf|perl -p -e 's/.*:log-error=(.*)/$1/') + if [ -n "$MYSQL_LOG" ];then + echo " - prepare log file $MYSQL_LOG" + LOG_DIR=`dirname $MYSQL_LOG` + if [ ! -d $LOG_DIR ];then + mkdir -p $LOG_DIR + chown mysql:mysql $LOG_DIR + fi + fi + ;; + esac + done RUN_INITIAL_SETUP="true" fi @@ -356,7 +363,7 @@ function import_ca_cert { # apache has to trust the api ssl certificate if [ ! -e /etc/ssl/certs/server.${FQHOSTNAME}.crt ]; then cp $backenddir/certs/server.${FQHOSTNAME}.crt \ - ${TRUST_ANCHORS_DIR}/server.${FQHOSTNAME}.pem + ${TRUST_ANCHORS_DIR}/server.${FQHOSTNAME}.${SSL_CERT_SUFFIX} $UPDATE_SSL_TRUST_BIN fi } @@ -499,11 +506,13 @@ function prepare_apache2 { PKG2INST="" for pkg in $APACHE_ADDITIONAL_PACKAGES;do - if [[ "$(lsb_release -si)" =~ ^(Debian|Ubuntu)$ ]]; then - dpkg -l $pkg >/dev/null 2>&1 || PKG2INST="$PKG2INST $pkg" - else - rpm -q $pkg >/dev/null || PKG2INST="$PKG2INST $pkg" - fi + . /etc/os-release + for d in $ID_LIKE $ID;do + case $d in + ubuntu|debian) dpkg -l $pkg >/dev/null 2>&1 || PKG2INST="$PKG2INST $pkg" ;; + *) rpm -q $pkg >/dev/null || PKG2INST="$PKG2INST $pkg" ;; + esac + done done if [[ -n $PKG2INST ]];then @@ -513,7 +522,12 @@ function prepare_apache2 { if [ "$CONFIGURE_APACHE" == 1 ];then MODULES="passenger rewrite proxy proxy_http headers socache_shmcb xforward" FLAGS="" - [[ "$(lsb_release -si)" =~ ^(Debian|Ubuntu)$ ]] && MODULES="$MODULES ssl" || FLAGS=SSL + for d in $ID_LIKE $ID;do + case $d in + ubuntu|debian) MODULES="$MODULES ssl" ;; + *) FLAGS=SSL ;; + esac + done for mod in $MODULES;do a2enmod -q $mod || a2enmod $mod @@ -619,6 +633,7 @@ function prepare_os_settings { HTTPD_GROUP=www PASSENGER_CONF=/etc/$HTTPD_SERVICE/conf.d/mod_passenger.conf TRUST_ANCHORS_DIR=/usr/share/pki/trust/anchors + SSL_CERT_SUFFIX=pem UPDATE_SSL_TRUST_BIN=update-ca-certificates MOD_PASSENGER_CONF=/etc/$HTTPD_SERVICE/conf.d/mod_passenger.conf INST_PACKAGES_CMD="zypper --non-interactive install" @@ -634,6 +649,7 @@ function prepare_os_settings { HTTPD_GROUP=apache PASSENGER_CONF=/etc/$HTTPD_SERVICE/conf.d/passenger.conf TRUST_ANCHORS_DIR=/etc/pki/ca-trust/source/anchors + SSL_CERT_SUFFIX=pem UPDATE_SSL_TRUST_BIN=update-ca-trust MOD_PASSENGER_CONF=/etc/$HTTPD_SERVICE/conf.d/passenger.conf INST_PACKAGES_CMD="dnf -y install" @@ -649,6 +665,7 @@ function prepare_os_settings { HTTPD_GROUP=www-data PASSENGER_CONF=/etc/$HTTPD_SERVICE/mods-available/passenger.conf TRUST_ANCHORS_DIR=/usr/local/share/ca-certificates + SSL_CERT_SUFFIX=crt UPDATE_SSL_TRUST_BIN=update-ca-certificates MOD_PASSENGER_CONF=/etc/$HTTPD_SERVICE/mods-available/passenger.conf INST_PACKAGES_CMD="apt-get install -qq -y" diff --git a/dist/setup-appliance.sh b/dist/setup-appliance.sh index d6fd1ef8f44b..9498ca74fe9e 100755 --- a/dist/setup-appliance.sh +++ b/dist/setup-appliance.sh @@ -20,11 +20,24 @@ MYSQL_PASS=opensuse PID_FILE=/run/setup-appliance.pid # package or appliance defaults -if [[ "$(lsb_release -si)" =~ ^(Debian|Ubuntu)$ ]]; then - defaultsfile="/etc/default/obs-server" +if [ -e /etc/os-release ];then + # execute in subshell to preserve the values of the variables + # $NAME and $VERSION as these are very generic + OS_NAME=`. /etc/os-release;echo $NAME` + OS_VERSION=`. /etc/os-release;echo $VERSION` + OS_ID_LIKE=`. /etc/os-release;echo $ID_LIKE` + OS_ID=`. /etc/os-release;echo $ID` + OS="$OS_NAME $OS_VERSION" else - defaultsfile="/etc/sysconfig/obs-server" + OS="UNKNOWN" fi + +for d in $OS_ID_LIKE $OS_ID;do + case $d in + ubuntu|debian) defaultsfile="/etc/default/obs-server" ;; + *) defaultsfile="/etc/sysconfig/obs-server" ;; + esac +done if [ -e "$defaultsfile" ]; then source "$defaultsfile" fi @@ -117,20 +130,12 @@ fi echo "$FQHOSTNAME" > $backenddir/.oldfqhostname -if [ -e /etc/os-release ];then - # execute in subshell to preserve the values of the variables - # $NAME and $VERSION as these are very generic - OS_NAME=`. /etc/os-release;echo $NAME` - OS_VERSION=`. /etc/os-release;echo $VERSION` - OS="$OS_NAME $OS_VERSION" -else - OS="UNKNOWN" -fi -if [[ "$OS_NAME" =~ ^(Debian|Ubuntu)$ ]]; then - OBSVERSION=`dpkg-query --showformat='${Version}' --show obs-server` -else - OBSVERSION=`rpm -q --qf '%{VERSION}' obs-server` -fi +for d in $OS_ID_LIKE $OS_ID;do + case $d in + ubuntu|debian) OBSVERSION=`dpkg-query --showformat='${Version}' --show obs-server` ;; + *) OBSVERSION=`rpm -q --qf '%{VERSION}' obs-server` ;; + esac +done RUN_INITIAL_SETUP=""