Is there a way to cause noobs to install apache and php during setup, or perhaps leave a script which will do that upon first boot? And then copy info into /var/www? Basically what I want is a way to get a headless pi to setup a webserver with no input from me once I have put in the sd card.
I would recommend FooDeas/raspberrypi-ua-netinst as the base for making your installer. Download a released zip, configure a few files, put it on the SD Card, put the card in your Pi and it will boot up and install however you choose without needing any further intervention.
I have written a blog post here that explains how to turn it into an installer that can do anything you want. (By showing how to automatically install NodeJS). There are a number of ways raspberrypi-ua-netinst can be made to perform complex installations but I only explore one method fully (both here and in my blog).
The raspberrypi-ua-netinst installer, as it is, is slightly limited. As it is, you can easily do the following:
- Supply a list of packages which it installs with
- Supply a set of files which will be loaded onto the final image.
- Provide (limited) scripts to run during the install, prior to first boot.
Both are explained at its homepage on github.
The biggest limitation is that the installer (and scripts you choose to run with it, such as
post-install.txt) are done so on
busybox which is a minimal shell with few tools.
There is a discussion here on how to take the installer further here. The user "netdesk" explains why the installer by itself is slightly limited, and solutions are explored. Please note the discussion is for raspbian-ua-netinst, not raspberrypi-ua-netinst. The latter is the one I prefer, as it has some useful extra features - the former is the original. But they are almost identical in how they work.
My blog article gives one possible solution: it explains how to bundle a
.bashrc file with the installer, and some systemd service files that do the following:
- The systemd files ensure that when the installer is done and reboots that the system automatically logs in.
- The .bashrc file ensures that when it logs in that first time, it performs the remaining installation that you choose in the full Raspbian rather than busybox, which makes it a whole lot easier.
You can monitor the entire install process via the UART if you connect a serial-to-USB converter to the Pi's UART GPIO pins and the USB of your PC or similar (using Putty if you're on windows). The systemd files make it log in as root with input/output via the UART so you can easily interact with it without having to rely on a working SSH connection.
Just change the contents of
on-first-login.sh to perform the remaining configuration of your system, eg install and configure Apache etc. You can bundle your files for
/var/www with the installer files directly on the SD card.
In case my blog goes down or whatever, the key to my method is you create a file with this in it:
# This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # Modified from /lib/systemd/system/serial-getty@.service [Unit] Description=Serial Getty on %I Documentation=man:agetty(8) man:systemd-getty-generator(8) Documentation=http://0pointer.de/blog/projects/serial-console.html BindsTo=dev-%i.device After=dev-%i.device systemd-user-sessions.service plymouth-quit-wait.service After=rc-local.service # If additional gettys are spawned during boot then we should make # sure that this is synchronized before getty.target, even though # getty.target didn't actually pull it in. Before=getty.target IgnoreOnIsolate=yes [Service] # ExecStart=-/sbin/agetty --keep-baud 115200,38400,9600 %I $TERM ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud 115200,38400,9600 %I $TERM Type=idle Restart=always UtmpIdentifier=%I TTYPath=/dev/%I TTYReset=yes TTYVHangup=yes KillMode=process IgnoreSIGPIPE=no SendSIGHUP=yes [Install] WantedBy=getty.target
And ensure this gets put in two places in the final installation:
Then just create some script, and in
/root/.bashrc call your script, and ensure the script will not get called in future.
There are other possible solutions; in the issue discussion, one person explains how he made his own repository and package which he configured the installer to use. He also posted a link to the source. And there are one or two other suggestions as well.
My method isn't perfect, but for the sake of keeping things short I will leave it as it is - it will get you off the ground. Mainly I suggest reviewing secirity since everything is done as root. But please do let me know if you have any issues or suggestions.
Yes, there is.
/etc/init.d is where you want to put your script in and also you should make it executable, otherwise it wouldn't work. Write the script in
/etc/init.d/yourscript. Make it executable by
chmod +x /etc/init.d/yourscript or
chmod 775 /etc/init.d/yourscript. You might also need to type
sudo before the codes I've written above. Then check this tutorial for writing your script: http://linuxconfig.org/bash-scripting-tutorial . I suggest you to put some sleep between codes (its trivial) so no problem would occur.
Since you are using Pi headless and you don't want to touch it you'll need it to loging automatically for things to happen, http://www.opentechguides.com/how-to/article/raspberry-pi/5/raspberry-pi-auto-start.html (there is also a method for running a script after login in this guide and it can take part of Script part as well)
The things you want in your script are including
sudo apt-get install what_ever_you_want,
cd /var/www | cat > info.txt for quickly creating a text file and also some
sleep n. But, if you choose to use the article I pasted in Autologin part, the script there works after login so you might not need to use
Hope this helps.