-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript-zipdd
executable file
·140 lines (123 loc) · 4.44 KB
/
script-zipdd
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/bash
BASEDIR=$(dirname $0)
echo 'Checking for parameters'
if [ "$1" == "" ] ; then
#echo :$1: parm DOES NOT exist
echo "Usage: script-zipdd <OS image zip file> <Your_SBC_Hostname> [device/sdb]"
exit
else
#echo :$1: parm exists
if [ -f $1 ] ; then
echo found $1
else
echo $1, file DOES NOT exist. Should be: filename.img.zip
fi
fi
if [ "$2" == "" ] ; then
echo 'FAIL - The Second parameter DOES NOT exist'
echo "Usage: script-zipdd <OS image zip file> <Your_SBC_Hostname> [device/sdb]"
exit
else
# set config entry myHostName for other scripts usage
sed -i s/myHostName=.*/myHostName=\"$2\"/g $BASEDIR/script-config
fi
if [ ! "$3" == "" ] ; then
echo 'USING Alternate Device /dev/'$3
SDDEVICE=$3
else
SDDEVICE="mmcblk0"
fi
echo 'PASSED - Parameter check'
echo 'Checking for previously mounted uSD'
# checking for uSD card
ls /dev/${SDDEVICE} > /dev/null 2>&1
if [ $? == 0 ] ; then
grep ${SDDEVICE} /etc/mtab > /dev/null 2>&1
if [ $? == 0 ] ; then
IS_MOUNTED=`df | grep ${SDDEVICE}`
if [ $? == 0 ] ; then
#echo 'test: $IS_MOUNTED'
#echo 'test: unmounting partitions'
if [ "${SDDEVICE}" == "mmcblk0" ] ; then
sudo umount /dev/${SDDEVICE}p*
else
sudo umount /dev/${SDDEVICE}?
fi
if [ ! $? == 0 ] ; then
echo 'FAIL - Unable to unmount the uSD card'
exit
fi
fi
echo 'PASSED - uSD unmounted check'
fi
echo 'PASSED - uSD check'
else
echo 'FAIL - No uSD card found. Please insert and try again.'
echo 'searched for:/dev/'${SDDEVICE}
exit
fi
echo You will now be prompted for your WiFi SSID and PassPhrase.
echo These will be used to populate the wpa_supplicant.conf file in
echo your Downloads directory and copied to /media/lubuntu/boot.
echo On startup, the raspberryPi will copy that into the netwok and use it.
echo -------------- Setting up WiFi --------------------------------------
FOUNDSSID=`iwgetid -r`
if [ "$FOUNDSSID" == "" ] ; then
FOUNDSSID="yourSSID"
fi
read -e -p "Enter Your WiFi SSID:" -i $FOUNDSSID MYSSID
echo -n "Enter your WiFi Passphrase: "
read MYPWD
cp ~/Downloads/wpa_supplicant.conf ~/Downloads/wpa_supplicant.conf.NEW
sed -i s/your-network-name/$MYSSID/g ~/Downloads/wpa_supplicant.conf.NEW
sed -i s/your-passphrase/$MYPWD/g ~/Downloads/wpa_supplicant.conf.NEW
#sed -i s/track/$2/g ~/Downloads/wpa_supplicant.conf.NEW
# set config entry mySSID for reference
sed -i s/mySSID=.*/mySSID=\"$MYSSID\"/g $BASEDIR/script-config
echo BUILDING your SBC image. Please Wait......
echo NOTE! Wait until copied data bufferes are flushed
echo and you see COPY DONE before ejecting
IMAGE_SIZE=`unzip -l $1 | grep "donkey\|raspbian\|raspios" | tail -n 1 | cut -f1 -d" "`
string=`unzip -l $1 | grep "donkey\|raspbian\|raspios" | tail -n 1`
DONKEY_IMAGE=`echo $string | cut -f4 -d" "`
unzip -p $1 $DONKEY_IMAGE | pv -s $IMAGE_SIZE | sudo dd of=/dev/${SDDEVICE} bs=1M
sync
echo COPY DONE
echo
echo Setting up Customizations
sudo partprobe # reloads partition tables
mkdir mnt1 mnt2
if [ "${SDDEVICE}" == "mmcblk0" ] ; then
sudo mount /dev/${SDDEVICE}p1 mnt1
sudo mount /dev/${SDDEVICE}p2 mnt2
else
sudo mount /dev/${SDDEVICE}1 mnt1
sudo mount /dev/${SDDEVICE}2 mnt2
fi
#echo Setting up new hostname
echo $2 | sudo tee mnt2/etc/hostname
sudo sed -i s/raspberrypi/$2/g mnt2/etc/hosts
#sudo cp ~/Downloads/wpa_supplicant.conf.NEW mnt1/wpa_supplicant.conf
sudo cp ~/Downloads/wpa_supplicant.conf.NEW mnt2/etc/wpa_supplicant/wpa_supplicant.conf
sudo cp ~/Downloads/wpa_supplicant.conf.NEW mnt1/wpa_supplicant.conf
sudo cp ~/Downloads/wlan0.conf mnt2/etc/network/interfaces.d/
sudo cp ~/Downloads/sixpair.c mnt2/home/pi/
sudo cp ~/Downloads/do-autohotspot.tgz mnt2/home/pi/
#auto ssh login
# This generates 2 files, ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub
ssh-keygen -f ~/.ssh/id_rsa -N ""
#
# Move id_rsa.pub to rPi, or use ssh-copy-id -i ~/.ssh/id_rsa pi@your-hostname.local
sudo mkdir mnt2/home/pi/.ssh
sudo mv ~/.ssh/id_rsa.pub mnt2/home/pi/.ssh/authorized_keys
sudo chown -R 1000:1000 mnt2/home/pi/.ssh
sudo rm -rf mnt2/etc/localtime
sudo cp mnt2/usr/share/zoneinfo/America/Los_Angeles mnt2/etc/localtime
sudo echo "America/Los_Angeles" | sudo tee mnt2/etc/timezone
sudo touch mnt1/ssh
sudo chown -R 1000:1000 mnt2/home/pi/.
sudo sync && sudo umount mnt1 mnt2
rm -rf mnt1 mnt2
echo Remove the uSD card and install it in your SBC(single board computer) and power it up.
echo You can now find it on this same WiFi network using $2.local or
echo using avahi-browse -at