Latest Pi OS and Pi Imager. It works to set up the user and login to the network. What i am now looking for is something like firstrun.sh but for the user created during the firstrun.
I set up a user named berry. The user directory does not exist until after the firstrun.sh completes and there is a reboot. I cannot put something in the new directory when creating the card. Could I set up something to copy userfirstrun.sh into the new user?
userfirstrun.sh needs the Internet connected so has to run after the firstrun reboot. The best use of userfirstrun.sh would be to run in the user's desktop after the user is automatically logged in as that would let the user see progress and any messages about problems.
The process would have to wait for the network to connect. I notice the WiFi connection to the Internet blinks for a few seconds before indicating a connection. Is there a way to detect that?
The alternative might be to place userfirstrun.sh somewhere else on the card then run it by hand. If I cannot find anything better, I might just set up another partition at the end of the card for extras.
Re: Pi Imager -> firstrun new user?
i've used these before, don't forget to cleanup afters your script runs, so it don't keep going at each boot, just sed/rm it out.
/etc/skel
and
/etc/xdg/lxsession/LXDE-pi/autostart
there's also rc.local, but it runs as root, etc....
/etc/skel
and
/etc/xdg/lxsession/LXDE-pi/autostart
there's also rc.local, but it runs as root, etc....
Re: Pi Imager -> firstrun new user?
Take a look at sdm (https://github.com/gitbls/sdm). It can do what you need and a LOT more (there is a not insignificant learning curve so it may be more than you need).
I am using it to (via easily repeatable scripts):
- setup all the usual first configuration settings,
- configure RealVNC, including custom setting (IdleTimeout),
- copy a number of standard scripts to /home/newuser/bin,
- install MQTT/Mosquitto and systemd service which reports miscellaneous system stats to a Node-RED dashboard running on a central RPi,
- install BlueDot to give me some minimal reboot/shutdown controls in case I can't access my headless RPi via VNC/SSH for some reason,
- add fstab entry for my RPi4 based NAS,
- download, unzip, and install RonR's image-file-utilities (viewtopic.php?t=332000),
- create crontab entry to perform incremental backup every night,
- create crontab entry to send periodic 'ping's to healtchecks.io so I'll get email if an RPi is down
I am using it to (via easily repeatable scripts):
- setup all the usual first configuration settings,
- configure RealVNC, including custom setting (IdleTimeout),
- copy a number of standard scripts to /home/newuser/bin,
- install MQTT/Mosquitto and systemd service which reports miscellaneous system stats to a Node-RED dashboard running on a central RPi,
- install BlueDot to give me some minimal reboot/shutdown controls in case I can't access my headless RPi via VNC/SSH for some reason,
- add fstab entry for my RPi4 based NAS,
- download, unzip, and install RonR's image-file-utilities (viewtopic.php?t=332000),
- create crontab entry to perform incremental backup every night,
- create crontab entry to send periodic 'ping's to healtchecks.io so I'll get email if an RPi is down
Re: Pi Imager -> firstrun new user?
SDM sounds like both overkill, underkill, and it would conflict with Pi imager.
I have scripts for things like installing a WiFi driver. Given that the example USB WiFi adaptor could be plugged in anywhere, I install the drivers in every machine. The same with replacing a Web browser and some other things. From what I read of SDM, it does not do some of the things I want which means using my scripts. I would look at it in more detail if I had not created my scripts.
I started using the Pi Imager for some basics and like it so far. I am looking for a way to augment the Pi Imager rather than replace it.
What I tested with success this afternoon was:
Create card with Pi Imager.
Add 100 MB Ext4 partition, extras, at end of card with Gparted.
Expand rootfs with Gparted as the automatic expand does not happen when there is an extra partition.
Load scripts into extras.
Run the scripts in extras.
I have one overall script that runs whatever I have loaded. I will run it manually while I study firstrun.sh.
I have scripts for things like installing a WiFi driver. Given that the example USB WiFi adaptor could be plugged in anywhere, I install the drivers in every machine. The same with replacing a Web browser and some other things. From what I read of SDM, it does not do some of the things I want which means using my scripts. I would look at it in more detail if I had not created my scripts.
I started using the Pi Imager for some basics and like it so far. I am looking for a way to augment the Pi Imager rather than replace it.
What I tested with success this afternoon was:
Create card with Pi Imager.
Add 100 MB Ext4 partition, extras, at end of card with Gparted.
Expand rootfs with Gparted as the automatic expand does not happen when there is an extra partition.
Load scripts into extras.
Run the scripts in extras.
I have one overall script that runs whatever I have loaded. I will run it manually while I study firstrun.sh.
Re: Pi Imager -> firstrun new user?
/etc/skel sounds like it will run at the start of every user creation on a machine. I will read further. I could put something there then delete it after first use. /etc/skel will be my next test.
rc.local runs before the login which is not what I want.
rc.local runs before the login which is not what I want.
Re: Pi Imager -> firstrun new user?
It is open sourced, branch it, make your changes and ask for a code merge.
https://github.com/raspberrypi/rpi-imager
If they choose not to include your changes in the imager, you still have your own version working as you need it to.
https://github.com/raspberrypi/rpi-imager
If they choose not to include your changes in the imager, you still have your own version working as you need it to.
-
- Posts: 1227
- Joined: Tue Oct 30, 2018 3:34 pm
Re: Pi Imager -> firstrun new user?
User directory should exist near the end of firstrun.sh, so put your own stuff before the "exit" command.
Create a .desktop file for your GUI application and put it in the user's autostart folder at end of firstrun.sh?The best use of userfirstrun.sh would be to run in the user's desktop after the user is automatically logged in as that would let the user see progress and any messages about problems.
On most Linux desktop environments the user specific autostart folder for user "berry" would be /home/berry/.config/autostart
Note that while the user's home directory should exists at the end of the firstrun.sh, the subdirectories like .config will not.
So make sure you create them in your script.
Among the lines of:
Code: Select all
mkdir -p /home/berry/.config/autostart
cat << EOF > /home/berry/.config/autostart/myapp.desktop
[Desktop Entry]
Type=Application
Version=1.0
Name=My app
Exec=command-that-starts-your-gui-application
EOF
chown -R berry:berry /home/berry/.config
If you don't have a GUI app, but a shell script, then you can try a .desktop file among the lines of:
Code: Select all
[Desktop Entry]
Type=Application
Version=1.0
Name=Script
Exec=/home/berry/yourscript.sh
Terminal=true
Re: Pi Imager -> firstrun new user?
Current status after about 50 tests.
~/.config/autostart/start.desktop
I place it in /home/pi/.config/autostart/ and pi is renamed to berry. start.desktop does run and start the script but the terminal window never appears.
Name[en_AU]=start.desktop just appeared when I renamed the file.
~/.config/lxsession/LXDE-pi/autostart
I place it in /home/pi/. install.b.sh does run and start the script but the terminal window never appears.
To make a window appear, I moved all the code out of start.a.sh into install.a.sh. start.a.sh is now:
A terminal window does appear for install.a.sh and it does remain open after the script finishes but there is an empty window also opened. I will experiment with variations of exec bash and exec $SHELL.
~/.config/autostart/start.desktop
Code: Select all
[Desktop Entry]
Version=1.0
Name=Test 5 lxterminal
Comment=Test the terminal running a command inside it
Exec=lxterminal -e ~/start.a.sh
Icon=lxterminal
Type=Application
Name[en_AU]=start.desktop
Name[en_AU]=start.desktop just appeared when I renamed the file.
~/.config/lxsession/LXDE-pi/autostart
Code: Select all
@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@xscreensaver -no-splash
@bash install.b.sh
To make a window appear, I moved all the code out of start.a.sh into install.a.sh. start.a.sh is now:
Code: Select all
#!/bin/bash
lxterminal -e "bash -c ~/install.a.sh;exec bash"
exec $SHELL
Re: Pi Imager -> firstrun new user?
Your "sdm sounds like" is based on your observation point and without a very deep look.peterlite wrote: ↑Fri Mar 17, 2023 10:04 amSDM sounds like both overkill, underkill, and it would conflict with Pi imager.
I have scripts for things like installing a WiFi driver. Given that the example USB WiFi adaptor could be plugged in anywhere, I install the drivers in every machine. The same with replacing a Web browser and some other things. From what I read of SDM, it does not do some of the things I want which means using my scripts. I would look at it in more detail if I had not created my scripts.
I started using the Pi Imager for some basics and like it so far. I am looking for a way to augment the Pi Imager rather than replace it.
What I tested with success this afternoon was:
Create card with Pi Imager.
Add 100 MB Ext4 partition, extras, at end of card with Gparted.
Expand rootfs with Gparted as the automatic expand does not happen when there is an extra partition.
Load scripts into extras.
Run the scripts in extras.
I have one overall script that runs whatever I have loaded. I will run it manually while I study firstrun.sh.
And, most importantly, I want to mention that there is no conflict with sdm and Pi imager. You can easily use both if you choose.
If you already have scripts that work, they can be easily adopted to working with sdm. This would give you all the advantages of sdm along with your customizations. Some tweaks to your scripts may be required, but it's quite easy to extend sdm with your own personal plugins. sdm provides a framework where your personal customizations can be done in a structured way. And, since they are just bash scripts, if you decide to move away from using sdm at some point, your code moves away easily.
What do I mean by "observation points"?
If someone is using, for example, pi-gen (another tool for configuring RasPiOS IMGs, they may be more inclined to use `dd` to burn disks, because they have exhibited an interest in fine-grain control over their IMG contents.
If someone is using sdm, they would probably use sdm to burn their disks, although there is no requirement to do so. But, sdm has several features that are attractive to some users.
Similarly, if someone finds that using pi-imager meets their customization and burning requirements, they will be less likely to use either pi-gen or sdm. And, while pi-imager can and will be extended, there are some limitations to what it can do. Most (all?) of the Pi-imager customizations are done at burn time, which can be a constraint for some users.
In general, pi-gen, sdm, and pi-imager address different aspects of the same problem: How to customize and burn your RasPiOS IMGs.
sdm enables me to take the standard RasPiOS distribution IMGs and get them set up EXACTLY as I need for my environment. This means that I do ZERO customization after the system boots. I'm ready to run experiments, test new software, etc, without having to remember what I might have done to the running system that perturbed it in some problematic way.
I did a writeup comparing pi-gen, sdm, and pi-imager including a brief overview and pros/cons of each.
If you're interested in pursuing sdm further, happy to help anyone get over the small learning curve. HMU at https://github.com/gitbls/sdm/discussions
Pi tools:
Quickly and easily build customized exactly as-you-want SSDs/SD Cards: https://github.com/gitbls/sdm
Easily run and manage your network's DHCP/DNS servers on a Pi: https://github.com/gitbls/ndm
Easy and secure IPSEC/IKEV2 VPN installer/manager: https://github.com/gitbls/pistrong
Lightweight Virtual VNC Config: https://github.com/gitbls/RPiVNCHowTo
Quickly and easily build customized exactly as-you-want SSDs/SD Cards: https://github.com/gitbls/sdm
Easily run and manage your network's DHCP/DNS servers on a Pi: https://github.com/gitbls/ndm
Easy and secure IPSEC/IKEV2 VPN installer/manager: https://github.com/gitbls/pistrong
Lightweight Virtual VNC Config: https://github.com/gitbls/RPiVNCHowTo
-
- Posts: 1227
- Joined: Tue Oct 30, 2018 3:34 pm
Re: Pi Imager -> firstrun new user?
1) It is more common to place "Terminal=true" in your .desktop and point Exec= to your script
2) in both cases the terminal window is likely to close once your script is finished. Try adding "sleep 30" at the end of the script being executed to make it wait for a while first. Or a construct like:
Code: Select all
read -n1 -p "Press a key to continue"
Re: Pi Imager -> firstrun new user?
Thank you for the comparison between sdm and other options. "command-line interface" No thank you. I am trying to minimise that. Raspberry Pi OS only. No thank you. I occasionally want to test other options. The Pi installer currently gives me a good starting point now I know how the user is created.
My scripts are currently function oriented and can run independent of the initial install. When i want remote access as part of the install, I just include the script for remote access and it is run the first time the user logs in. If I want to add remote access to an existing install, I can run the remote access script at any time.
Just need a few more experiments with making the terminal window cooperate.
My scripts are currently function oriented and can run independent of the initial install. When i want remote access as part of the install, I just include the script for remote access and it is run the first time the user logs in. If I want to add remote access to an existing install, I can run the remote access script at any time.
Just need a few more experiments with making the terminal window cooperate.
Re: Pi Imager -> firstrun new user?
The great thing about Linux is that there are many ways to do just about everything, so everyone can typically find a way that works for them.peterlite wrote: ↑Sun Mar 19, 2023 12:35 amThank you for the comparison between sdm and other options. "command-line interface" No thank you. I am trying to minimise that. Raspberry Pi OS only. No thank you. I occasionally want to test other options. The Pi installer currently gives me a good starting point now I know how the user is created.
My scripts are currently function oriented and can run independent of the initial install. When i want remote access as part of the install, I just include the script for remote access and it is run the first time the user logs in. If I want to add remote access to an existing install, I can run the remote access script at any time.
Just need a few more experiments with making the terminal window cooperate.
Enjoy!
Pi tools:
Quickly and easily build customized exactly as-you-want SSDs/SD Cards: https://github.com/gitbls/sdm
Easily run and manage your network's DHCP/DNS servers on a Pi: https://github.com/gitbls/ndm
Easy and secure IPSEC/IKEV2 VPN installer/manager: https://github.com/gitbls/pistrong
Lightweight Virtual VNC Config: https://github.com/gitbls/RPiVNCHowTo
Quickly and easily build customized exactly as-you-want SSDs/SD Cards: https://github.com/gitbls/sdm
Easily run and manage your network's DHCP/DNS servers on a Pi: https://github.com/gitbls/ndm
Easy and secure IPSEC/IKEV2 VPN installer/manager: https://github.com/gitbls/pistrong
Lightweight Virtual VNC Config: https://github.com/gitbls/RPiVNCHowTo
Re: Pi Imager -> firstrun new user?
The following works for what i want.
Code: Select all
lxterminal -e "bash -c ~/install.a.sh;exec bash"
Re: Pi Imager -> firstrun new user?
Did not work for me. I tested lots of combinations but none showed a terminal window or left it open. The best I could get is to execute a script that then opened a terminal window for a second script. I have .desktop running the invisible start.sh which runs the visible install.sh.It is more common to place "Terminal=true" in your .desktop and point Exec= to your script
Thank you everyone for the suggestions. .config/autostart -> start.sh -> install.sh is working.