Skip to content

Commit

Permalink
[dist] replace lsb-release calls by sourcing /etc/os-release
Browse files Browse the repository at this point in the history
  • Loading branch information
jjacque committed Oct 21, 2023
1 parent 5d68f95 commit 950db22
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 42 deletions.
67 changes: 42 additions & 25 deletions dist/functions.setup-appliance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
39 changes: 22 additions & 17 deletions dist/setup-appliance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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=""

Expand Down

0 comments on commit 950db22

Please sign in to comment.