[SOLVED] Respond to Legal Notice before login.

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Post Reply
RWMills
Level 1
Level 1
Posts: 9
Joined: Sat May 08, 2021 2:57 am
Location: London, England

[SOLVED] Respond to Legal Notice before login.

Post by RWMills »

OS: Linux Mint 21 (vanessa) Cinnamon (5.4.12) Edition
Shell: Ksh 93u+m/1.0.0-beta.2 20021-12-17

I'm trying to display a Legal Notice that needs acceptance prior to the desktop login prompt being displayed.

I have a ksh93 shell script that uses zenity (3.42.1) to display a message, checkbox, and the buttons [Accept] and [Reject].

If the user does not accept the conditions in the message and does not 'tick' the checkbox then the only the [Reject] button is available.

If the user 'ticks' the checkbox and clicks on the [Accept] button the script will just terminate letting the normal login process continue. Otherwise the
script needs to get the system to power down using '/sbin/shutdown now -P' or something similar.

My problem is how and where to trigger the execution of the script.

Source of script:

Code: Select all

    #!/bin/ksh93
    FILE=`dirname $0`/LegalNotice.msg
    zenity \
    --text-info \
    --title="Legal Notice" \
    --width=510 \
    --height=530 \
    --filename=$FILE \
    --checkbox="I have read and accept the legal notice." \
    --ok-label="Accept"\
    --cancel-label="Reject"
    response=$?
    if (($response != 0)); then
      # shutdown the system.
      echo "shutting down..."
      #/sbin/shutdown now -P
    fi
Last edited by RWMills on Fri Feb 09, 2024 11:37 am, edited 1 time in total.
rickNS
Level 9
Level 9
Posts: 2981
Joined: Tue Jan 25, 2011 11:59 pm

Re: Respond to Legal Notice before login.

Post by rickNS »

RWMills wrote: Fri Jan 19, 2024 1:04 pm
My problem is how and where to trigger the execution of the script.
I can think of a couple possibilities;
1, create a cron job to run at boot.
https://phoenixnap.com/kb/crontab-reboot

2, create a systemd service,
https://unix.stackexchange.com/question ... gin-screen

You probably get better answers if you ask a moderator to move this topic to 'Scripts & Bash'
Mint 20.0, and 21.0 MATE on Thinkpads, 3 X T420, T450, T470, and X200
RWMills
Level 1
Level 1
Posts: 9
Joined: Sat May 08, 2021 2:57 am
Location: London, England

Re: Respond to Legal Notice before login.

Post by RWMills »

@rickNS,

Have just tried your 2nd suggestion, a systemd service.

1) Created a service file (LegalNotice.servide) which I placed in /etc/systemd/system, made root the owner, made it executable.
2) Did a 'systemctl start LegalNotice' which reported no problems. Looking good so far.
3) Waited a few minutes and then did a 'systemctrl status LegalNotice'. Not looking good now :( See the 2nd line in the systemctl output below.
4) Did a bit more reading and replaced 'multi-user.target' with 'graphical.target' on the WantedBy option.
5) Did a 'systemctl start LegalNotice' which again reported no problems. Still looking good (so far).
6) Waited a few minutes and then did a 'systemctrl status LegalNotice'. Not looking good again :(( Gave same message from zenity.

Oh well, back to the drawing board.

LegalNotice.service file:

Code: Select all

[Unit]
Description=Service to display Legal Message during boot.
[Service]
Type=simple
ExecStart=/home/robert/Scripting/LegalNotice
[Install]
WantedBy=multi-user.target
Output from systemctl status:

Code: Select all

Jan 19 20:26:35 Hawk systemd[1]: Started Service to display Legal Message during boot..
Jan 19 20:26:35 Hawk zenity[1269173]: cannot open display: 
Jan 19 20:26:35 Hawk LegalNotice[1269171]: shutting down...
Jan 19 20:26:35 Hawk systemd[1]: LegalNotice.service: Deactivated successfully.
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Respond to Legal Notice before login.

Post by Koentje »

After a 2 hour fight to get a service running to execute this script at logon, i came to the conclusion that it is not possible at the login screen! The same cannot open display kept popping up in the status of the service.
After a quick search it seems that the login screen is not X. Lightdm writes directly to the screen. That's why Zenity can not display it self because there is no X server running.....
After another few searches i came across something else. Via /etc/lightdm/lightdm.conf you can start a script, but it needs the user to login first. Immediately after login, before anything shows on the desktop (complete black background) you get the zenity window! Accept and the login proceeds, reject and you get thrown back on the login prompt.

If that is what you want?

Your bash script slightly customized:

Code: Select all

#!/bin/sh

FILE="/root/.logon/text" # place text to be displayed in this file.

logger -t LegalNotice "Show window to $USER"

zenity --text-info \
  --title="Legal Notice" \
  --width=550 \
  --height=500 \
  --filename=$FILE \
  --checkbox="I have read and accept the legal notice."
response=$?

if [ "$response" = "0" ]; then
  logger -t LegalNotice "User $USER accepted legal notice, proceed login!"
else
  logger -t LegalNotice "User $USER did not accept legal notice, loggin out!"
  systemctl restart lightdm
fi
Place this script in /root/.logon, call it legalnotice and make it executable.

Then edit /etc/lightdm/lightdm.conf
and add this line: session-setup-script=/root/.logon/legalnotice

Now logout and login... let me know if it works for you.
RWMills
Level 1
Level 1
Posts: 9
Joined: Sat May 08, 2021 2:57 am
Location: London, England

[SOLVED] Respond to Legal Notice before login.

Post by RWMills »

@Koentje,

It worked just like you said, thanks for your help. It looks as if I nearly had the solution when I first wrote the script back in November.

This is what I originally wrote as the installation instructions:

Code: Select all

# Installation:
#
#   1) Save file as LegalNotice in /usr/local/bin/
#   2) Create an HTML file named LegalNotice.msg in /usr/local/bin/ containing
#      the text to be displayed to the user. You may have to adjust the --width
#      and --height parameters used by zenity to see the full message without
#      the user having to use the scroll bars.
#   3) Add to the following line to /etc/lightdm/lightdb.conf.d/10-ubuntu.conf:
#        session-setup-script=/usr/local/bin/LegalNotice
#   4) Restart lightdm (service lightdm restart) or reboot.
As you can see in item 3), I was just looking at the wrong lightdm.conf.
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Respond to Legal Notice before login.

Post by Koentje »

Glad it works! :D
User avatar
AndyMH
Level 21
Level 21
Posts: 13759
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: Respond to Legal Notice before login.

Post by AndyMH »

Not sure which conf file you amended, but this is how you should do it to launch a display setup script:
viewtopic.php?p=2209128#p2209128
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
Post Reply

Return to “Scripts & Bash”