summaryrefslogtreecommitdiffstats
path: root/libalpine.sh
blob: 8b68bd78a2929ee4627cd3a128d762419671e86b (plain)
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
#!/bin/sh

PREFIX=

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"
}

init_tmpdir() {
	local omask=`umask`
	local __tmpd="/tmp/$PROGRAM-${$}-`date +%s`"
	umask 077 || die "umask"
	mkdir "$__tmpd" || exit 1
	trap "rm -fr \"$__tmpd\"; exit" 0
	umask $omask
	eval "$1=\"$__tmpd\""
}

pkg_inst() {
	[ -z "$NOCOMMIT" ] && apk_add $*
}

pkg_deinst() {
	[ -z "$NOCOMMIT" ] && apk_delete $*
}

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 "$@"
}