Project

General

Profile

Download (1.59 KB) Statistics
| Branch: | Tag: | Revision:
1
#
2
# ex: filetype=sh
3
#
4
# common.subr
5
#
6
# part of pfSense (https://www.pfsense.org)
7
# Copyright (c) 2004-2013 BSD Perimeter
8
# Copyright (c) 2013-2016 Electric Sheep Fencing
9
# Copyright (c) 2014-2024 Rubicon Communications, LLC (Netgate)
10
# All rights reserved.
11
#
12
# Licensed under the Apache License, Version 2.0 (the "License");
13
# you may not use this file except in compliance with the License.
14
# You may obtain a copy of the License at
15
#
16
# http://www.apache.org/licenses/LICENSE-2.0
17
#
18
# Unless required by applicable law or agreed to in writing, software
19
# distributed under the License is distributed on an "AS IS" BASIS,
20
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
# See the License for the specific language governing permissions and
22
# limitations under the License.
23

    
24
# Obtained from poudriere common.sh
25
eargs() {
26
	local fname="$1"
27
	shift
28
	case $# in
29
		0) err "${fname}: No arguments expected" ;;
30
		1) err "${fname}: 1 argument expected: $1" ;;
31
		*) err "${fname}: $# arguments expected: $*" ;;
32
	esac
33
}
34

    
35
err() {
36
	[ $# -eq 1 ] || eargs err msg
37
	local msg="$1"
38

    
39
	echo >&2 "====>> ERROR: $msg"
40
	exit 1
41
}
42

    
43
run() {
44
	[ $# -eq 2 ] || eargs run msg cmd
45
	local msg="$1"
46
	local cmd="$2"
47

    
48
	echo "====>> ${msg}"
49
	${cmd} 2>&1
50
	rc=$?
51
	[ $rc -ne 0 ] \
52
		&& err "Execution of '${cmd}' failed (rc = ${rc})"
53
}
54

    
55
force_rm() {
56
	[ $# -eq 1 ] || eargs force_rm directory
57
	local directory="$1"
58

    
59
	[ "${directory}" = "/" ] \
60
		&& err "Removing / is not a good idea"
61

    
62
	run "Removing immutable flags from ${directory}" \
63
		"chflags -R noschg ${directory}"
64

    
65
	run "Removing recursively ${directory}" \
66
		"rm -rf ${directory}"
67
}
(2-2/5)