-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflashimage.sh
More file actions
executable file
·122 lines (97 loc) · 2.82 KB
/
flashimage.sh
File metadata and controls
executable file
·122 lines (97 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# Find SD Card with:
# lsblk
# Unmount the card
# clear the cards content:
# sudo dd status=progress bs=4M if=/dev/zero of=/dev/mmcblk0 oflag=sync
# sudo dd status=progress bs=4M if=~/Downloads/2019-09-26-raspbian-buster-full. of=/dev/mmcblk0 oflag=sync
DISC=/dev/mmcblk0 #TODO path to device (use lsblk to find it, use the device not the partitions!)
BOOT=/media/$USER/boot
ROOTFS=/media/$USER/rootfs
CURRENT_DIR=`pwd`
WPA_SUPPLICANT=$CURRENT_DIR/secret/wpa_supplicant.conf
AUTHORIZED_KEYS=$CURRENT_DIR/secret/authorized_keys
IMAGE=$CURRENT_DIR/images/2020-02-13-raspbian-buster-lite.img #TODO
DEFAULT_NAME=raspberrypi
PI_ETC=/media/$USER/rootfs/etc
HOSTS_FILE=hosts
HOSTNAME_FILE=hostname
MOTION_SCRIPT=$CURRENT_DIR/setup_motioneye.sh
function confirmation() {
read -p "Continue (y/n)?" choice
case "$choice" in
y|Y ) return 1;;
n|N ) return 0;;
* ) return 0;;
esac
}
echo "Writing image $IMAGE to sd card?"
confirmation
if [ "$?" = 1 ]
then
echo "unmounting"
udisksctl unmount -b ${DISC}p1
udisksctl unmount -b ${DISC}p2
# udisksctl unmount -b $DISC
echo "Start Image Writing:"
sleep 1
# sudo dd status=progress bs=4M if=/dev/zero of=/dev/mmcblk0 oflag=sync
sudo dd status=progress bs=4M if=$IMAGE of=$DISC oflag=sync
sleep 10
else
# echo "Continue with SSH and WLAN configuration"
sleep 1
fi
# TODO: After the image is written ensure that the paths for BOOT, ROOTFS and PI_ETC are still correct!
# echo "Continue with SSH and WLAN configuration"
echo "Setup WLAN and SSH?"
confirmation
if [ "$?" = 1 ]
then
udisksctl mount -b ${DISC}p1
udisksctl mount -b ${DISC}p2
if [ -d $BOOT ] && [ -d $ROOTFS ]; then
echo "Boot mounted!"
echo "Enable ssh"
touch $BOOT/ssh
echo "Enable WLAN"
cp $WPA_SUPPLICANT $BOOT/
mkdir -p $ROOTFS/home/pi/.ssh
echo "Copy ssh key"
cp $AUTHORIZED_KEYS $ROOTFS/home/pi/.ssh/
else
echo "No boot dir!"
fi
else
# echo "Continue with SSH and WLAN configuration"
sleep 1
fi
echo "Change hostname?"
confirmation
if [ "$?" = 1 ]
then
udisksctl mount -b ${DISC}p1
udisksctl mount -b ${DISC}p2
read -p "Enter hostname: " piname
sudo sed -i -e "s/$DEFAULT_NAME/$piname/g" $PI_ETC/$HOSTS_FILE
sudo sed -i -e "s/$DEFAULT_NAME/$piname/g" $PI_ETC/$HOSTNAME_FILE
else
# echo "Continue with SSH and WLAN configuration"
sleep 1
fi
echo "Copy Motion install script?"
confirmation
if [ "$?" = 1 ]
then
udisksctl mount -b ${DISC}p1
udisksctl mount -b ${DISC}p2
echo -n "Copy installation script ..."
cp $MOTION_SCRIPT $ROOTFS/home/pi/
echo " done!"
else
# echo "Continue with SSH and WLAN configuration"
sleep 1
fi
echo -n "unmount ..."
udisksctl unmount -b ${DISC}p1
udisksctl unmount -b ${DISC}p2
echo "Done!"