/
reboot-gen
executable file
·114 lines (96 loc) · 2.35 KB
/
reboot-gen
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
#!/bin/sh
set -e
show_help() {
cat << EOF
Simple tool to generate Mender Artifact suitable for reboot Update Module
Usage: $0 [options] [-- [options-for-mender-artifact] ]
Options: [ -n|artifact-name -t|--device-type -o|--output_path -h|--help ]
--artifact-name - Artifact name
--device-type - Target device type identification (can be given more than once)
--output-path - Path to output artifact file. Default: reboot-artifact.mender
--help - Show help and exit
Anything after a '--' gets passed directly to the mender-artifact tool.
EOF
}
show_help_and_exit_error() {
show_help
exit 1
}
check_dependency() {
if ! which "$1" > /dev/null; then
echo "The $1 utility is not found but required to generate Artifacts." 1>&2
return 1
fi
}
if ! check_dependency mender-artifact; then
echo "Please follow the instructions here to install mender-artifact and then try again: https://docs.mender.io/downloads#mender-artifact" 1>&2
exit 1
fi
device_types=""
artifact_name=""
output_path="reboot-artifact.mender"
passthrough=0
passthrough_args=""
while [ -n "$1" ]; do
if test $passthrough -eq 1
then
passthrough_args="$passthrough_args $1"
shift
continue
fi
case "$1" in
--device-type | -t)
if [ -z "$2" ]; then
show_help_and_exit_error
fi
device_types="$device_types $1 $2"
shift 2
;;
--artifact-name | -n)
if [ -z "$2" ]; then
show_help_and_exit_error
fi
artifact_name=$2
shift 2
;;
--output-path | -o)
if [ -z "$2" ]; then
show_help_and_exit_error
fi
output_path=$2
shift 2
;;
-h | --help)
show_help
exit 0
;;
--)
passthrough=1
shift
;;
-*)
echo "Error: unsupported option $1"
show_help_and_exit_error
;;
*)
shift
;;
esac
done
if [ -z "${artifact_name}" ]; then
echo "Artifact name not specified. Aborting."
show_help_and_exit_error
fi
if [ -z "${device_types}" ]; then
echo "Device type not specified. Aborting."
show_help_and_exit_error
fi
mender-artifact write module-image \
-T reboot \
$device_types \
-o $output_path \
-n $artifact_name \
$passthrough_args
echo "Artifact $output_path generated successfully:"
mender-artifact read $output_path
exit 0