-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcopy-files.sh
executable file
·175 lines (150 loc) · 3.63 KB
/
copy-files.sh
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
169
170
171
172
173
174
175
#!/usr/bin/env bash
usage() {
local old_xtrace
old_xtrace="$(shopt -po xtrace || :)"
set +o xtrace
echo "${script_name} - Copy ILP32 base files." >&2
echo "Usage: ${script_name} [flags] <file-type>" >&2
echo "Option flags:" >&2
echo " -c --check - Run shellcheck." >&2
echo " -h --help - Show this help and exit." >&2
echo " -v --verbose - Verbose execution." >&2
echo " -f --force - Overwrite files without prompting." >&2
echo "Args:" >&2
echo " <file-type> - File type {${file_types} all}." >&2
echo " Default: '${file_type}'." >&2
eval "${old_xtrace}"
}
process_opts() {
local short_opts="chvf"
local long_opts="check,help,verbose,force"
local opts
opts=$(getopt --options ${short_opts} --long ${long_opts} -n "${script_name}" -- "$@")
eval set -- "${opts}"
while true ; do
case "${1}" in
-c | --check)
check=1
shift
;;
-h | --help)
usage=1
shift
;;
-v | --verbose)
#verbose=1
set -x
shift
;;
-f | --force)
force=1
shift
;;
--)
file_type=${2}
if [[ ${usage} || ${check} ]]; then
break
fi
if ! shift 2; then
echo "${script_name}: ERROR: Missing args: <file-type>" >&2
usage
exit 1
fi
if [[ -n "${1}" ]]; then
echo "${script_name}: ERROR: Got extra args: '${*}'" >&2
usage
exit 1
fi
break
;;
*)
echo "${script_name}: ERROR: Internal opts: '${*}'" >&2
exit 1
;;
esac
done
}
on_exit() {
local result=${1}
set +x
echo "${script_name}: Done: ${result}" >&2
}
run_shellcheck() {
local file=${1}
shellcheck=${shellcheck:-"shellcheck"}
if ! test -x "$(command -v "${shellcheck}")"; then
echo "${script_name}: ERROR: Please install '${shellcheck}'." >&2
exit 1
fi
${shellcheck} "${file}"
}
copy_files() {
local type=${1}
local no_force
if [[ ! ${force} ]]; then
no_force=1
fi
case "${type}" in
binfmt)
cp -v ${no_force:+-i} \
"${SCRIPTS_TOP}/fs/compat_binfmt_elf.c" \
"${SCRIPTS_TOP}/fs/binfmt_arm64_ilp32_elf.c"
;;
signal)
cp -v ${no_force:+-i} \
"${SCRIPTS_TOP}/arch/arm64/kernel/signal.c" \
"${SCRIPTS_TOP}/arch/arm64/kernel/signal_ilp32.c"
;;
syscall)
cp -v ${no_force:+-i} \
"${SCRIPTS_TOP}/arch/arm64/kernel/sys32.c" \
"${SCRIPTS_TOP}/arch/arm64/kernel/sys_ilp32.c"
;;
vdso)
mkdir -p "${SCRIPTS_TOP}/arch/arm64/kernel/vdso_ilp32"
cp -v ${no_force:+-i} \
"${SCRIPTS_TOP}/arch/arm64/kernel/vdso/gen_vdso_offsets.sh" \
"${SCRIPTS_TOP}/arch/arm64/kernel/vdso/Makefile" \
"${SCRIPTS_TOP}/arch/arm64/kernel/vdso/sigreturn.S" \
"${SCRIPTS_TOP}/arch/arm64/kernel/vdso/vdso.lds.S" \
"${SCRIPTS_TOP}/arch/arm64/kernel/vdso/vdso.S" \
"${SCRIPTS_TOP}/arch/arm64/kernel/vdso/vgettimeofday.c" \
"${SCRIPTS_TOP}/arch/arm64/kernel/vdso32/note.c" \
"${SCRIPTS_TOP}/arch/arm64/kernel/vdso_ilp32/"
;;
*)
echo "${script_name}: ERROR: Unknown <file-type> '${type}'" >&2
usage
exit 1
;;
esac
}
#===============================================================================
# program start
#===============================================================================
export PS4='\[\033[0;33m\]+ ${BASH_SOURCE##*/}:${LINENO}:(${FUNCNAME[0]:-"?"}): \[\033[0;37m\]'
script_name="${0##*/}"
SCRIPTS_TOP=${SCRIPTS_TOP:-"$(cd "${0%/*}" && pwd)"}
trap "on_exit 'failed.'" EXIT
set -e
file_types="binfmt signal syscall vdso"
process_opts "${@}"
if [[ ${usage} ]]; then
usage
trap - EXIT
exit 0
fi
if [[ ${check} ]]; then
run_shellcheck "${0}"
trap "on_exit 'Success'" EXIT
exit 0
fi
if [[ "${file_type}" == "all" ]]; then
for ft in ${file_types}; do
copy_files "${ft}"
done
else
copy_files "${file_type}"
fi
trap "on_exit 'Success.'" EXIT
exit 0