|
#!/bin/sh
|
|
# postinst script for foreman
|
|
#
|
|
# see: dh_installdeb(1)
|
|
|
|
if [ ! -z "${DEBUG}" ]; then
|
|
set -x
|
|
else
|
|
set -e
|
|
fi
|
|
|
|
. /usr/share/debconf/confmodule
|
|
|
|
LOGFILE='/var/log/foreman-install.log'
|
|
|
|
# if this script aborts with an error dpkg can hang if a debconf can
|
|
# hang if daemons have been started
|
|
trap db_stop EXIT
|
|
|
|
# Add the "foreman" user and group
|
|
getent group foreman >/dev/null || groupadd -r foreman
|
|
getent passwd foreman >/dev/null || \
|
|
useradd -r -g foreman -d /usr/share/foreman -s /usr/sbin/nologin -c "Foreman" foreman
|
|
|
|
chown -Rf foreman:foreman '/var/log/foreman'
|
|
chown -Rf foreman:foreman '/var/cache/foreman'
|
|
chown -Rf foreman:foreman '/var/lib/foreman'
|
|
chmod 755 '/var/lib/foreman'
|
|
chmod 755 '/var/lib/foreman/db'
|
|
chmod 755 '/var/lib/foreman/public'
|
|
chmod 755 '/var/lib/foreman/public/assets'
|
|
chmod 755 '/var/cache/foreman'
|
|
|
|
# Test for Gemfile.lock to determine the right action.
|
|
cd /usr/share/foreman
|
|
if [ -f Gemfile.lock ]; then
|
|
CMD="bundle update --local"
|
|
else
|
|
CMD="bundle install --path ./vendor/ --local --no-prune"
|
|
fi
|
|
|
|
if [ ! -z "${DEBUG}" ]; then
|
|
$CMD
|
|
else
|
|
$CMD 2>&1 >> $LOGFILE
|
|
fi
|
|
|
|
# Run a db:migrate and db:seed if the user has created a dbfile
|
|
if [ -f /usr/share/foreman/config/database.yml ]; then
|
|
if [ ! -z "${DEBUG}" ]; then
|
|
/usr/sbin/foreman-rake db:migrate || true
|
|
/usr/sbin/foreman-rake db:seed || true
|
|
else
|
|
/usr/sbin/foreman-rake db:migrate >> $LOGFILE 2>&1 || true
|
|
/usr/sbin/foreman-rake db:seed >> $LOGFILE 2>&1 || true
|
|
fi
|
|
fi
|
|
|
|
# Generate a static session token for signing cookies
|
|
#if [ ! -f config/initializers/local_secret_token.rb ]; then
|
|
#touch config/initializers/local_secret_token.rb
|
|
#chmod 0640 config/initializers/local_secret_token.rb
|
|
#chgrp foreman config/initializers/local_secret_token.rb
|
|
#if [ ! -z "${DEBUG}" ]; then
|
|
#rake -f /usr/share/foreman/Rakefile -t security:generate_token
|
|
#else
|
|
#rake -f /usr/share/foreman/Rakefile security:generate_token >> $LOGFILE 2>&1
|
|
#fi
|
|
#fi
|
|
|
|
# Own all the core files
|
|
chown -Rf foreman:foreman '/usr/share/foreman'
|
|
|
|
#DEBHELPER#
|
|
|
|
exit 0
|