2013-04-12 16:43:46 +02:00
2015-07-08 15:01:21 +02:00
###########################
## Pre-Install functions ##
###########################
2013-04-12 16:43:46 +02:00
2015-07-08 15:01:21 +02:00
update_default_user() {
2014-01-20 10:35:50 +01:00
2015-07-08 15:01:21 +02:00
# Make sure there is a qubes group
groupadd --force --system --gid 98 qubes
2013-04-12 16:43:46 +02:00
2015-07-08 15:01:21 +02:00
# Archlinux bash version has a 'bug' when running su -c, /etc/profile is not loaded because bash consider there is no interactive pty when running 'su - user -c' or something like this.
# See https://bugs.archlinux.org/task/31831
id -u 'user' >/dev/null 2>&1 || {
useradd --user-group --create-home --shell /bin/zsh user
}
usermod -a --groups qubes user
2013-04-12 16:43:46 +02:00
2015-07-08 15:01:21 +02:00
}
2013-04-12 16:43:46 +02:00
## arg 1: the new package version
2013-04-18 13:34:50 +02:00
pre_install() {
2015-07-08 15:01:21 +02:00
echo "Pre install..."
2013-04-26 09:32:10 +02:00
2015-07-08 15:01:21 +02:00
update_default_user
2013-04-26 09:32:10 +02:00
2015-07-08 15:01:21 +02:00
# do this whole %pre thing only when updating for the first time...
2013-04-26 09:32:10 +02:00
2015-07-08 15:01:21 +02:00
mkdir -p /var/lib/qubes
2014-02-03 20:10:36 +01:00
2015-07-08 15:01:21 +02:00
# Backup fstab / But use archlinux defaults (cp instead of mv)
2015-10-15 04:34:55 +02:00
if [ -e /etc/fstab ] ; then
2015-07-08 15:01:21 +02:00
cp /etc/fstab /var/lib/qubes/fstab.orig
fi
2013-04-26 09:32:10 +02:00
2015-07-08 15:01:21 +02:00
# Add qubes core related fstab entries
echo "xen /proc/xen xenfs defaults 0 0" >> /etc/fstab
2015-02-07 12:07:35 +01:00
2015-07-08 15:01:21 +02:00
usermod -p '' root
usermod -L user
2013-04-18 13:34:50 +02:00
}
2013-04-12 16:43:46 +02:00
2015-07-08 15:01:21 +02:00
2013-04-12 16:43:46 +02:00
## arg 1: the new package version
2015-07-08 15:01:21 +02:00
## arg 2: the old package version
pre_upgrade() {
# do something here
echo "Pre upgrade..."
update_default_user
}
2015-10-16 14:34:15 +02:00
###################
## Install Hooks ##
###################
2015-07-08 15:01:21 +02:00
2015-10-16 14:34:15 +02:00
configure_notification-daemon() {
# Enable autostart of notification-daemon when installed
if [ ! -e /etc/xdg/autostart/notification-daemon.desktop ]; then
ln -s /usr/share/applications/notification-daemon.desktop /etc/xdg/autostart/
fi
2015-07-08 15:01:21 +02:00
}
2015-10-16 14:34:15 +02:00
configure_selinux() {
# SELinux is not enabled on archlinux
#echo "--> Disabling SELinux..."
echo "SELINUX not enabled on archlinux. skipped."
# sed -e s/^SELINUX=.*$/SELINUX=disabled/ -i /etc/selinux/config
# setenforce 0 2>/dev/null
2015-07-08 15:01:21 +02:00
}
2015-10-16 14:34:15 +02:00
############################
## Post-Install functions ##
############################
2015-07-08 15:01:21 +02:00
update_qubesconfig() {
2013-04-12 16:43:46 +02:00
2015-11-28 17:00:36 +01:00
# Create NetworkManager configuration if we do not have it
if ! [ -e /etc/NetworkManager/NetworkManager.conf ]; then
echo '[main]' > /etc/NetworkManager/NetworkManager.conf
echo 'plugins = keyfile' >> /etc/NetworkManager/NetworkManager.conf
echo '[keyfile]' >> /etc/NetworkManager/NetworkManager.conf
fi
/usr/lib/qubes/qubes-fix-nm-conf.sh
2015-07-08 15:01:21 +02:00
# Remove ip_forward setting from sysctl, so NM will not reset it
# Archlinux now use sysctl.d/ instead of sysctl.conf
#sed 's/^net.ipv4.ip_forward.*/#\0/' -i /etc/sysctl.conf
2015-10-15 04:34:55 +02:00
2015-07-08 15:01:21 +02:00
# Remove old firmware updates link
if [ -L /lib/firmware/updates ]; then
rm -f /lib/firmware/updates
fi
2013-04-12 16:43:46 +02:00
2015-07-08 15:01:21 +02:00
# Yum proxy configuration is fedora specific
#if ! grep -q '/etc/yum\.conf\.d/qubes-proxy\.conf' /etc/yum.conf; then
# echo >> /etc/yum.conf
# echo '# Yum does not support inclusion of config dir...' >> /etc/yum.conf
# echo 'include=file:///etc/yum.conf.d/qubes-proxy.conf' >> /etc/yum.conf
#fi
# Location of files which contains list of protected files
mkdir -p /etc/qubes/protected-files.d
PROTECTED_FILE_LIST='/etc/qubes/protected-files.d'
2015-10-15 04:34:55 +02:00
2015-07-08 15:01:21 +02:00
# qubes-core-vm has been broken for some time - it overrides /etc/hosts; restore original content
if ! grep -rq "^/etc/hosts$" "${PROTECTED_FILE_LIST}" 2>/dev/null; then
if ! grep -q localhost /etc/hosts; then
cat <<EOF > /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 `hostname`
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
2015-07-14 08:09:11 +02:00
EOF
2015-07-08 15:01:21 +02:00
fi
fi
2015-10-15 04:34:55 +02:00
2015-07-08 15:01:21 +02:00
# ensure that hostname resolves to 127.0.0.1 resp. ::1 and that /etc/hosts is
# in the form expected by qubes-sysinit.sh
if ! grep -rq "^/etc/hostname$" "${PROTECTED_FILE_LIST}" 2>/dev/null; then
for ip in '127\.0\.0\.1' '::1'; do
if grep -q "^${ip}\(\s\|$\)" /etc/hosts; then
sed -i "/^${ip}\s/,+0s/\(\s`hostname`\)\+\(\s\|$\)/\2/g" /etc/hosts
sed -i "s/^${ip}\(\s\|$\).*$/\0 `hostname`/" /etc/hosts
else
echo "${ip} `hostname`" >> /etc/hosts
fi
done
fi
2013-04-12 16:43:46 +02:00
2015-07-08 15:01:21 +02:00
# Make sure there is a default locale set so gnome-terminal will start
if [ ! -e /etc/locale.conf ] || ! grep -q LANG /etc/locale.conf; then
touch /etc/locale.conf
echo "LANG=en_US.UTF-8" >> /etc/locale.conf
fi
# ... and make sure it is really generated
2015-12-08 15:32:30 +01:00
# This line is buggy as LANG can be set to LANG="en_US.UTF-8". The Quotes must be stripped
current_locale=`grep LANG /etc/locale.conf|cut -f 2 -d = | tr -d '"'`
2015-07-08 15:01:21 +02:00
if [ -n "$current_locale" ] && ! locale -a | grep -q "$current_locale"; then
base=`echo "$current_locale" | cut -f 1 -d .`
charmap=`echo "$current_locale.UTF-8" | cut -f 2 -d .`
[ -n "$charmap" ] && charmap="-f $charmap"
localedef -i $base $charmap $current_locale
fi
}
2015-10-16 14:34:15 +02:00
configure_systemd() {
PRESET_FAILED=0
if [ $1 -eq 1 ]; then
2015-12-15 16:20:03 +01:00
# Needs to be started two times to deal with services name changes (systemctl bug?)
echo "Resetting systemd services to defaults presets (PASS 1)"
systemctl --no-reload preset-all 2>&1 && PRESET_FAILED=0 || PRESET_FAILED=1
echo "Resetting systemd services to defaults presets (PASS 2)"
systemctl --no-reload preset-all 2>&1 && PRESET_FAILED=0 || PRESET_FAILED=1
2015-10-16 14:34:15 +02:00
else
2015-10-18 10:56:18 +02:00
services="qubes-dvm qubes-misc-post qubes-firewall qubes-mount-dirs"
2015-10-16 14:34:15 +02:00
services="$services qubes-netwatcher qubes-network qubes-sysinit"
services="$services qubes-iptables qubes-updates-proxy qubes-qrexec-agent"
services="$services qubes-random-seed"
for srv in $services; do
2015-12-15 16:20:03 +01:00
echo "Enable service defaults for $service"
2015-10-16 14:34:15 +02:00
systemctl --no-reload preset $srv.service
done
systemctl --no-reload preset qubes-update-check.timer
# Upgrade path - now qubes-iptables is used instead
systemctl --no-reload preset iptables.service
systemctl --no-reload preset ip6tables.service
fi
# Set default "runlevel"
rm -f /etc/systemd/system/default.target
ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
grep '^[[:space:]]*[^#;]' /lib/systemd/system-preset/75-qubes-vm.preset | while read action unit_name; do
case "$action" in
(disable)
if [ -f /lib/systemd/system/$unit_name ]; then
if ! fgrep -q '[Install]' /lib/systemd/system/$unit_name; then
# forcibly disable
ln -sf /dev/null /etc/systemd/system/$unit_name
fi
fi
;;
*)
# preset-all is not available in fc20; so preset each unit file listed in 75-qubes-vm.preset
if [ $1 -eq 1 -a "${PRESET_FAILED}" -eq 1 ]; then
systemctl --no-reload preset "${unit_name}" > /dev/null 2>&1 || true
fi
;;
esac
done
systemctl daemon-reload
}
2016-01-21 18:21:44 +01:00
config_prependtomark() {
FILE=$1
APPENDBEFORELINE=$2
APPENDLINE=$3
grep -q "$APPENDLINE" "$FILE" || sed "/$APPENDBEFORELINE/i$APPENDLINE" -i "$FILE"
}
2016-01-21 07:59:35 +01:00
2016-01-21 18:21:44 +01:00
config_appendtomark() {
2016-01-21 07:59:35 +01:00
FILE=$1
APPENDAFTERLINE=$2
APPENDLINE=$3
grep -q "$APPENDLINE" "$FILE" || sed "/$APPENDAFTERLINE/a$APPENDLINE" -i "$FILE"
}
2015-10-16 14:34:15 +02:00
update_finalize() {
2015-07-08 15:01:21 +02:00
2016-04-26 12:57:36 +02:00
# Archlinux specific: Prepare pacman.conf to add qubes specific config
QUBES_MARKER="### QUBES CONFIG MARKER ###"
config_prependtomark "/etc/pacman.conf" "# REPOSITORIES" "$QUBES_MARKER"
2015-07-08 15:01:21 +02:00
# Archlinux specific: Update pam.d configuration for su to enable systemd-login wrapper
2016-04-26 12:57:36 +02:00
# Also remove pam_unix.so from su configuration
# as system-login (which include system-auth) already gives pam_unix.so
# with more appropriate parameters (fix the missing nullok parameter)
if [ -n "`cat /etc/pam.d/su | grep pam_unix.so`" ] ; then
2015-07-08 15:01:21 +02:00
echo "Fixing pam.d"
2016-04-26 12:57:36 +02:00
cat <<EOF > /etc/pam.d/su
#%PAM-1.0
auth sufficient pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth sufficient pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
#auth required pam_wheel.so use_uid
auth include system-login
account include system-login
session include system-login
EOF
2015-07-08 15:01:21 +02:00
cp /etc/pam.d/su /etc/pam.d/su-l
2016-04-26 12:57:36 +02:00
echo "Ensure pam.d will not be modified by archlinux package updates"
config_appendtomark '/etc/pacman.conf' "$QUBES_MARKER" 'NoUpgrade = etc/pam.d/su'
config_appendtomark '/etc/pacman.conf' "$QUBES_MARKER" 'NoUpgrade = etc/pam.d/su-l'
2015-07-08 15:01:21 +02:00
fi
# Archlinux specific: ensure tty1 is enabled
rm -f /etc/systemd/system/getty.target.wants/getty@tty*.service
systemctl enable getty\@tty1.service
2016-01-21 07:59:35 +01:00
# Add Qubes setup script markers at the right place (this won't work at the end of pacman.conf)"
2016-01-21 18:21:44 +01:00
config_appendtomark "/etc/pacman.conf" "$QUBES_MARKER" "### QUBES END ###"
config_appendtomark "/etc/pacman.conf" "$QUBES_MARKER" "### QUBES BEGIN ###"
2016-01-21 07:59:35 +01:00
2015-07-08 15:01:21 +02:00
systemctl daemon-reload
2013-04-12 16:43:46 +02:00
}
## arg 1: the new package version
2015-07-08 15:01:21 +02:00
post_install() {
2013-04-12 16:43:46 +02:00
2015-07-08 15:01:21 +02:00
update_qubesconfig
# do the rest of %post thing only when updating for the first time...
if [ -e /etc/init/serial.conf ] && ! [ -f /var/lib/qubes/serial.orig ] ; then
cp /etc/init/serial.conf /var/lib/qubes/serial.orig
fi
# Remove most of the udev scripts to speed up the VM boot time
# Just leave the xen* scripts, that are needed if this VM was
# ever used as a net backend (e.g. as a VPN domain in the future)
#echo "--> Removing unnecessary udev scripts..."
mkdir -p /var/lib/qubes/removed-udev-scripts
for f in /etc/udev/rules.d/*
do
if [ $(basename $f) == "xen-backend.rules" ] ; then
continue
fi
2015-10-15 04:34:55 +02:00
2015-07-08 15:01:21 +02:00
if [ $(basename $f) == "50-qubes-misc.rules" ] ; then
continue
fi
2015-10-15 04:34:55 +02:00
2015-07-08 15:01:21 +02:00
if echo $f | grep -q qubes; then
continue
fi
2015-10-15 04:34:55 +02:00
2015-07-08 15:01:21 +02:00
mv $f /var/lib/qubes/removed-udev-scripts/
done
mkdir -p /rw
2015-07-28 16:12:07 +02:00
configure_notification-daemon
configure_selinux
2015-10-16 14:34:15 +02:00
configure_systemd 0
2015-07-08 15:01:21 +02:00
2015-10-16 14:34:15 +02:00
update_finalize
2015-07-08 15:01:21 +02:00
glib-compile-schemas /usr/share/glib-2.0/schemas &> /dev/null || :
2015-10-16 14:34:15 +02:00
2013-04-12 16:43:46 +02:00
}
## arg 1: the new package version
## arg 2: the old package version
2015-07-08 15:01:21 +02:00
post_upgrade() {
update_qubesconfig
2015-07-28 16:12:07 +02:00
configure_notification-daemon
configure_selinux
2015-10-18 11:11:45 +02:00
configure_systemd 1
2015-10-16 14:34:15 +02:00
update_finalize
2015-07-08 15:01:21 +02:00
/usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas &> /dev/null || :
2013-04-18 13:34:50 +02:00
}
2013-04-12 16:43:46 +02:00
2015-07-08 15:01:21 +02:00
######################
## Remove functions ##
######################
2013-04-12 16:43:46 +02:00
## arg 1: the old package version
2014-02-03 20:10:36 +01:00
pre_remove() {
# no more packages left
if [ -e /var/lib/qubes/fstab.orig ] ; then
mv /var/lib/qubes/fstab.orig /etc/fstab
fi
mv /var/lib/qubes/removed-udev-scripts/* /etc/udev/rules.d/
if [ -e /var/lib/qubes/serial.orig ] ; then
mv /var/lib/qubes/serial.orig /etc/init/serial.conf
fi
}
2013-04-12 16:43:46 +02:00
## arg 1: the old package version
2014-01-20 10:35:50 +01:00
post_remove() {
2014-02-03 20:10:36 +01:00
/usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas &> /dev/null || :
if [ -L /lib/firmware/updates ] ; then
rm /lib/firmware/updates
fi
2015-10-18 11:11:45 +02:00
rm -rf /var/lib/qubes/xdg
2015-10-14 21:09:49 +02:00
for srv in qubes-dvm qubes-sysinit qubes-misc-post qubes-mount-dirs qubes-netwatcher qubes-network qubes-qrexec-agent; do
2015-07-08 15:01:21 +02:00
systemctl disable $srv.service
2015-07-14 08:09:11 +02:00
done
2015-10-16 14:34:15 +02:00
2014-01-20 10:35:50 +01:00
}