-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·29 lines (21 loc) · 944 Bytes
/
install.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
#!/bin/bash
function makeFileWithMode {
[[ -f $1 ]] || (touch $1 ; chmod $2 $1)
}
# assume sudo permission (it is default)
# check ssh is turned on
sudo systemctl status ssh | grep -q "Active: active" || sudo systemctl start ssh
sudo systemctl status ssh | grep Loaded: | grep -q "ssh.service; enabled" || sudo systemctl enable ssh
# check ssh keygen ran for pi
[[ -f /home/pi/.ssh/id_rsa ]] || (echo -e "\n\n\n" | ssh-keygen 2>&1 >/dev/null)
# check pi has its own authorized_key
ak="/home/pi/.ssh/authorized_keys"
makeFileWithMode $ak 600
grep -q "$(cat /home/pi/.ssh/id_rsa.pub)" $ak || (cat /home/pi/.ssh/id_rsa.pub >> $ak)
# check pi has the localhost known_host
kh="/home/pi/.ssh/known_hosts"
makeFileWithMode $kh 600
grep -q localhost $kh || ssh-keyscan localhost >>$kh
# install Ansible if necessary
sudo dpkg -s ansible 2>&1 >/dev/null || sudo apt-get install -y ansible
ansible-playbook playbook.yml -i hosts-localhost -u pi