1
|
#
|
2
|
# ex: filetype=sh
|
3
|
#
|
4
|
# common.subr
|
5
|
#
|
6
|
# part of pfSense (https://www.pfsense.org)
|
7
|
# Copyright (c) 2004-2016 Electric Sheep Fencing, LLC
|
8
|
# All rights reserved.
|
9
|
#
|
10
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
11
|
# you may not use this file except in compliance with the License.
|
12
|
# You may obtain a copy of the License at
|
13
|
#
|
14
|
# http://www.apache.org/licenses/LICENSE-2.0
|
15
|
#
|
16
|
# Unless required by applicable law or agreed to in writing, software
|
17
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
18
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19
|
# See the License for the specific language governing permissions and
|
20
|
# limitations under the License.
|
21
|
|
22
|
# Obtained from poudriere common.sh
|
23
|
eargs() {
|
24
|
local fname="$1"
|
25
|
shift
|
26
|
case $# in
|
27
|
0) err "${fname}: No arguments expected" ;;
|
28
|
1) err "${fname}: 1 argument expected: $1" ;;
|
29
|
*) err "${fname}: $# arguments expected: $*" ;;
|
30
|
esac
|
31
|
}
|
32
|
|
33
|
err() {
|
34
|
[ $# -eq 1 ] || eargs err msg
|
35
|
local msg="$1"
|
36
|
|
37
|
echo >&2 "====>> ERROR: $msg"
|
38
|
exit 1
|
39
|
}
|
40
|
|
41
|
run() {
|
42
|
[ $# -eq 2 ] || eargs run msg cmd
|
43
|
local msg="$1"
|
44
|
local cmd="$2"
|
45
|
|
46
|
echo "====>> ${msg}"
|
47
|
${cmd} 2>&1
|
48
|
rc=$?
|
49
|
[ $rc -ne 0 ] \
|
50
|
&& err "Execution of '${cmd}' failed (rc = ${rc})"
|
51
|
}
|
52
|
|
53
|
force_rm() {
|
54
|
[ $# -eq 1 ] || eargs force_rm directory
|
55
|
local directory="$1"
|
56
|
|
57
|
[ "${directory}" = "/" ] \
|
58
|
&& err "Removing / is not a good idea"
|
59
|
|
60
|
run "Removing immutable flags from ${directory}" \
|
61
|
"chflags -R noschg ${directory}"
|
62
|
|
63
|
run "Removing recursively ${directory}" \
|
64
|
"rm -rf ${directory}"
|
65
|
}
|