forked from Enginexp/pi_kube
/
sd_write.sh
executable file
·78 lines (71 loc) · 1.86 KB
/
sd_write.sh
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
#!/bin/bash
set -e
source config.ini
#
# Download Raspbian Image
#
OUTFILE='raspbian_lite.zip'
if [ ! -f $OUTFILE ]; then
curl -o "$OUTFILE" -L https://downloads.raspberrypi.org/raspbian_lite_latest
fi
unzip "$OUTFILE"
#
# Write Image to MicroSD
#
IMG_FILE=$(ls *.img)
read -p "Plug your MicroSD card and press enter to continue"
df -h | grep "/dev"
echo -n "Confirm and type MicroSD card location (eg: /dev/xpto): "
read SD_LOCATION
echo
echo "Unmounting disk..."
if [[ "$OSTYPE" == "darwin"* ]]; then
sudo diskutil unmountDisk $SD_LOCATION
echo "Burning image..."
sudo dd bs=4m if="$IMG_FILE" of="$SD_LOCATION" conv=sync
else
sync
umount $BOOT_PATH
echo "Burning image..."
sudo dd bs=4M if="$IMG_FILE" of="$SD_LOCATION" conv=fsync
fi
#
# Touch 'ssh' file for enabling SSH server
#
sleep 10
echo
df
echo -n "Confirm and type boot mount point (eg: /run/media/user/boot): "
read BOOT_PATH
sudo touch "$BOOT_PATH/ssh"
sudo cp "$BOOT_PATH/cmdline.txt" "$BOOT_PATH/cmdline_backup.txt"
orig="$(head -n1 $BOOT_PATH/cmdline.txt) cgroup_enable=cpuset cgroup_enable=memory"
echo $orig | sudo tee "$BOOT_PATH/cmdline.txt"
#
# Sync and Unmount
#
if [[ "$OSTYPE" == "darwin"* ]]; then
sudo diskutil unmountDisk $BOOT_PATH
else
sync
umount $BOOT_PATH
fi
#
# Wait for your new friend to be available and setup key auth.
#
echo
echo "Unplug and boot to your new Pi!"
echo -n "Enter the remote IP address of the new Pi: "
read REMOTE_IP
echo
echo "Adding public key..."
echo "NOTE: The default password of 'raspberry' should be used (if prompted)"
ssh-copy-id pi@$REMOTE_IP
ssh pi@$REMOTE_IP sudo passwd -l pi
#
# Copy config and setup script to your new node and install docker/kubernetes
#
echo
echo "Copying files to our new friend and deploy kubernetes, sit back and relax"
scp config.ini setup.sh pi@$REMOTE_IP:/home/pi
ssh pi@$REMOTE_IP sh -c './setup.sh'