2017-03-13 13:55:48 +01:00
|
|
|
#!/bin/bash
|
2020-04-29 10:08:43 +02:00
|
|
|
echo "Setupscript for Raspberry Pi SD's"
|
2018-05-07 13:00:08 +02:00
|
|
|
echo
|
2020-04-29 10:08:43 +02:00
|
|
|
echo "@author Kevin Veen-Birkenbach [kevin@veen.world]"
|
2017-03-13 13:55:48 +01:00
|
|
|
echo "@since 2017-03-12"
|
2018-05-07 13:00:08 +02:00
|
|
|
echo
|
2020-04-29 10:08:43 +02:00
|
|
|
echo "The images will be stored in /home/\$username/images/."
|
|
|
|
tmp_folder="/tmp/raspberry-pi-tools-$(date +%s)";
|
|
|
|
echo "Create temporary working folder in $tmp_folder";
|
|
|
|
if [ $(id -u) != 0 ];then
|
|
|
|
echo "This script must be executed as root!" && exit 1
|
2017-03-13 16:26:33 +01:00
|
|
|
fi
|
2020-04-29 10:08:43 +02:00
|
|
|
echo "Please type in the username from which the SSH-Key should be copied:"
|
|
|
|
read username;
|
|
|
|
image_folder="/home/$username/images/";
|
|
|
|
echo "List of actual mounted devices:"
|
2018-05-07 13:00:08 +02:00
|
|
|
echo
|
2017-04-13 22:56:50 +02:00
|
|
|
ls -lasi /dev/ | grep -E "sd|mm"
|
2017-03-13 13:55:48 +01:00
|
|
|
echo
|
2017-03-13 16:26:33 +01:00
|
|
|
while [ \! -b "$ofi" ]
|
2017-03-13 13:55:48 +01:00
|
|
|
do
|
2020-04-29 10:08:43 +02:00
|
|
|
echo "Please select the correct SD-Card."
|
2017-03-13 13:55:48 +01:00
|
|
|
echo "/dev/:"
|
|
|
|
read device
|
2018-05-07 13:00:08 +02:00
|
|
|
ofi="/dev/$device"
|
|
|
|
done
|
2017-03-13 13:55:48 +01:00
|
|
|
while [ "$workingpath" == "" ]
|
|
|
|
do
|
|
|
|
echo "Bitte waehlen Sie den Arbeitspfad zu $(pwd) aus:"
|
|
|
|
read workingpath
|
|
|
|
if [ "${workingpath:0:1}" != "/" ]
|
|
|
|
then
|
|
|
|
workingpath=$(pwd)"/"$workingpath
|
|
|
|
fi
|
2017-03-13 16:26:33 +01:00
|
|
|
if [ -d "$workingpath" ]
|
2017-03-13 13:55:48 +01:00
|
|
|
then
|
2017-03-13 16:26:33 +01:00
|
|
|
i=$((${#workingpath}-1)) #Letzte Zeichenstelle ermitteln
|
|
|
|
if [ "${workingpath:$i:1}" != "/" ]
|
2018-05-07 13:00:08 +02:00
|
|
|
then
|
|
|
|
workingpath=$workingpath"/"
|
|
|
|
fi
|
2017-03-13 13:55:48 +01:00
|
|
|
else
|
|
|
|
echo "Der ausgewaehlte Arbeitspfad existiert nicht."
|
|
|
|
workingpath=""
|
|
|
|
fi
|
|
|
|
|
2017-04-13 23:12:59 +02:00
|
|
|
done
|
2020-04-29 10:08:43 +02:00
|
|
|
echo "Which raspberry pi version do you want to use?"
|
2018-05-07 13:00:08 +02:00
|
|
|
read version
|
2020-04-29 10:08:43 +02:00
|
|
|
echo "Image for RaspberryPi $version will be used..."
|
|
|
|
echo "Which OS do you want to use?"
|
|
|
|
echo "1) arch"
|
|
|
|
echo "2) moode"
|
|
|
|
echo "3) retropie"
|
|
|
|
echo "Please type in the os:"
|
|
|
|
read os
|
|
|
|
case "$os" in
|
|
|
|
"arch")
|
|
|
|
base_download_url="http://os.archlinuxarm.org/os/";
|
|
|
|
case "$version" in
|
|
|
|
"1")
|
|
|
|
imagename="ArchLinuxARM-rpi-latest.tar.gz"
|
|
|
|
;;
|
|
|
|
"2" | "3")
|
|
|
|
imagename="ArchLinuxARM-rpi-2-latest.tar.gz"
|
|
|
|
;;
|
|
|
|
"4")
|
|
|
|
imagename="ArchLinuxARM-rpi-4-latest.tar.gz"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "ArchLinux for RaspberryPi Version $version is not supported!" && exit 1;
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
downloadurl="http://os.archlinuxarm.org/os/$imagename"
|
|
|
|
;;
|
|
|
|
"moode")
|
|
|
|
imagename="moode-r651-iso.zip";
|
|
|
|
downloadurl="https://github.com/moode-player/moode/releases/download/r651prod/moode-r651-iso.zip";
|
|
|
|
;;
|
|
|
|
"retropie")
|
|
|
|
base_download_url="https://github.com/RetroPie/RetroPie-Setup/releases/download/4.6/";
|
|
|
|
case "$version" in
|
|
|
|
"1")
|
|
|
|
imagename="retropie-buster-4.6-rpi1_zero.img.gz"
|
|
|
|
;;
|
|
|
|
|
|
|
|
"2" | "3")
|
|
|
|
imagename="retropie-buster-4.6-rpi2_rpi3.img.gz"
|
|
|
|
;;
|
|
|
|
|
|
|
|
"4")
|
|
|
|
imagename="retropie-buster-4.6-rpi4.img.gz"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "RetroPie for RaspberryPi Version $version is not supported!" && exit 1;
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
downloadurl="$base_download_url$imagename"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "The operation system \"$os\" is not supported yet!" && exit 1;
|
|
|
|
;;
|
|
|
|
esac
|
2017-04-13 23:12:59 +02:00
|
|
|
while [ "$imagepath" == "" ]
|
|
|
|
do
|
2018-05-07 13:00:08 +02:00
|
|
|
echo "Setzen Sie den Imagenamen(Standart:$workingpath$imagename)"
|
2017-04-13 23:12:59 +02:00
|
|
|
read image
|
|
|
|
if [ "$image" == "" ]
|
2018-05-07 13:00:08 +02:00
|
|
|
then
|
|
|
|
imagepath=$workingpath$imagename
|
2017-04-13 23:12:59 +02:00
|
|
|
else
|
|
|
|
imagepath=$workingpath$image
|
|
|
|
fi
|
|
|
|
if [ \! -f "$imagepath" ]
|
2018-05-07 13:00:08 +02:00
|
|
|
then
|
2017-04-13 23:12:59 +02:00
|
|
|
echo "Das ausgewaehlte Image existiert nicht!"
|
|
|
|
#Image ggf. downloaden
|
|
|
|
if [ \! -f "$imagepath" ]
|
|
|
|
then
|
2018-05-07 13:00:08 +02:00
|
|
|
echo "Image wird gedownloadet..."
|
|
|
|
wget $downloadurl
|
2017-04-13 23:12:59 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2017-03-13 13:55:48 +01:00
|
|
|
done
|
2017-08-17 21:00:34 +02:00
|
|
|
|
2017-03-13 13:55:48 +01:00
|
|
|
echo "Die Arbeitsvariablen werden gesetzt..."
|
2018-05-07 13:00:08 +02:00
|
|
|
bootpath=$workingpath"boot"
|
2017-03-13 13:55:48 +01:00
|
|
|
rootpath=$workingpath"root"
|
2017-08-17 21:00:34 +02:00
|
|
|
|
|
|
|
ssh_key_source="/home/$user/.ssh/id_rsa.pub"
|
|
|
|
ssh_key_target="$rootpath/home/alarm/.ssh/authorized_keys"
|
|
|
|
|
2017-03-13 16:26:33 +01:00
|
|
|
if [ "${ofi:5:1}" != "s" ]
|
|
|
|
then
|
|
|
|
partion="p"
|
|
|
|
else
|
2018-05-07 13:00:08 +02:00
|
|
|
partion=""
|
2017-03-13 16:26:33 +01:00
|
|
|
fi
|
|
|
|
ofiboot=$ofi$partion"1"
|
|
|
|
ofiroot=$ofi$partion"2"
|
2017-03-13 13:55:48 +01:00
|
|
|
echo "Arbeitsverzeichnis: $workingpath"
|
|
|
|
echo "Rootpath: $rootpath"
|
|
|
|
echo "Bootpath: $bootpath"
|
|
|
|
echo "Imagepath: $imagepath"
|
2017-03-13 16:26:33 +01:00
|
|
|
echo "SD-Karte: $ofi"
|
|
|
|
echo "SD-Karte-Partition 1(boot): $ofiboot"
|
|
|
|
echo "SD-Karte-Partition 2(root): $ofiroot"
|
2017-08-17 21:00:34 +02:00
|
|
|
echo "SSH-Source-Path: $ssh_key_source"
|
|
|
|
echo "SSH-Target-Path: $ssh_key_target"
|
2017-03-13 13:55:48 +01:00
|
|
|
echo "Bestaetigen Sie mit der Enter-Taste. Zum Abbruch Ctrl + Alt + C druecken"
|
|
|
|
read bestaetigung
|
2017-03-13 16:26:33 +01:00
|
|
|
echo "fdisk wird ausgefuehrt..."
|
|
|
|
( echo "o" #Type o. This will clear out any partitions on the drive.
|
|
|
|
echo "p" #Type p to list partitions. There should be no partitions left
|
|
|
|
echo "n" #Type n,
|
|
|
|
echo "p" #then p for primary,
|
|
|
|
echo "1" #1 for the first partition on the drive,
|
|
|
|
echo "" #press ENTER to accept the default first sector,
|
|
|
|
echo "+100M" #then type +100M for the last sector.
|
|
|
|
echo "t" #Type t,
|
|
|
|
echo "c" #then c to set the first partition to type W95 FAT32 (LBA).
|
|
|
|
echo "n" #Type n,
|
|
|
|
echo "p" #then p for primary,
|
|
|
|
echo "2" #2 for the second partition on the drive,
|
|
|
|
echo "" #and then press ENTER twice to accept the default first and last sector.
|
2018-05-07 13:00:08 +02:00
|
|
|
echo ""
|
2017-03-13 16:26:33 +01:00
|
|
|
echo "w" #Write the partition table and exit by typing w.
|
2020-04-29 10:08:43 +02:00
|
|
|
)| fdisk "$ofi"
|
2017-03-13 16:26:33 +01:00
|
|
|
|
|
|
|
#Bootpartion formatieren und mounten
|
2017-03-13 13:55:48 +01:00
|
|
|
echo "Generiere und mounte boot-Partition..."
|
2020-04-29 10:08:43 +02:00
|
|
|
mkfs.vfat "$ofiboot"
|
|
|
|
mkdir "$bootpath"
|
|
|
|
mount "$ofiboot" "$bootpath"
|
2017-03-13 16:26:33 +01:00
|
|
|
|
|
|
|
#Rootpartition formatieren und mounten
|
2017-03-13 13:55:48 +01:00
|
|
|
echo "Generiere und mounte root-Partition..."
|
2020-04-29 10:08:43 +02:00
|
|
|
mkfs.ext4 "$ofiroot"
|
|
|
|
mkdir "$rootpath"
|
|
|
|
mount "$ofiroot" "$rootpath"
|
2017-03-13 16:26:33 +01:00
|
|
|
|
|
|
|
echo "Die Root-Dateien werden auf die SD-Karte aufgespielt..."
|
2020-04-29 10:08:43 +02:00
|
|
|
bsdtar -xpf "$imagepath" -C "$rootpath"
|
2017-03-13 13:55:48 +01:00
|
|
|
sync
|
2017-03-13 16:26:33 +01:00
|
|
|
|
|
|
|
echo "Die Boot-Dateien werden auf die SD-Karte aufgespielt..."
|
2020-04-29 10:08:43 +02:00
|
|
|
mv -v $rootpath"/boot/"* "$bootpath"
|
2017-03-13 16:26:33 +01:00
|
|
|
|
2017-08-17 21:00:34 +02:00
|
|
|
if [ "$user" != "" ] && [ -f "$ssh_key_source" ]
|
|
|
|
then
|
|
|
|
echo "Der SSH-Key wird auf den Raspberry kopiert..."
|
2018-05-07 13:00:08 +02:00
|
|
|
mkdir -v "$rootpath/home/alarm/.ssh"
|
2017-08-17 21:00:34 +02:00
|
|
|
cat "$ssh_key_source" > "$ssh_key_target"
|
|
|
|
chown -R 1000 "$rootpath/home/alarm/.ssh"
|
|
|
|
chmod -R 400 "$rootpath/home/alarm/.ssh"
|
2018-05-07 13:16:01 +02:00
|
|
|
echo "SSH File wird angelegt..."
|
|
|
|
echo "" > "$bootpath/ssh"
|
2017-08-17 21:00:34 +02:00
|
|
|
fi
|
|
|
|
|
2017-03-13 13:55:48 +01:00
|
|
|
echo "Script rauemt das Verzeichnis auf..."
|
2020-04-29 10:08:43 +02:00
|
|
|
umount "$rootpath" "$bootpath"
|
|
|
|
rm -r "$rootpath"
|
|
|
|
rm -r "$bootpath"
|