-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultitool.sh
More file actions
executable file
·151 lines (121 loc) · 5.24 KB
/
multitool.sh
File metadata and controls
executable file
·151 lines (121 loc) · 5.24 KB
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
#!/bin/sh
set -e
toolname="${0##*/}" && toolname="${toolname%.sh}"
scriptrealpath="$(realpath "$0")"
scriptname="${scriptrealpath##*/}"
scriptrealdir="$(dirname "$scriptrealpath")"
scriptdir="${scriptrealdir}"
# Include utilities:
. "$scriptdir/utils/utils-basic.sh"
. "$scriptdir/utils/utils-info.sh"
. "$scriptdir/utils/utils-list.sh"
. "$scriptdir/utils/utils-file.sh"
. "$scriptdir/utils/utils-search.sh"
. "$scriptdir/utils/utils-plugin-loader.sh"
. "$scriptdir/utils/utils-checksum.sh"
. "$scriptdir/utils/utils-apk.sh"
. "$scriptdir/utils/utils-fkrt.sh"
# Check for quiet flag and set global 'QUIET=yes' before running anything that generates output. Skipped in main option parser.
# Let verbose override quiet before setting verbose, but quiet acts directly.
_co="$@" && for _i in $_co ; do case "$_i" in -q|--quiet) QUIET="yes" ; VERBOSE="" ;; -v|--verbose) [ "$QUIET" = "yes" ] || VERBOSE="yes" ; QUIET="" ;; --) break ;; esac ; done
default_colors
info_prog_set "$scriptname"
multitool_usage() { multitool_opts_usage ; }
multitool_opts_usage() {
cat <<EOF
Global options:
--quiet|-q Enable quiet mode.
--verbose|-v Increase verbosity.
--apk-cmd Override APK command.
--arch Override arch.
--hostname Override hostname.
--staging-root Override staging root.
--install-root Override install root.
EOF
}
apkroot_opts_usage() {
cat <<EOF
apkroot options:
--cache-dir Set apk cache directory for apkroot.
--repository|--repo Add apk repository to apkroot repos.
--repositories-file|--repo-file Add apk repos from file to apkroot repos.
--key-file|--key Add key in file to apkroot keys dir.
--keys-dir Add keys in dir to apkroot keys dir.
--host-keys Copy host keys to apkroot keys dir.
--no-host-keys Don't copy host keys.
EOF
}
# load plugins from script dir and ~/.mkimage
info_prog_set "$scriptname:plugin-loader (tools)"
load_plugins "$scriptdir" "tools"
info_prog_set "$scriptname"
[ "$toolname" = "multitool" ] && toolname="$1" && shift
case "$(type $toolname)" in
*"shell function") TOOL="$toolname" ;;
*) error "Unknown tool '$toolname'!" ; return 1 ;;
esac
case "$TOOL" in
apkroottool) : ;;
kerneltool)
load_plugins "$scriptdir/initfs"
load_plugins "$scriptdir/kernels"
load_plugins "$scriptdir/archs"
. "$scriptdir/kernels/tool-kerneltool.sh"
. "$scriptdir/kernels/tool-kerneltool-apk.sh"
. "$scriptdir/kernels/tool-kerneltool-kbuild.sh"
;;
mkinitfs)
load_plugins "$scriptdir/initfs"
. "$scriptdir/initfs/plugin-mkinitfs.sh"
;;
initfstool)
load_plugins "$scriptdir/archs"
load_plugins "$scriptdir/kernels"
load_plugins "$scriptdir/initfs"
. "$scriptdir/tools/tool-apkroottool.sh"
. "$scriptdir/kernels/tool-kerneltool.sh"
. "$scriptdir/kernels/tool-kerneltool-apk.sh"
. "$scriptdir/kernels/tool-kerneltool-kbuild.sh"
. "$scriptdir/initfs/tool-initfstool.sh"
;;
esac
OPT_apkroot_setup_cmdline=""
while [ $# -gt 0 ] ; do
# Global options that may apply to any tool.
case "$1" in
--quiet|-q) shift ; continue ;;
--verbose|-v) shift ; continue ;;
--apk-cmd) OPT_apk_cmd="$2" ; shift 2 ; continue ;;
--arch) OPT_arch="$2"; shift 2 ; continue ;;
--hostname) OPT_hostname="$2"; shift 2 ; continue ;;
--staging-root) OPT_staging_root="$2" ; shift 2 ; continue ;;
--install-root) OPT_install_root="$2" ; shift 2 ; continue ;;
esac
# Options for tools that call apkroot_setup
case "$1" in
# Options to pass to apkroot_setup
--cache-dir) OPT_apkroot_setup_cmdline="${OPT_apkroot_setup_cmdline:+"$OPT_apkroot_setup_cmdline "}--cache-dir $2" ; shift 2 ; continue ;;
--repository|--repo) OPT_apkroot_setup_cmdline="${OPT_apkroot_setup_cmdline:+"$OPT_apkroot_setup_cmdline "}--repository $2" ; shift 2 ; continue ;;
--repositories-file|--repo-file) OPT_apkroot_setup_cmdline="${OPT_apkroot_setup_cmdline:+"$OPT_apkroot_setup_cmdline "}--repositories-file $2" ; shift 2 ; continue ;;
--key-file|--key) OPT_apkroot_setup_cmdline="${OPT_apkroot_setup_cmdline:+"$OPT_apkroot_setup_cmdline "}--key-file $2" ; shift 2 ; continue ;;
--keys-dir) OPT_apkroot_setup_cmdline="${OPT_apkroot_setup_cmdline:+"$OPT_apkroot_setup_cmdline "}--keys-dir $2" ; shift 2 ; continue ;;
--host-keys) OPT_apkroot_setup_cmdline="${OPT_apkroot_setup_cmdline:+"$OPT_apkroot_setup_cmdline "}--host-keys" ; shift ; continue ;;
--no-host-keys) OPT_apkroot_setup_cmdline="${OPT_apkroot_setup_cmdline//--host-keys/ }" ; shift ; continue ;;
--arch-keys) OPT_apkroot_setup_cmdline="${OPT_apkroot_setup_cmdline:+"$OPT_apkroot_setup_cmdline "}--arch-keys" ; shift ; continue ;;
--no-arch-keys) OPT_apkroot_setup_cmdline="${OPT_apkroot_setup_cmdline//--arch-keys/ }" ; shift ; continue ;;
esac
break
#case "$1" in
case "$1" in -*|--*) warning "Unknown global option '$1'!" ; shift ; continue ;; *) break ;; esac
done
# Setup our apk tool:
[ "$APK" ] || _apk_init ${OPT_apk_cmd:+"$OPT_apk_cmd"}
# Determine our value for hostname
: "${mkalpine_hostname:="${HOSTNAME:-alpine}"}"
HOSTNAME="${OPT_hostname:-${mkalpine_hostname}}"
# Determine our staging root
: "${mkalpine_staging_root:=/var/cache/mkalpine/staging}"
STAGING_ROOT="${OPT_staging_root:-$mkalpine_staging_root}"
# Default apkroot_setup_cmdline if nothing has been specified
: "${OPT_apkroot_setup_cmdline:="--host-keys --arch-keys"}"
"$TOOL" "$@"