aboutsummaryrefslogtreecommitdiff
path: root/devices.sh
blob: 6c1f30b8220c02b6497c3460c6c46b2298f2cb51 (plain)
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
#!/usr/bin/env bash
source "${0%/*}/common.sh"
declare -a devices
################################################################################
## aarch64
# Mox
devices+=( "dean" "spt-mox" "spt-mox2" )
# Raspberry Pi
devices+=( "adm-mpd" )

## armv7
# Omnia
devices+=( "spt-omnia" "adm-omnia" "adm-omnia2" )
# Raspberry Pi
devices+=( "spt-mpd" )
################################################################################

valid_device() {
	local check="$1"
	for dev in "${devices[@]}"; do
		[ "$dev" != "$check" ] \
			|| return 0
	done
	return 1
}

for_devices() {
	for device in "${selected_devices[@]}"; do
		for op in "$@"; do
			if ! "$op" "$device"; then
				error "Operation '$op' failed for: $device" >&2
				break
			fi
		done
	done
}

################################################################################
operation="${1:-}"
[ $# -gt 0 ] && shift

declare -a selected_devices
if [ $# -gt 0 ]; then
	for device in "$@"; do
		if valid_device "$device"; then
			selected_devices+=("$device")
		else
			asdev="$(sshhost "$device")"
			if valid_device "$asdev"; then
				selected_devices+=("$asdev")
			else
				error "No such device: $device" >&2
				exit 2
			fi
		fi
	done
else
	selected_devices=("${devices[@]}")
fi


case "$operation" in
	help|h)
		cat <<-EOF
		Usage $0 operation [device]...
		Local system builder and updater for remote devices.

		Operations:
		  build: build device system
		  copy: copy built system to the device
		  boot: set built system to be boot default on the device
		  switch: switch to the built system on the target device
		  test: test the built system on the target device
		EOF
		;;
	build|b|"")
		for_devices build
		;;
	copy|c)
		for_devices copy
		;;
	boot)
		for_devices boot
		;;
	switch|s)
		for_devices switch
		;;
	test|t)
		for_devices switch_test
		;;
	build-copy|bc)
		for_devices build copy
		;;
	build-switch|bs)
		for_devices build copy switch
		;;
	build-test|bt)
		for_devices build copy switch_test
		;;
	build-boot|bb)
		for_devices build copy boot
		;;
	default)
		echo "Unknown operation: $operation" >&2
		exit 2
		;;
esac