-
Notifications
You must be signed in to change notification settings - Fork 6
/
ls-machines
executable file
·168 lines (138 loc) · 3.14 KB
/
ls-machines
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Copyright (C) 2017-2023 TQ-Systems GmbH <[email protected]>,
# D-82229 Seefeld, Germany.
# Author: Markus Niebel
#
# Description: list all machines in a layer
#
###############################################################################
set -e
set -C # noclobber
readonly SCRIPTNAME="${0}"
readonly SCRIPTPATH=$(dirname "$(readlink -f "${0}")")
# TRAP SIGNALS
trap 'error_abort $LINENO' ERR
function error_abort () {
echo "error at $1"
}
. "${SCRIPTPATH}/utils"
readonly DEFAULT_LAYER_DIR="./sources/meta-tq/meta-tq"
usage() {
cat <<END
${SCRIPTNAME} usage:
List available machines either from config file or from template directory
${SCRIPTNAME} --dir[=<directory>]
use default template dir ${DEFAULT_TEMPLATEDIR} or directory
Note: directory needs to have the structure of a layer and distros are
under <layer dir>/conf/distro/.
${SCRIPTNAME} --file[=<filename>] --config=<name>
use default config file ${DEFAULT_BUILD_CONFIG} or given file to parse for supported
distros for given config name
Note: config file needs to to be a json file and must be in sync with workspace
structure and settings
END
}
function parse_machines_from_file () {
local configfile
configfile="$(readlink --canonicalize-existing "${1}")"
local config="${2}"
if [ -f "${configfile}" ]; then
local machines
machines=$(get_machines_for_config "${configfile}" "${config}")
for m in ${machines}; do
echo "${m}"
done
else
error_out "config file ${1} not existing"
fi
}
function parse_machines_from_dir () {
local machinepath
machinepath="$(readlink --canonicalize-existing ${1}/conf/machine)"
if [ -d "${machinepath}" ]; then
# filter out distros from the layer
local machines
machines=$(find "${machinepath}" -name "*.conf" | \
sed s/\.conf//g | xargs -n1 basename)
for m in ${machines}; do
echo "${m}"
done
fi
}
main() {
local machine_dir=""
local config_file=""
local config_name=""
local pos_params=""
if [ "${#}" -gt "2" ]; then
usage
return 1
fi
if ! is_gnu_grep; then
return 1
fi
while (( "$#" )); do
case ${1} in
-h|--help )
usage
return 0
;;
--config=* )
config_name=${1#*=}
shift
;;
--file=* )
config_file=${1#*=}
shift
;;
--file )
config_file="${DEFAULT_BUILD_CONFIG}"
shift
;;
--dir=* )
machine_dir=${1#*=}
shift
;;
--dir )
machine_dir="${DEFAULT_LAYER_DIR}"
shift
;;
--*=|-*) # unsupported flags
error_out "Error: Unsupported flag $1"
exit 1
;;
*) # preserve positional arguments
pos_params="$pos_params $1"
shift
;;
esac
done
if [ -n "${pos_params}" ]; then
error_out "unhandled parameters $pos_params"
fi
if [ -n "${config_file}" ] && [ -n "${machine_dir}" ]; then
usage
exit 1
fi
if [ -z ${config_file} ] && [ -z ${machine_dir} ]; then
usage
exit 1
fi
if [ -n "${config_file}" ] && [ -z ${config_name} ]; then
usage
exit 1
fi
if [ -n "${config_file}" ]; then
parse_machines_from_file "${config_file}" ${config_name}
return 0
fi
if [ -n "${machine_dir}" ]; then
parse_machines_from_dir "${machine_dir}"
return 0
fi
usage
return 1
}
main "$@"