summary refs log tree commit diff
path: root/debian/dash.postinst
blob: 6dd59d12170d44b30a1cdd1fc47de3f6076a63e4 (plain) (blame)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/sh
#
# post-install script for the Debian GNU/Linux dash package
#
# $Id$

set -e

check_divert() {
	div=$(dpkg-divert --list $2)
	distrib=${4:-$2.distrib}
	case "$1" in
	true)
		if [ -z "$div" ]; then
			dpkg-divert --package dash --divert $distrib --add $2
			cp -dp $2 $distrib
			ln -sf $3 $2
		fi
		;;
	false)
		if [ -n "$div" ] && [ -z "${div%%*by dash}" ]; then
			mv $distrib $2
			dpkg-divert --remove $2
		fi
		;;
	ash)
		case $div in
		'')
			;;
		*by\ ash)
			dst=${div% by ash}
			dst=${dst##* to }

			# Work around dpkg-divert bug.
			if [ -e "$dst" ]; then
				mv "$dst" "$dst.dash-tmp"
			fi
			dpkg-divert --remove $2
			if [ -e "$dst.dash-tmp" ]; then
				mv "$dst.dash-tmp" "$dst"
			fi

			dpkg-divert --package dash --divert $distrib --add $2
			if [ "$dst" != $distrib ] && [ -e "$dst" ]; then
				mv "$dst" $distrib
			fi
			ln -sf $3 $2
			;;
		*)
			d=${2%/*}
			if
				[ -h $2 ] && [ -f $2 ] && [ -f $d/$5 ] &&
				cmp $2 $d/$5
			then
				ln -sf $3 $2
			fi
			;;
		esac
	esac
}

add_shell() {
	if ! type add-shell > /dev/null 2>&1; then
		return
	fi

	add-shell /bin/dash
}

debconf=
if [ -f /usr/share/debconf/confmodule ]; then
	. /usr/share/debconf/confmodule
	debconf=yes
fi

if [ "$1" = configure ] && [ -z "$2" ]; then
	check_divert ash /bin/sh dash '' ash
	check_divert ash /usr/share/man/man1/sh.1.gz dash.1.gz \
		/usr/share/man/man1/sh.distrib.1.gz ash.1.gz
	add_shell
elif [ "$1" = configure ] && dpkg --compare-versions "$2" lt 0.4.18; then
	add_shell
fi

if [ $debconf ]; then
	db_get dash/sh
	check_divert "$RET" /bin/sh dash
	check_divert "$RET" /usr/share/man/man1/sh.1.gz dash.1.gz \
		/usr/share/man/man1/sh.distrib.1.gz
fi

#DEBHELPER#