Commit e5619e90 authored by Michael Shigorin's avatar Michael Shigorin

live: initial rollback hook subsystem

Currently done for 40-autologin script only but might be more widely useful: when describing an action to be done while forming the LiveCD image, also prepare the one that undoes the effect so that an installed LiveCD doesn't (mis)behave as if it were young again. NB: livecd-install provides 50-{gdm,kdm}-autologin-off.sh hooks which can collide with ours, so let's override those until things are sorted out properly at both sides. PS: some half-year old nodm hacks are still in place for t6/branch (and #27451 should be re-examined when dropping those).
parent 2ff873eb
...@@ -15,6 +15,28 @@ add_nopasswdlogin_group() ...@@ -15,6 +15,28 @@ add_nopasswdlogin_group()
gpasswd -a "$USER" nopasswdlogin gpasswd -a "$USER" nopasswdlogin
} }
BAK=".save"
backup() {
[ -f "$1" -a ! -f "$1$BAK" ] || return 1
cp -av "$1" "$1$BAK"
}
restore_later() {
[ -n "$1" ] || return 0
local prefix="/usr/lib/alterator/hooks/livecd-preinstall.d"
[ -d "$prefix" ] || mkdir -p "$prefix"
local hook="$prefix/51-disable-autologin-again.sh"
[ -s "$hook" ] || cat >> "$hook" <<- EOF
#!/bin/sh
. livecd-functions
EOF
echo mv -v "\$destdir$1$BAK" "\$destdir$1" >> "$hook"
chmod +x "$hook"
}
## setup runlevel ## setup runlevel
INITTAB=/etc/inittab INITTAB=/etc/inittab
if [ -f "$INITTAB" ]; then if [ -f "$INITTAB" ]; then
...@@ -23,39 +45,62 @@ if [ -f "$INITTAB" ]; then ...@@ -23,39 +45,62 @@ if [ -f "$INITTAB" ]; then
fi fi
## autologin^2 ## autologin^2
AUTOLOGIN_CFG=/etc/sysconfig/autologin
if [ -x /usr/sbin/autologin ]; then if [ -x /usr/sbin/autologin ]; then
cat << E_O_F >> /etc/sysconfig/autologin backup "$AUTOLOGIN_CFG"
USER=$USER cat >> "$AUTOLOGIN_CFG" <<- EOF
AUTOLOGIN=yes USER=$USER
E_O_F AUTOLOGIN=yes
EOF
restore_later "$AUTOLOGIN_CFG"
fi fi
## lightdm autologin ## lightdm autologin
LIGHTDM_CONF=/etc/lightdm/lightdm.conf LIGHTDM_CONF=/etc/lightdm/lightdm.conf
if [ -f "$LIGHTDM_CONF" ]; then if [ -f "$LIGHTDM_CONF" ]; then
backup "$LIGHTDM_CONF"
sed -i \ sed -i \
-e "s/^#\(autologin-user=\).*$/\1$USER/" \ -e "s/^#\(autologin-user=\).*$/\1$USER/" \
-e "s/^#\(autologin-user-timeout=0\)/\1/" \ -e "s/^#\(autologin-user-timeout=0\)/\1/" \
"$LIGHTDM_CONF" "$LIGHTDM_CONF"
backup "/etc/group"
add_nopasswdlogin_group lightdm ||: add_nopasswdlogin_group lightdm ||:
restore_later "$LIGHTDM_CONF"
restore_later "/etc/group"
fi fi
## gdm2 autologin ## gdm2 autologin
GDM_CONF=/etc/X11/gdm/custom.conf GDM_CONF=/etc/X11/gdm/custom.conf
if [ -f "$GDM_CONF" ]; then if [ -f "$GDM_CONF" ]; then
backup "$GDM_CONF"
sed -i -e '/\[daemon\]/aAutomaticLoginEnable=true\nAutomaticLogin='$USER \ sed -i -e '/\[daemon\]/aAutomaticLoginEnable=true\nAutomaticLogin='$USER \
"$GDM_CONF" "$GDM_CONF"
backup "/etc/group"
add_nopasswdlogin_group gdm ||: add_nopasswdlogin_group gdm ||:
restore_later "$GDM_CONF"
restore_later "/etc/group"
fi fi
autologin_kdm() { autologin_kdm() {
backup "$1"
sed -i \ sed -i \
-e '/AutoLoginEnable/ s,^.*$,AutoLoginEnable=true,' \ -e '/AutoLoginEnable/ s,^.*$,AutoLoginEnable=true,' \
-e '/AutoLoginUser/ s,^.*$,AutoLoginUser='$USER',' \ -e '/AutoLoginUser/ s,^.*$,AutoLoginUser='$USER',' \
"$1" "$1"
restore_later "$1"
} }
## kdm3 autologin ## kdm3 autologin
# FIXME: tde packages have kdmrc in /usr via an absolute symlink :-(
KDM_ETC=/etc/X11/kdm
KDM_USR=/usr/share/kde/config/kdm
if [ "$(readlink "$KDM_ETC")" = "$KDM_USR" ]; then
rm -f "$KDM_ETC"
ln -s ../.."$KDM_USR" "$KDM_ETC"
fi
KDMRC=/etc/X11/kdm/kdmrc KDMRC=/etc/X11/kdm/kdmrc
if [ -f "$KDMRC" ]; then autologin_kdm "$KDMRC"; fi if [ -f "$KDMRC" ]; then autologin_kdm "$KDMRC"; fi
...@@ -67,22 +112,25 @@ if [ -f "$KDMRC" ]; then autologin_kdm "$KDMRC"; fi ...@@ -67,22 +112,25 @@ if [ -f "$KDMRC" ]; then autologin_kdm "$KDMRC"; fi
# FIXME nodm and xinitrc should be modified (also in p6) # FIXME nodm and xinitrc should be modified (also in p6)
NODM_RC=/etc/sysconfig/nodm NODM_RC=/etc/sysconfig/nodm
NODM_EXE=/usr/sbin/nodm NODM_EXE=/usr/sbin/nodm
if [ -x "$NODM_EXE" ]; then if [ -x "$NODM_EXE" ]; then
cat << E_O_F >> "$NODM_RC" backup "$NODM_RC"
export NODM_USER=$USER cat >> "$NODM_RC" <<- EOF
E_O_F export NODM_USER=$USER
EOF
restore_later "$NODM_RC"
else else
exit 0 exit 0
fi fi
# FIXME: drop when #27449 is fixed # FIXME: drop since #27449 is fixed
PREFDM=/etc/X11/prefdm PREFDM=/etc/X11/prefdm
if [ -f "$PREFDM" ] && ! grep -q nodm "$PREFDM"; then if [ -f "$PREFDM" ] && ! grep -q nodm "$PREFDM"; then
backup "$PREFDM"
sed -i \ sed -i \
-e '/AUTOLOGIN_EXE=/ s,^.*$,AUTOLOGIN_EXE='$NODM_EXE',' \ -e '/AUTOLOGIN_EXE=/ s,^.*$,AUTOLOGIN_EXE='$NODM_EXE',' \
-e '/AUTOLOGIN_CFG=/ s,^.*$,AUTOLOGIN_CFG='$NODM_RC',' \ -e '/AUTOLOGIN_CFG=/ s,^.*$,AUTOLOGIN_CFG='$NODM_RC',' \
"$PREFDM" "$PREFDM"
restore_later "$PREFDM"
fi fi
# FIXME: drop when #27451 is fixed # FIXME: drop when #27451 is fixed
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment