1

I have been creating an install script that is going to be used for installing proxy and Dev configs on Ubuntu Xenial Desktop only.

I have 2 scripts that are all interactive and require input from the user, my challenge is each script needs a reboot after it is installed and then needs to automatically open another console and become interactive with the next script.

here is a diagram of the flow:

  script_1.sh  >  reboot  >  script_2.sh 
       V                          V              
   usr input                  usr input               
   required                   required                 

I have all the scripts completed and working as they should my challenge is trying to configure Systemd so after the reboot it will open a console and begin the next script.

I am new to this but I built something using rc.local then read the magnitude of posts saying it's not good practice to use it for these sorts of installations, I started using upstart then I found out that it is deprecated and I am required to use Systemd.

Obviously, I would have these scripts built and just copy them in and delete them out when done during the process, here is an attempt earlier any help on how to do this would be fantastic as I have lost 2 days this.

previous atempt:

description     "install script"

start on local-filesystems or runlevel [2345]
stop on runlevel [!2345]

pre-start script
    # prepare environment
    touch /var/logs/DID.log
    exec echo DID installation started  `date` >> /var/log/DID.log
end script

script
    # do some stuff
    exec ~/Documents/script_2.sh
    console output
end script

post-stop script
    # clean up
    exec echo DID stage 2 installation finished  `date` >> /var/log/DID.log
end script

Cheers in advance for any help you can provide.

4
  • You're rebooting already and why would your scripts require further reboots?? Commented Nov 5, 2017 at 14:12
  • are all interactive and require input from the user, I don't think this is the write way to do things. Instead you should use config files and make those startup scripts non-interactive.. Commented Nov 5, 2017 at 14:14
  • the first script is configuring the settings for the internal proxies and domain credential and after playing with it I have found the easiest way to ensure that it will come back up is to reboot the system. I could combine the last 2 scripts which would make it easier and remove the need for a 2nd reboot, it was more of a confidence reboot than anything else the more I think about it. Commented Nov 5, 2017 at 14:16
  • I have done that for as much as I can but the input needed is things like domain credentials and team affiliations and other bits and pieces that I don't have access to pull from other systems and automate into the script and at this point, as not all devs will be using Linux. Commented Nov 5, 2017 at 14:22

1 Answer 1

3

You can create user systemd scripts that might help you out (https://wiki.archlinux.org/index.php/Systemd/User).

Here is a brief example of how you can start a script in a terminal from systemd (not on Ubuntu at the moment so not sure this will work with the paths) goes in your systemd user folder, probably /etc/systemd/user/:

[Unit]
Description=Start Script in terminal

[Service]
ExecStart=/usr/bin/xterm -hold -e /path/to/your/script.sh

[Install]
WantedBy=graphical.target

This will run for me on my system (Arch) with systemctl --user start servicename.service

The trick will be getting it to start once you have a full graphical environment up (with the script I have given if you ran systemctl --user enable servicename.service it would almost certainly start before your window manager, since I am not in Ubuntu I can't test). This might help (last response): https://superuser.com/questions/759759/writing-a-service-that-depends-on-xorg . They are an Ubuntu user that got a systemd service to run a graphical program after login.

If you can figure the start timing out you can create the service file, create/enable it at the end of your first script and then disable/delete it at the end of your second.

Sign up to request clarification or add additional context in comments.

2 Comments

Fantastic that helps I can see where I was going wrong now, cheers !! :)
this doesn't work and gives me a nasty error in syslogd - and I'm already logged in when it runs: "Warning: This program is an suid-root program or is being run by the root user. The full text of the error or warning message cannot be safely formatted in this environment. You may get a more descriptive message by running the program as a non-root user or by removing the suid bit on the executable. /usr/bin/xterm: Xt error: Can't open display: %s /usr/bin/xterm: DISPLAY is not set"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.