From 38a7074f1015489ba0affe18c10940e345e1e4c9 Mon Sep 17 00:00:00 2001 From: "kebler.net" Date: Thu, 30 Dec 2021 13:07:36 -0800 Subject: [PATCH] feat: lightdm session startup and cleanup installer added --- all/modules/lightdm/.session/session_login | 12 ++++ all/modules/lightdm/.session/session_logout | 9 +++ all/modules/lightdm/.session/slogin | 3 + all/modules/lightdm/.session/slogout | 4 ++ all/modules/lightdm/50-setup-cleanup.conf | 3 + all/modules/lightdm/cpy.session.sh | 28 +++++++++ all/modules/lightdm/lightdm-cleanup.sh | 4 ++ all/modules/lightdm/lightdm-setup.sh | 4 ++ all/modules/lightdm/loginout-install.sh | 67 +++++++++++++++++++++ all/modules/lightdm/readme.md | 51 ++++++++++++++++ 10 files changed, 185 insertions(+) create mode 100755 all/modules/lightdm/.session/session_login create mode 100755 all/modules/lightdm/.session/session_logout create mode 100755 all/modules/lightdm/.session/slogin create mode 100755 all/modules/lightdm/.session/slogout create mode 100644 all/modules/lightdm/50-setup-cleanup.conf create mode 100644 all/modules/lightdm/cpy.session.sh create mode 100644 all/modules/lightdm/lightdm-cleanup.sh create mode 100644 all/modules/lightdm/lightdm-setup.sh create mode 100755 all/modules/lightdm/loginout-install.sh create mode 100644 all/modules/lightdm/readme.md diff --git a/all/modules/lightdm/.session/session_login b/all/modules/lightdm/.session/session_login new file mode 100755 index 0000000..57f9f7a --- /dev/null +++ b/all/modules/lightdm/.session/session_login @@ -0,0 +1,12 @@ +#!/bin/bash +log=$HOME/.session/session.log +&>> $log +echo $USER $HOME +echo "lightdm login setup $(date)" + +# example commands to run when logging in, here binding some other directories for the user +#echo "binding chromium browsers to .browsers" +#/usr/bin/bindfs --map=sysadmin/$USER:@users/@$USER /opt/chromium/default $HOME/.browsers/default +# bind alternate downloads directory +#/usr/bin/bindfs --map=sysadmin/$USER:@users/@$USER /data/downloads $HOME/Downloads + diff --git a/all/modules/lightdm/.session/session_logout b/all/modules/lightdm/.session/session_logout new file mode 100755 index 0000000..d985884 --- /dev/null +++ b/all/modules/lightdm/.session/session_logout @@ -0,0 +1,9 @@ +#!/bin/bash +log=$HOME/.session/session.log +&>> $log +echo $USER $HOME +echo "lightdm logout cleanup $(date)" +# example complimentary cleanup here unmounting those mounted in session_login +#echo "un mounting chromium browsers from .browsers" +#/bin/fusermount -u $HOME/.browsers/default +#/bin/fusermount -u $HOME/Downloads diff --git a/all/modules/lightdm/.session/slogin b/all/modules/lightdm/.session/slogin new file mode 100755 index 0000000..2423345 --- /dev/null +++ b/all/modules/lightdm/.session/slogin @@ -0,0 +1,3 @@ +#!/bin/bash +# run the session login script manually, used for debugging +sudo -E HOME=$HOME USER=$USER ./session_login diff --git a/all/modules/lightdm/.session/slogout b/all/modules/lightdm/.session/slogout new file mode 100755 index 0000000..b90e33a --- /dev/null +++ b/all/modules/lightdm/.session/slogout @@ -0,0 +1,4 @@ +#!/bin/bash +# run the session logout script manually, used for debugging +sudo -E HOME=$HOME USER=$USER /bin/bash session_logout + diff --git a/all/modules/lightdm/50-setup-cleanup.conf b/all/modules/lightdm/50-setup-cleanup.conf new file mode 100644 index 0000000..adf4c8e --- /dev/null +++ b/all/modules/lightdm/50-setup-cleanup.conf @@ -0,0 +1,3 @@ +[Seat:*] +session-cleanup-script=/opt/scripts/lightdm-cleanup.sh +session-setup-script=/opt/scripts/lightdm-setup.sh \ No newline at end of file diff --git a/all/modules/lightdm/cpy.session.sh b/all/modules/lightdm/cpy.session.sh new file mode 100644 index 0000000..24fc0d2 --- /dev/null +++ b/all/modules/lightdm/cpy.session.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +function confirm() +{ + echo -n "$@ " + read -e answer + for response in y Y yes YES Yes Sure sure SURE OK ok Ok + do + if [ "_$answer" == "_$response" ] + then + return 0 + fi + done + + # Any answer other than the list above is considered a "no" answer + return 1 +} + +if [[ -d $HOME/.session ]]; then +echo $HOME/.session folder already exists +confirm "!overwrite??? (y/n)" || exit +/bin/cp -r -f $HOME/.session/ $HOME/.session-saved/ +echo saved copy first to $HOME/.session-saved +fi +echo copying .session from $(pwd) to $HOME +/bin/cp -r -f .session/ $HOME +echo setting execute permissions +chmod +x $HOME/.session/* \ No newline at end of file diff --git a/all/modules/lightdm/lightdm-cleanup.sh b/all/modules/lightdm/lightdm-cleanup.sh new file mode 100644 index 0000000..d63c247 --- /dev/null +++ b/all/modules/lightdm/lightdm-cleanup.sh @@ -0,0 +1,4 @@ +#!/bin/bash +echo "cleanup for ${USER}:${HOME} $(date)" >> /opt/scripts/lightdm.log +log=${HOME}/.session.log +if [[ -e $HOME/.session_logout ]]; then su -c "/bin/bash $HOME/.session_logout 1>>${log} 2>>${log} || true" $USER; fi \ No newline at end of file diff --git a/all/modules/lightdm/lightdm-setup.sh b/all/modules/lightdm/lightdm-setup.sh new file mode 100644 index 0000000..69adc97 --- /dev/null +++ b/all/modules/lightdm/lightdm-setup.sh @@ -0,0 +1,4 @@ +#!/bin/bash +echo "setup for ${USER}:${HOME} $(date)" >> /opt/scripts/lightdm.log +log=${HOME}/.session.log +if [[ -e $HOME/.session_login ]]; then su -c "/bin/bash $HOME/.session_login 1>>${log} 2>>${log} || true" $USER; fi \ No newline at end of file diff --git a/all/modules/lightdm/loginout-install.sh b/all/modules/lightdm/loginout-install.sh new file mode 100755 index 0000000..94efcce --- /dev/null +++ b/all/modules/lightdm/loginout-install.sh @@ -0,0 +1,67 @@ +#!/bin/bash +loginout_install() { + module_load confirm + module_load helpers + + [[ ! $(systemctl list-units | grep lightdm) ]] && echo lightdm not running on this machine, aborting && return + + SDIR=$(adirname "$0") + + pushd $SDIR &> /dev/null || exit + [[ ! -d /etc/lightdm/lightdm.conf.d ]] && mkdir -p /etc/lightdm/lightdm.conf.d + echo copying 50-setup-cleanup.conf to /etc/lightdm/lightdm.conf.d + sudo cp -f 50-setup-cleanup.conf /etc/lightdm/lightdm.conf.d + + if [[ ! -d /opt/scripts ]]; then + if [[ ! $(mkdir -p /opt/scripts) ]]; then + _sudo="sudo" + [[ $($_sudo mkdir -p /opt/scripts) ]] && echo can not make /opt/scripts, aborting && return + fi + fi + + echo copying lightdm-cleanup.sh and lightdm-setup.sh to /opt/scripts + $_sudo cp -f lightdm-*.sh /opt/scripts + + + popd >/dev/null + + _user=${1:-${USER}} + confirm "add a user .session folder for $_user" && add_user_session $1 + + +} + +function add_user_session { + + module_load confirm + module_load helpers + + SDIR=$(adirname "$0") + # echo source directory: $SDIR + + pushd $SDIR &> /dev/null || exit + + _user=${1:-${USER}} + + [[ ! $(user_exists $_user) ]] && echo user $_user does not exist, aborting && return + _home=$(bash -c "cd ~$(printf %q $_user) && pwd") + + echo making $_home/.session folder for $_user + # mkdir $USER/.session + + sudo -H -E -u "$_user" -s /bin/bash cpy.session.sh + + popd >/dev/null + + +# confirm "do you want to install WidevineCDM for digital streaming rights?" +# if [ $? -eq 0 ]; then +# module_load widevine-install +# widevine_install +# fi + + +} + +# if script was executed then call the function +(return 0 2>/dev/null) || loginout_install $@ diff --git a/all/modules/lightdm/readme.md b/all/modules/lightdm/readme.md new file mode 100644 index 0000000..b25a7e8 --- /dev/null +++ b/all/modules/lightdm/readme.md @@ -0,0 +1,51 @@ + +Lightdm (gdm) is the login manager for linux ubuntu and mint (by default) + +If you need setup and cleanup that is ONLY done at lightdm login/logout then +one can run a script to setup and cleanup the session by + +running the loginout-install script, requires sudo + +`module_load loginout-install; loginout_install ` # default is current user + +after loading common scripts this will ask if you want to add the .session folder for the user + +or if you just need to add a user .session folder afterward + +`module_load loginout-install; add_user_session ` + + +the script does this + +in `/etc/lightdm/lightdm.conf.d` adds a file `50-setup-cleanup.conf` + +``` +[Seat:*] +session-cleanup-script=/opt/scripts/lightdm-cleanup.sh +session-setup-script=/opt/scripts/lightdm-setup.sh +``` + +in /opt/scripts put two files below and make sure they are +x executable + +``` +#!/bin/bash +#lightdm-setup.sh +echo "setup for ${USER}:${HOME} $(date)" >> /opt/scripts/lightdm.log +log=${HOME}/.session.log +if [[ -e $HOME/.session_login ]]; then su -c "/bin/bash $HOME/.session_login 1>>${log} 2>>${log} || true" $USER; fi +``` + +``` +#!/bin/bash +#lightdm-cleanup.sh +echo "cleanup for ${USER}:${HOME} $(date)" >> /opt/scripts/lightdm.log +log=${HOME}/.session.log +if [[ -e $HOME/.session_logout ]]; then su -c "/bin/bash $HOME/.session_logout 1>>${log} 2>>${log} || true" $USER; fi +``` + +then in the user home puts +`.session_login` and `.session_logout` files both executable +in those you can do anything like bindfs and fusermount -u + +make sure you restart lightdm or reboot +`sdr lightdm` \ No newline at end of file