libalpine.sh.in 996 Bytes
Newer Older
Natanael Copa's avatar
Natanael Copa committed
1 2
#!/bin/sh

Natanael Copa's avatar
Natanael Copa committed
3
PREFIX=@PREFIX@
Natanael Copa's avatar
Natanael Copa committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

PROGRAM=`basename $0`


echon () {
	if [ X"$ECHON" = X ]; then
		# Determine how to "echo" without newline: "echo -n"
		# or "echo ...\c"
		if [ X`echo -n` = X-n ]; then
			ECHON=echo
			NNL="\c"
			# "
		else
			ECHON="echo -n"
			NNL=""
		fi
	fi
	$ECHON "$*$NNL"
}

24 25 26 27 28
# echo if in verbose mode
vecho() {
	[ -n "$VERBOSE" ] && echo "$@"
}

Natanael Copa's avatar
Natanael Copa committed
29 30 31 32 33 34 35 36 37 38
# echo unless quiet mode
qecho() {
	[ -z "$QUIET" ] && echo "$@"
}

# echo to stderr
eecho() {
	echo "$@" >&2
}

Natanael Copa's avatar
Natanael Copa committed
39 40
init_tmpdir() {
	local omask=`umask`
Natanael Copa's avatar
Natanael Copa committed
41
	local __tmpd="/tmp/$PROGRAM-${$}-`date +%s`-$RANDOM"
Natanael Copa's avatar
Natanael Copa committed
42
	umask 077 || die "umask"
Natanael Copa's avatar
Natanael Copa committed
43
	mkdir -p "$__tmpd" || exit 1
Natanael Copa's avatar
Natanael Copa committed
44 45 46 47 48 49
	trap "rm -fr \"$__tmpd\"; exit" 0
	umask $omask
	eval "$1=\"$__tmpd\""
}

pkg_inst() {
Natanael Copa's avatar
Natanael Copa committed
50
	[ -z "$NOCOMMIT" ] && apk add -q $*
Natanael Copa's avatar
Natanael Copa committed
51 52
}

53
pkg_deinst() {
Natanael Copa's avatar
Natanael Copa committed
54
	[ -z "$NOCOMMIT" ] && apk del -q $*
55 56
}

Natanael Copa's avatar
Natanael Copa committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
default_read() {
	local n
	read n
	[ -z "$n" ] && n="$2"
	eval "$1=\"$n\""
}


invalid_ip() {
	[ "$1" ] || return 0
	! ipcalc -s $1
}


cfg_add() {
	[ -z "$NOCOMMIT" ] && lbu_add "$@"
}