slitaz-arm view rpi/slitaz-rpi @ rev 216

piboot: berryboot compatible
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Feb 06 18:44:20 2017 +0100 (2017-02-06)
parents 0eb0f35e2f0d
children
line source
1 #!/bin/sh
2 #
3 # A tiny utility to help manage SliTaz R-Pis from an i486 machine. Make
4 # it clean and fast for users :-). if you're looking for the SliTaz R-Pi
5 # distro builder, have a look at sat-rpi.
6 #
7 # (C) 2014 SliTaz ARM - BSD License
8 # AUTHOR: Christophe Lincoln <pankso@slitaz.org>
9 #
10 # TODO:
11 #
12 # GUI box to dl/install SliTaz R-Pi on sdcard (à la tazusb-box)
13 # SD card DD backup and restore
14 # Setup a R-Pi webboot on any i?86/X64 server/machine
15 #
16 #
17 . /lib/libtaz.sh
19 pilist="$HOME/.config/slitaz/rpi.list"
21 usage() {
22 cat << EOT
24 $(boldify "Usage:") $(basename $0) [command] [host]
26 $(boldify "Commands:")
27 netmap Search and map R-Pis on the wired local network
28 pscan Scan one or all Raspberry Pi hosts open ports
29 box Run the GTK/Yad graphical user interface
31 EOT
32 }
34 ssh_term() {
35 xterm -e "echo 'Connecting: $@'; ssh $@ || read"
36 }
38 netmap_term() {
39 xterm -e "$0 netmap; echo -n 'Press ENTER to continue...'; read"
40 $0 box
41 }
43 pscan_term() {
44 local host="$1"
45 echo $0 pscan $host
46 xterm -e "$0 pscan $1; echo -n 'Press ENTER to continue...'; read"
47 $0 box
48 }
50 rpi_list() {
51 for host in $(cat $pilist); do
52 echo -n "$host!"
53 done
54 echo "Clean list"
55 }
57 rpi_box() {
58 count=$(cat $pilist | wc -l)
59 logo="/usr/share/pixmaps/raspberrypi.png"
60 text="<b>Connect to your local Raspberry Pi devices</b>\nRaspberry Pi: $count\n"
61 # Have a config file, store RPi IPs, have button to launch an SSH
62 # connection or an sftp connection with gftp.
63 yad --form --borders=4 \
64 --window-icon="$logo" \
65 --title="SliTaz RPi" --center \
66 --image="$logo" --image-on-top \
67 --text "$text" --width=520 --height=240 \
68 --button="Web admin!gtk-properties:4" \
69 --button="Netmap!find:2" \
70 --button="Connect!insert-link:0" \
71 --button="Cancel!gtk-close:1" \
72 --field="$(gettext "Raspberry Pi host:")":CB \
73 --field="$(gettext "New device IP:")" \
74 --field="$(gettext "User name:")" \
75 "$(rpi_list)" "" "$USER"
76 }
78 case "$1" in
79 netmap)
80 # MAC address works for wired raspberry R-Pis
81 # http://hwaddress.com/?q=raspberry
82 newline && colorize 35 "Raspberry Pi wired LAN map"
83 separator
84 arp -a | grep -i "b8:27:eb" | awk '{print $2}' | while read line
85 do
86 ip=$(echo "$line" | tr -d '()')
87 ssh="$(colorize 31 OFF)"
88 http="$ssh"
89 if pscan ${ip} -p 22 -P 22 | fgrep 'ssh' | fgrep -q 'open'; then
90 ssh="$(colorize 32 ON)"
91 fi
92 if pscan ${ip} -p 81 -P 81 | fgrep 'http' | fgrep -q 'open'; then
93 http="$(colorize 32 ON)"
94 fi
95 echo -n "IP: $ip $(indent 30 "SSH: $ssh")"
96 indent 46 "HTTP: $http"
97 done
98 separator
99 count=$(arp -a | grep -i "b8:27:eb" | wc -l)
100 echo -n "Raspberry Pi found: "; boldify "$count"
101 newline ;;
103 pscan)
104 if [ "$2" ]; then
105 pscan ${2} && exit 0
106 fi
107 arp -a | grep -i "b8:27:eb" | awk '{print $2}' | while read line
108 do
109 ip=$(echo "$line" | tr -d '()')
110 newline
111 echo "$(colorize 35 'Raspberry Pi Open ports')"
112 separator
113 pscan ${ip}
114 separator; newline
115 done ;;
117 box)
118 # Store box results
119 main=$(rpi_box)
120 action="$?"
122 host=$(echo $main | cut -d "|" -f 1)
123 new=$(echo $main | cut -d "|" -f 2)
124 user=$(echo $main | cut -d "|" -f 3)
126 # New host
127 [ "$new" ] && host="$new" && main="$new"
128 if [ "$new" ] && ! grep "^$new" ${pilist}; then
129 echo "$new" >> ${pilist}
130 fi
132 # Deal with --button actions
133 case "$action" in
134 0) ssh_term "$user@$host" ;;
135 1) exit 0 ;;
136 2) netmap_term ;;
137 4) tazweb --notoolbar ${host}/adm ;;
138 *) continue ;;
139 esac
141 # Deal with $main values
142 case "$main" in
143 Clean*)
144 echo "Cleaning: $pilist"
145 rm -f ${pilist} && touch ${pilist}
146 $0 box ;;
147 esac ;;
149 backup)
150 # dd an SD card with time stamp
151 ;;
153 restore)
154 # Restore a previous backup SD card
155 ;;
157 *) usage ;;
159 esac && exit 0