Created
September 2, 2018 15:24
-
-
Save ekohilas/a73233055b8beee2490129cfaf8192ca to your computer and use it in GitHub Desktop.
image installation scripts for bluetooth and ssh on a raspberry pi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if test $# -ne 2 | |
then | |
echo "Usage: ./burn.sh image_name disk_name" | |
exit 1 | |
fi | |
img=$1 | |
sd=$2 | |
echo "Are you sure you want to run: (Y)" | |
echo "'sudo dd bs=4M if=$img of=/dev/$sd status=progress conv=fsync'" | |
read okay | |
if test "$okay" = "Y" | |
then | |
sudo dd bs=4M if="$img" "of=/dev/$sd" status=progress conv=fsync | |
sync | |
else | |
echo "Didn't burn $img to $sd." | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
root_mnt="$1" | |
hostname="$2" | |
# Set Hostname | |
echo "Setting Bluetooth Hostname to $hostname." | |
echo "PRETTY_HOSTNAME=$hostname" > "$root_mnt/etc/machine-info" | |
# Enable bluetooth serial services | |
bluet_service="bluetooth.service" | |
bluet_location="$root_mnt/lib/systemd/system/$bluet_service" | |
bluez_service="dbus-org.bluez.service" | |
bluez_location="$root_mnt/etc/systemd/system/$bluez_service" | |
service_name="$bluet_service" | |
serivce_loc="$bluet_location" | |
mark="# BT serial config" | |
service_str="$mark\n\ | |
# Add -C for compatibility\n\ | |
ExecStart=/usr/lib/bluetooth/bluetoothd -C\n\ | |
# Add the SP profile\n\ | |
ExecStartPost=/usr/bin/sdptool add SP\n\ | |
# Make bluetooth discoverable\n\ | |
ExecStartPost=/bin/hciconfig hci0 piscan" | |
echo "Enabling bluetooth serial services by editing '$serivce_loc'." | |
if grep -xq "$mark" "$serivce_loc" | |
then | |
echo "'$serivce_loc' already edited." | |
else | |
sudo sed -i "s|^Exec.*toothd$|$service_str|" "$serivce_loc" | |
fi | |
# create the rfcomm service to enable the bluetooth serial port from systemctl | |
rf_service="$root_mnt/etc/systemd/system/rfcomm.service" | |
echo -n "Creating rfcomm service to enable the Bluetooth serial port " | |
echo "from systemctl by creating '$rf_service'." | |
sudo cat > "$rf_service" << EOF | |
[Unit] | |
Description=RFCOMM service | |
After=$service_name | |
Requires=$service_name | |
[Service] | |
ExecStart=/usr/bin/rfcomm watch hci0 1 getty rfcomm0 115200 vt100 -a pi | |
[Install] | |
WantedBy=multi-user.target | |
EOF | |
echo "Finished setting up bluetooth." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
boot_mnt="$1" | |
# Enable ssh | |
echo "Enabling SSH by creating '$boot_mnt/ssh'." | |
sudo touch "$boot_mnt/ssh" | |
# Enable device tree overlay | |
config="$boot_mnt/config.txt" | |
config_str="dtoverlay=dwc2" | |
echo "Enabling device tree overlay by adding '$config_str' to '$config'." | |
if grep -xq "$config_str" "$config" | |
then | |
echo "'$config_str' already in '$config'." | |
else | |
sudo echo >> "$config" | |
sudo echo "# Enable device tree overlay for SSH over USB" >> "$config" | |
sudo echo "$config_str" >> "$config" | |
fi | |
# ?? | |
#echo "start_x=0" >> "$boot_mnt/config.txt" | |
# Enable modules | |
cmdline="$boot_mnt/cmdline.txt" | |
cmdline_str="modules-load=dwc2,g_ether" | |
echo "Enable modules by editing '$cmdline' to include '$cmdline_str'." | |
if grep -q "$cmdline_str" "$cmdline" | |
then | |
echo "'$cmdline_str' already in '$cmdline'." | |
else | |
sudo sed -i "s/rootwait/rootwait $cmdline_str/" "$cmdline" | |
fi | |
echo "Finished setting up ssh." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
distro="https://downloads.raspberrypi.org/raspbian_lite_latest" | |
if test "$#" -ne 1 | |
then | |
echo "usage sudo ./setup.sh image" | |
exit 1 | |
fi | |
img="$1" | |
boot_mnt="$(mktemp -d)" | |
root_mnt="$(mktemp -d)" | |
hostname="raspberry-pi" | |
# parition and mount | |
sudo losetup -P /dev/loop0 "$img" || exit 1 | |
echo "Mounting boot to $boot_mnt." | |
sudo mount "/dev/loop0p1" "$boot_mnt" || exit 1 | |
echo "Mounting root to $root_mnt." | |
sudo mount "/dev/loop0p2" "$root_mnt" || exit 1 | |
# setup ssh | |
sh setup-ssh.sh "$boot_mnt" | |
# setup bt | |
sh setup-bt.sh "$root_mnt" "$hostname" | |
# Unmount | |
echo "Unmounting '$boot_mnt'." | |
sudo umount "$boot_mnt" | |
echo "Unmounting '$root_mnt'." | |
sudo umount "$root_mnt" | |
sudo losetup -D "$img" | |
echo "Done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment