toastie89 4 years ago
parent
commit
ad41571e98
6 changed files with 264 additions and 1 deletions
  1. 1 1
      bluetooth.sh
  2. 26 0
      disk-selection.sh
  3. 15 0
      docker.sh
  4. 57 0
      download.sh
  5. 43 0
      mpd.sh
  6. 122 0
      prepare-sd-card.sh

+ 1 - 1
bluetooth.sh

@@ -49,4 +49,4 @@ pcm.!default {
 }
 }
 EOF
 EOF
 
 
-aplay /usr/share/sounds/alsa/Noise.wav
+aplay /usr/share/sounds/alsa/Noise.wav

+ 26 - 0
disk-selection.sh

@@ -0,0 +1,26 @@
+#!/bin/bash
+
+
+PS3="Select disk to install Raspbian: "
+select disk in `lsblk --include 8 --nodeps --output NAME --noheadings`
+do
+  echo "________________________________________________________________________"
+  lsblk --nodeps /dev/$disk --output TRAN,VENDOR,MODEL,HOTPLUG
+  echo "________________________________________________________________________"
+  lsblk /dev/$disk --output NAME,TYPE,FSTYPE,SIZE,LABEL,MOUNTPOINT
+  echo "________________________________________________________________________"
+  read -p "ARE YOU SURE TO OVERRIDE THIS DISK? (y/n) " -n 1 -r
+  echo #newline
+  if [[ $REPLY =~ ^[Yy]$ ]]; then
+    echo "Proceeding with $sdcard"
+    sdcard=/dev/$disk
+    break
+  fi
+done
+
+for part in \
+  `findmnt  --output SOURCE,TARGET --raw | grep $sdcard | cut -d" " -f2`
+  do sudo umount --verbose $part
+done
+
+

+ 15 - 0
docker.sh

@@ -0,0 +1,15 @@
+#!/bin/bash
+
+# https://dev.to/rohansawant/installing-docker-and-docker-compose-on-the-raspberry-pi-in-5-simple-steps-3mgl
+curl -sSL https://get.docker.com | sh
+sudo usermod -aG docker pi
+sudo apt-get install -y libffi-dev libssl-dev python3 python3-pip
+sudo pip3 install docker-compose
+
+# https://github.com/docker-library/official-images#architectures-other-than-amd64
+# https://hub.docker.com/u/arm32v7/
+
+# Test
+docker run -d --rm arm32v6/bash sleep 100
+docker ps
+docker run -it --rm arm32v6/alpine

+ 57 - 0
download.sh

@@ -0,0 +1,57 @@
+#!/bin/bash
+
+# Get latest Raspbian image and checksum file 
+img_url_regex='http:\/\/downloads\.raspberrypi\.org\/raspbian_lite\/images\/raspbian_lite-[0-9-]{10}\/[0-9-]{10}-raspbian-buster-lite\.zip'
+img_url=`curl --silent https://downloads.raspberrypi.org/raspbian_lite_latest | \
+grep --extended-regexp --ignore-case --only-matching $img_url_regex`
+sha256_url=$img_url.sha256
+image=`basename $img_url`
+sha256=`basename $sha256_url`
+
+# Download latest image and checksum file if not present yet
+mkdir -p ~/images && cd ~/images
+if [[ -f "$image" && -f "$sha256" ]]; then
+  echo "Latest Raspbian image found: $image"
+else
+  echo "Downloading latest Raspbian..."
+  curl --continue-at - --remote-name-all $img_url $sha256_url
+fi
+
+# Test checksum and exit if fails
+echo -n "Testing checksum... "
+set -e && sha256sum --check  $sha256 || exit 1
+set +e
+
+
+# Guess SDcard Reader
+sdcard=`find /dev/disk/by-id/ -iregex '.*Card.*0$'`
+sudo fdisk -l $sdcard
+
+read -p "Continue with this disk? " -n 1 -r
+echo #newline
+if [[ $REPLY =~ ^[Yy]$ ]]; then
+  echo "Proceeding with $sdcard"
+else
+  set -e && exit 1
+fi
+
+
+for part in `find /dev/disk/by-id/ -iregex '.*Card.*-part.*'`;
+  do sudo umount --verbose $part && /bin/true;
+done
+
+unzip -p $image *.img \
+| sudo dd of="$sdcard" bs=4K status=progress
+
+
+# https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md
+
+# https://www.raspberrypi.org/documentation/remote-access/ssh/
+
+
+chown -R 1000:1000 /media/$USER/rootfs/home/pi/.ssh
+
+sync
+for part in `find /dev/disk/by-id/ -iregex '.*Card.*-part.*'`;
+  do umount --verbose $part && /bin/true;
+done

+ 43 - 0
mpd.sh

@@ -0,0 +1,43 @@
+
+
+sudo apt install mpd mpc ncmpc ffmpeg
+sudo cp /usr/share/sounds/alsa/Noise.wav /var/lib/mpd/music/
+
+mpc update
+mpc ls | mpc add
+mpc repeat
+mpc play
+
+
+-----
+
+
+sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl
+sudo chmod a+rx /usr/local/bin/youtube-dl
+
+youtube-dl -g https://www.youtube.com/watch?v=FJWd92Vi5Ww
+
+
+
+
+
+docker run -it --rm --device=/dev/snd:/dev/snd --name mpd -p 6600:6600 -p 8000:8000 arm32v6/alpine
+apk --no-cache add mpd mpc
+
+cat <<EOF | tee /etc/asound.conf
+pcm.!default {
+        type plug
+        slave.pcm {
+                type bluealsa
+                device "$btid"
+                profile "a2dp"
+        }
+}
+EOF
+
+/usr/bin/mpd --no-daemon --stdout
+
+apk add bluez
+
+/usr/lib/alsa-lib
+

+ 122 - 0
prepare-sd-card.sh

@@ -0,0 +1,122 @@
+#!/bin/bash
+
+# this script is not intended to be used without modifications!
+
+# ----------------------------------------------------------------------
+# Get latest Raspbian image and checksum file 
+img_url_regex='http:\/\/downloads\.raspberrypi\.org\/raspbian_lite\/images\/raspbian_lite-[0-9-]{10}\/[0-9-]{10}-raspbian-buster-lite\.zip'
+img_url=`curl --silent https://downloads.raspberrypi.org/raspbian_lite_latest | \
+grep --extended-regexp --ignore-case --only-matching $img_url_regex`
+sha256_url=$img_url.sha256
+image=`basename $img_url`
+sha256=`basename $sha256_url`
+
+# Download latest image and checksum file if not present yet
+mkdir -p ~/images && cd ~/images
+if [[ -f "$image" && -f "$sha256" ]]; then
+  echo "Latest Raspbian image found: $image"
+else
+  echo "Downloading latest Raspbian..."
+  curl --continue-at - --remote-name-all $img_url $sha256_url
+fi
+
+# Test checksum and exit if fails
+echo -n "Testing checksum... "
+set -e && sha256sum --check  $sha256 || exit 1
+set +e
+
+# ----------------------------------------------------------------------
+# Select the disk
+PS3="Select disk to install Raspbian: "
+select disk in `lsblk --include 8 --nodeps --output NAME --noheadings`
+do
+  echo "________________________________________________________________________"
+  lsblk --nodeps /dev/$disk --output TRAN,VENDOR,MODEL,HOTPLUG
+  echo "________________________________________________________________________"
+  lsblk /dev/$disk --output NAME,TYPE,FSTYPE,SIZE,LABEL,MOUNTPOINT
+  echo "________________________________________________________________________"
+  read -p "ARE YOU SURE THAT YOU WANT TO OVERWRITE THIS DISK? (y/n) " -n 1 -r
+  echo #newline
+  if [[ $REPLY =~ ^[Yy]$ ]]; then
+    echo "Proceeding with $sdcard"
+    sdcard=/dev/$disk
+    break
+  fi
+done
+
+
+# ----------------------------------------------------------------------
+# Testing parameters / hostname
+name=$1
+
+if [ "X$name" == "X" ]; then
+  echo "Kein Hostname für die Box angegeben!"
+  echo "USAGE: $0 name"
+  read -p "Hostname jetzt eingeben?: " name
+fi
+
+echo "Hostname: $name"
+echo "Image: $image"
+
+
+# ----------------------------------------------------------------------
+# Preparing the disk
+
+# Unmounting partitions
+for part in \
+  `findmnt  --output SOURCE,TARGET --raw | grep $sdcard | cut -d" " -f2`
+  do sudo umount --verbose $part
+done
+
+# Write image to sdcard
+unzip -p $image *.img \
+| sudo dd of="$sdcard" bs=4K status=progress
+sync
+
+echo 
+echo Rausnehmen, kurz warten, reinstecken und mount abwarten, dann Enter
+read -n 1 -p "Geht's weiter?" unused
+
+# Configure WiFi
+# https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md
+cp ~/wpa_supplicant.conf /media/$USER/boot/
+
+# Enable / Setup SSH
+# https://www.raspberrypi.org/documentation/remote-access/ssh/
+touch /media/$USER/boot/ssh
+
+mkdir -p /media/$USER/rootfs/home/pi/.ssh
+chmod 0700 /media/$USER/rootfs/home/pi/.ssh
+
+cp ~/.ssh/id_rsa.pub /media/$USER/rootfs/home/pi/.ssh/authorized_keys
+chmod 0600 /media/$USER/rootfs/home/pi/.ssh/authorized_keys
+
+chown -R 1000:1000 /media/$USER/rootfs/home/pi/.ssh
+
+# Setting hostname
+echo $name | sudo tee /media/$USER/rootfs/etc/hostname
+echo 127.0.1.2 $name | sudo tee -a /media/$USER/rootfs/etc/hosts
+
+# Set timezone
+echo "Europe/Berlin" \
+  | sudo tee  /media/$USER/rootfs/etc/timezone
+sudo ln -sf /usr/share/zoneinfo/Europe/Berlin \
+  /media/dominik/rootfs/etc/localtime
+   
+
+# Set locales
+sudo sed -i -e '/^# en_US\.UTF-8 UTF-8/s/^# //' \
+            -e '/^# de_DE\.UTF-8 UTF-8/s/^# //' \
+            /media/$USER/rootfs/etc/locale.gen
+#sudo locale-gen # need to run at first boot
+#idea: https://github.com/nmcclain/raspberian-firstboot
+#sudo update-locale LANG=de_DE.UTF-8 LC_MESSAGES=en_US.UTF-8 #equivalent
+echo -e "LANG=de_DE.UTF-8\nLC_MESSAGES=en_US.UTF-8" \
+  | sudo tee /media/$USER/rootfs/etc/default/locale 
+
+# Unmounting partitions
+sync
+for part in \
+  `findmnt  --output SOURCE,TARGET --raw | grep $sdcard | cut -d" " -f2`
+  do sudo umount --verbose $part
+done