update-conf.in 2.06 KB
Newer Older
Natanael Copa's avatar
Natanael Copa committed
1
2
3
#!/bin/sh

PREFIX=
Dubiousjim's avatar
Dubiousjim committed
4
5
VERSION=@VERSION@

Natanael Copa's avatar
Natanael Copa committed
6
7
8
9
10
11
12
13
. $PREFIX/lib/libalpine.sh

# set up temp dir
init_tmpdir TMPD

LBUCACHE="$TMPD/lbucache"

usage() {
Dubiousjim's avatar
Dubiousjim committed
14
15
16
17
18
19
20
21
	cat >&2 << __EOF__
$PROGRAM $VERSION
Usage: $PROGRAM [-a|--all] [-i|--initd] [-l|--list] [-h|--help]
Options:
  -a, --all    Select all updated files
  -i, --initd  Use all new init.d scripts
  -l, --list   List updated files
  -h, --help   Show this help
Natanael Copa's avatar
Natanael Copa committed
22

Dubiousjim's avatar
Dubiousjim committed
23
__EOF__
Natanael Copa's avatar
Natanael Copa committed
24
25
26
27
28
}


is_modified() {
	[ -f "$LBUCACHE" ] || lbu status -a | awk '{print $2}' > "$LBUCACHE"
29
	test -n "$( ( echo \"$1\" ; cat \"$LBUCACHE\" ) | sort | uniq -d)"
Natanael Copa's avatar
Natanael Copa committed
30
31
}

32
33
34
35
36

is_initd() {
	echo "$1" | grep etc/init.d/ > /dev/null
}

37
args=$(getopt -o ailh --long all,initd,list,help -n "$PROGRAM" -- "$@")
Dubiousjim's avatar
Dubiousjim committed
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
if [ $? -ne 0 ]; then
	usage
	exit 2
fi
eval set -- "$args"
while true; do
	case $1 in
		-a|--all) aflag="-a";;
		-i|--initd) iflag="-i";;
		-l|--list) lflag="-l";;
		-h|--help) usage; exit;;
		--) shift; break;;
		*) exit 1;; # getopt error
	esac
	shift
Natanael Copa's avatar
Natanael Copa committed
53
54
done

Dubiousjim's avatar
Dubiousjim committed
55
56
57
58
59
if which vimdiff >/dev/null; then
	vflag=", Vimdiff old new"
	vflag2="/v"
fi

60
for apknew in $(find "$ROOT/etc" -name '*.apk-new') ; do
Natanael Copa's avatar
Natanael Copa committed
61
62
63
64
65
	p="${apknew%.apk-new}"
	f="${p#${ROOT}/}"
	unset choice

	if [ "$lflag" ] ; then
66

Natanael Copa's avatar
Natanael Copa committed
67
68
69
70
		# just list the file
		if [ "$aflag" ] || is_modified "$f" ; then
			echo "$p"
		fi
71

Natanael Copa's avatar
Natanael Copa committed
72
	elif [ "$aflag" ] || is_modified "$f" ; then
73
74
75
76
77
		if [ "$iflag" ] && is_initd "$f" ; then
			echo "Autoupdating $p"
			mv "$apknew" "$p"
			continue
		fi
78

79
80
		diff -u "$p" "$apknew"

Natanael Copa's avatar
Natanael Copa committed
81
82
83
		# ask user what to do with the file
		while [ -z "$choice" ] ; do
			echo "New $p available:"
Dubiousjim's avatar
Dubiousjim committed
84
			echon "Quit, Next, Show diff, Edit new${vflag}, Zap new, Use new (q/n/s/e${vflag2}/z/u) [s]: "
Natanael Copa's avatar
Natanael Copa committed
85
86
87
88
89
90
			default_read choice "s" </dev/tty
			case "$choice" in
				q) exit;;
				n) continue;;
				s) diff -u "$p" "$apknew" | ${PAGER:-less}
				   unset choice
91
				   ;;
Natanael Copa's avatar
Natanael Copa committed
92
				e) ${EDITOR:-vi} "$apknew" ; unset choice;;
Dubiousjim's avatar
Dubiousjim committed
93
94
95
96
				v) if [ "$vflag" ]; then
					vimdiff "$p" "$apknew"
				   fi
				   unset choice;;
Natanael Copa's avatar
Natanael Copa committed
97
98
99
100
101
102
103
104
105
106
107
				z) rm "$apknew";;
				u) mv "$apknew" "$p";;
				*) unset choice;;
			esac
		done
	else
		# auto update
		echo "Autoupdating unchanged $p"
		mv "$apknew" "$p"
	fi
done