initial commit
This commit is contained in:
commit
561686795a
11 changed files with 270 additions and 0 deletions
47
01-raspi_image_editor.sh
Executable file
47
01-raspi_image_editor.sh
Executable file
|
@ -0,0 +1,47 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
print('##################################################\n########### Raspberry Pi Image Editor ############\n##################################################')
|
||||
echo ""
|
||||
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
echo " 1 = hostname"
|
||||
echo " 2 = path to boot partition"
|
||||
echo " 3 = path to system partition"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
file_dir="files"
|
||||
|
||||
wpa_file="$file_dir/wpa_supplicant.conf"
|
||||
interfaces_file="$file_dir/interfaces"
|
||||
hostname="$1"
|
||||
path_boot="$2"
|
||||
path_system="$3"
|
||||
|
||||
if [ ! -f "$path_boot/config.txt" ]
|
||||
then
|
||||
echo "ERROR! Not a boot partition"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ ! -f "$path_system/etc/fstab" ]
|
||||
then
|
||||
echo "ERROR! Not a sytem partition"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Editing hostname
|
||||
echo $hostname > $file_dir/hostname
|
||||
|
||||
sed -i '$d' $file_dir/hosts
|
||||
echo "127.0.1.1 $hostname" >> $file_dir/hosts
|
||||
|
||||
# Copying files
|
||||
cp hosts "$path_system/etc/hosts"
|
||||
cp hostname "$path_system/etc/hostname"
|
||||
cp $file_dir/$wpa_file "$path_boot"
|
||||
touch $path_boot/ssh
|
||||
# chmod 644 "$path_system/etc/wpa_supplicant/$wpa_file"
|
||||
# cp $interfaces_file "$path_system/etc/network/$interfaces_file"
|
||||
# chmod 644 "$path_system/etc/network/$interfaces_file"
|
33
02-raspi_pusher.sh
Executable file
33
02-raspi_pusher.sh
Executable file
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
echo "Raspi pusher"
|
||||
echo ""
|
||||
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
echo " 1 = hostname"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
file_dir="files"
|
||||
user="pi"
|
||||
hostname="$1"
|
||||
ip=$(hostname -I)
|
||||
ssh-copy-id -i $HOME/.ssh/id_rsa.pub $user@$hostname
|
||||
ssh $user@$hostname -C "sudo passwd $user"
|
||||
ssh $user@$hostname -C "mkdir ~/bin ~/tmp"
|
||||
scp $file_dir/cputemp.sh $user@$hostname:~/bin/
|
||||
ssh $user@$hostname -C "sudo timedatectl set-timezone Europe/Zurich"
|
||||
|
||||
### uncomment to deactivate unneeded resources on startup (perfect for BOINC)
|
||||
# scp $file_dir/raspicron $user@$hostname:~
|
||||
# ssh $user@$hostname -C "crontab ~/raspicron && rm ~/raspicron"
|
||||
# ssh $user@$hostname -C "cat /etc/hostname; ~/bin/cputemp.sh"
|
||||
# ssh $user@$hostname -C "echo 0 | sudo tee /sys/devices/platform/soc/3f980000.usb/buspower"
|
||||
# ssh $user@$hostname -C "sudo tvservice --off"
|
||||
|
||||
ssh $user@$hostname -C "sudo apt update && sudo apt upgrade -y"
|
||||
ssh $user@$hostname -C "sudo apt install vim-nox boinc-client -y"
|
||||
ssh $user@$hostname -C "echo $ip | sudo tee -a /etc/boinc-client/remote_hosts.cfg"
|
||||
ssh $user@$hostname -C "sudo systemctl restart boinc-client"
|
||||
notify-send "Raspi is ready"
|
5
LICENSE
Normal file
5
LICENSE
Normal file
|
@ -0,0 +1,5 @@
|
|||
Copyright (C) YEAR by AUTHOR EMAIL
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
60
README.md
Normal file
60
README.md
Normal file
|
@ -0,0 +1,60 @@
|
|||
# Raspberry Pi Image Modification Automation
|
||||
|
||||
Modify \*.img fast doing following automatically:
|
||||
- update **wpa_supplicant.conf** to have a wifi connection ready on first startup
|
||||
- upload monitoring scripts like **cputemp.sh** to monitor the temperature
|
||||
- install **cronjobs**, which will be triggered on every boot or every x hours
|
||||
- edit the **hostname** before starting the operation system the first time
|
||||
|
||||
After modification the img file can be flashed on an sd card and is ready for a Raspberry Pi
|
||||
|
||||
## Why do I need this software?
|
||||
|
||||
I've configured a bunch of *Raspberry Pis* to crunch for [BOINC](https://utopify.org/boinc-what-is-it.html). This is a time consuming task and it was faster to create scripts, which are doing the important stuff automatically.
|
||||
|
||||
The important steps:
|
||||
|
||||
- change **hosts** and **hostname**
|
||||
- update **wpa_supplicant.conf** to connect to my router automatically after booting
|
||||
- activate **ssh**
|
||||
- change **password** on Raspberry Pi
|
||||
- make my host trustworthy to connect to the Raspi without a password
|
||||
- set my **time zonen**
|
||||
- install predefined **cronjobs** to monitor cpu temperature
|
||||
- install predefined **cronjobs** to deactivate unneeded resources on startup
|
||||
- update the operating system
|
||||
- install **vim** and **boinc**
|
||||
- make my host able to connect with **boincmgr**
|
||||
- restart **boinc service** to be able to connect to it and configure it with [BAM!](https://www.boincstats.com/bam) (a boinc account manager)
|
||||
|
||||
And that's it! With this tools I got a ready-to-go system within seconds.
|
||||
|
||||
## How to use it?
|
||||
|
||||
1. Download the headless (no GUI) version of [Raspberry Pi OS](https://www.raspberrypi.com/software/operating-systems/), which is called *Raspberry Pi OS Lite* or similar Debian based distributions.
|
||||
2. Mount the two partitions of the image file where you want to, but you have to remember the paths (you need root privileges)
|
||||
```
|
||||
sudo losetup -P /dev/loop0p1 2021-01-11-raspios-buster-armhf-lite.img
|
||||
sudo mount /dev/loop1p1 ~/mnt/image1
|
||||
sudo mount /dev/loop1p2 ~/mnt/image2
|
||||
```
|
||||
3. Execute **01-raspi_image_editor.sh** with the paths of the **partitions** and your chosen **hostname**
|
||||
```
|
||||
sudo ./raspi_image_editor.sh raspi3no5 ~/mnt/image1 ~/mnt/image2
|
||||
```
|
||||
4. Unmount partitions and release the loop device
|
||||
```
|
||||
sudo umount ~/mnt/image1
|
||||
sudo umount ~/mnt/image2
|
||||
sudo losetup -d /dev/loop1
|
||||
```
|
||||
5. Flash the new image on your sd card and trigger a notification if it's done. ATTENTION!!! Change sdXXX to the one your sd card has. You can find it out with the following command: `lsblk`
|
||||
```
|
||||
sudo dd if=/home/maxmoon/os_images/2021-01-11-raspios-buster-armhf-lite.img of=/dev/sdXXX conv=fsync bs=4M && notify-send "Raspi is ready" || notify-send "ERROR" -u critical
|
||||
```
|
||||
6. Insert sd card into the Raspi and power it on
|
||||
7. Execute **02-raspi_pusher.sh** and follow the instructions
|
||||
|
||||
*Congratulations! Your Raspi is ready!*
|
||||
|
||||
After that you can connect with **ssh** or **boincmgr** from your host system to your raspi and control the BOINC tasks.
|
69
files/config.txt
Executable file
69
files/config.txt
Executable file
|
@ -0,0 +1,69 @@
|
|||
# For more options and information see
|
||||
# http://rpf.io/configtxt
|
||||
# Some settings may impact device functionality. See link above for details
|
||||
|
||||
# uncomment if you get no picture on HDMI for a default "safe" mode
|
||||
#hdmi_safe=1
|
||||
|
||||
# uncomment this if your display has a black border of unused pixels visible
|
||||
# and your display can output without overscan
|
||||
#disable_overscan=1
|
||||
|
||||
# uncomment the following to adjust overscan. Use positive numbers if console
|
||||
# goes off screen, and negative if there is too much border
|
||||
#overscan_left=16
|
||||
#overscan_right=16
|
||||
#overscan_top=16
|
||||
#overscan_bottom=16
|
||||
|
||||
# uncomment to force a console size. By default it will be display's size minus
|
||||
# overscan.
|
||||
#framebuffer_width=1280
|
||||
#framebuffer_height=720
|
||||
|
||||
# uncomment if hdmi display is not detected and composite is being output
|
||||
#hdmi_force_hotplug=1
|
||||
|
||||
# uncomment to force a specific HDMI mode (this will force VGA)
|
||||
#hdmi_group=1
|
||||
#hdmi_mode=1
|
||||
|
||||
# uncomment to force a HDMI mode rather than DVI. This can make audio work in
|
||||
# DMT (computer monitor) modes
|
||||
#hdmi_drive=2
|
||||
|
||||
# uncomment to increase signal to HDMI, if you have interference, blanking, or
|
||||
# no display
|
||||
#config_hdmi_boost=4
|
||||
|
||||
# uncomment for composite PAL
|
||||
#sdtv_mode=2
|
||||
|
||||
#uncomment to overclock the arm. 700 MHz is the default.
|
||||
#arm_freq=800
|
||||
|
||||
# Uncomment some or all of these to enable the optional hardware interfaces
|
||||
#dtparam=i2c_arm=on
|
||||
#dtparam=i2s=on
|
||||
#dtparam=spi=on
|
||||
|
||||
# Uncomment this to enable infrared communication.
|
||||
#dtoverlay=gpio-ir,gpio_pin=17
|
||||
#dtoverlay=gpio-ir-tx,gpio_pin=18
|
||||
|
||||
# Additional overlays and parameters are documented /boot/overlays/README
|
||||
|
||||
# Enable audio (loads snd_bcm2835)
|
||||
dtparam=audio=on
|
||||
|
||||
[pi4]
|
||||
# Enable DRM VC4 V3D driver on top of the dispmanx display stack
|
||||
dtoverlay=vc4-fkms-v3d
|
||||
max_framebuffers=2
|
||||
|
||||
[all]
|
||||
#dtoverlay=vc4-fkms-v3d
|
||||
|
||||
# custom flags
|
||||
# disable bluetooth
|
||||
dtoverlay=disable-bt
|
14
files/cputemp.sh
Executable file
14
files/cputemp.sh
Executable file
|
@ -0,0 +1,14 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# epoch
|
||||
time=$(date +%s)
|
||||
|
||||
# Load
|
||||
load1=$(cat /proc/loadavg | awk '{print $1}')
|
||||
|
||||
# Temperatur
|
||||
cpuTT=$(cat /sys/class/thermal/thermal_zone0/temp | awk '{printf "%.1f", $1/1000}')
|
||||
|
||||
#Ausgabe
|
||||
echo $time';'$load1';'$cpuTT
|
||||
|
1
files/hostname
Normal file
1
files/hostname
Normal file
|
@ -0,0 +1 @@
|
|||
rp4b1
|
5
files/hosts
Normal file
5
files/hosts
Normal file
|
@ -0,0 +1,5 @@
|
|||
127.0.0.1 localhost
|
||||
::1 localhost ip6-localhost ip6-loopback
|
||||
ff02::1 ip6-allnodes
|
||||
ff02::2 ip6-allrouters
|
||||
127.0.1.1 rp4b1
|
16
files/interfaces
Normal file
16
files/interfaces
Normal file
|
@ -0,0 +1,16 @@
|
|||
# interfaces(5) file used by ifup(8) and ifdown(8)
|
||||
|
||||
# Please note that this file is written to be used with dhcpcd
|
||||
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
|
||||
|
||||
auto lo
|
||||
iface lo inet loopback
|
||||
|
||||
allow-hotplug wlan0
|
||||
iface wlan0 inet manual
|
||||
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
|
||||
post-up ifdown eth0
|
||||
iface default inet dhcp
|
||||
|
||||
# Include files from /etc/network/interfaces.d:
|
||||
source-directory /etc/network/interfaces.d
|
13
files/raspicron
Normal file
13
files/raspicron
Normal file
|
@ -0,0 +1,13 @@
|
|||
# Example of job definition:
|
||||
# .---------------- minute (0 - 59)
|
||||
# | .------------- hour (0 - 23)
|
||||
# | | .---------- day of month (1 - 31)
|
||||
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
|
||||
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
|
||||
# | | | | |
|
||||
# * * * * * user-name command to be executed
|
||||
|
||||
@reboot sudo tvservice --off
|
||||
@reboot echo 0 | sudo tee /sys/devices/platform/soc/3f980000.usb/buspower
|
||||
*/15 * * * * ~/bin/cputemp.sh >> ~/tmp/cputemp
|
||||
0 * * * * echo "$(date +\%s);$(($(cat /sys/class/net/[ew]*/statistics/rx_bytes | paste -sd '+')))" >> ~/tmp/bandwidth
|
7
files/wpa_supplicant.conf
Normal file
7
files/wpa_supplicant.conf
Normal file
|
@ -0,0 +1,7 @@
|
|||
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
|
||||
update_config=1
|
||||
country=DE
|
||||
network={
|
||||
ssid="Your SSID"
|
||||
psk=00000000000000000000000000000000000000
|
||||
}
|
Loading…
Reference in a new issue