summaryrefslogtreecommitdiff
path: root/mk/install/deinstall
blob: 81444ffa5efed13d9d5a77b3a6aeb442fe0130fe (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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# start of deinstall
#
# $NetBSD: deinstall,v 1.4 2001/11/21 05:38:03 jlam Exp $

ALL_FILES="${CONF_FILES} ${SUPPORT_FILES} ${RCD_SCRIPTS}"
set -- ${CONF_FILES_PERMS} ${SUPPORT_FILES_PERMS}
while [ $# -gt 0 ]
do
	samplefile="$1"; file="$2"; owner="$3"; group="$4"; mode="$5"
	shift; shift; shift; shift; shift 
	ALL_FILES="${ALL_FILES} ${samplefile} ${file}"
done

ALL_MAKE_DIRS="${MAKE_DIRS}"
set -- ${MAKE_DIRS_PERMS}
while [ $# -gt 0 ]
do
	dir="$1"; owner="$2"; group="$3"; mode="$4"
	shift; shift; shift; shift
	ALL_MAKE_DIRS="${ALL_MAKE_DIRS} ${dir}"
done
ALL_DIRS="${ALL_MAKE_DIRS} ${OWN_DIRS}"
set -- ${OWN_DIRS_PERMS}
while [ $# -gt 0 ]
do
	dir="$1"; owner="$2"; group="$3"; mode="$4"
	shift; shift; shift; shift
	ALL_DIRS="${ALL_DIRS} ${dir}"
done
ALL_DIRS=`								\
	${ECHO} ${ALL_DIRS} |						\
	${SED} "s,[ 	][ 	]*, ,g" |				\
	${TR} ' ' "\012" |						\
	${SORT} -r							\
`

case ${STAGE} in
DEINSTALL)
	# Remove configuration files if they don't differ from the default
	# config file.
	#
	set -- ${ALL_FILES}
	while [ $# -gt 0 ]
	do
		samplefile="$1"; file="$2"
		shift; shift

		if [ "${file}" != "${samplefile}" -a			\
		     -e ${file} -a -e ${samplefile} ]
		then
			if ${CMP} -s ${file} ${samplefile}
			then
				${RM} -f ${file}
			fi
		fi
	done
	;;

POST-DEINSTALL)
	modified_files=''
	set -- ${ALL_FILES}
	while [ $# -gt 0 ]
	do
		samplefile="$1"; file="$2"
		shift; shift

		if [ -e ${file} ]
		then
			modified_files="${modified_files} ${file}"
		fi
	done

	existing_dirs=''
	set -- ${ALL_DIRS}
	while [ $# -gt 0 ]
	do
		dir=$1; shift
		is_make_dir=0
		for make_dir in __dummy ${ALL_MAKE_DIRS}
		do
			if [ "${make_dir}" != "__dummy" -a		\
			     "${dir}" = "${make_dir}" ]
			then
				is_make_dir=1
				break
			fi
		done

		${RMDIR} -p ${dir} 2>/dev/null || ${TRUE}
		if [ ${is_make_dir} -eq 0 -a -d ${dir} ]
		then
			existing_dirs="${existing_dirs} ${dir}"
		fi
	done

	if [ -n "${PKG_USER}" -o -n "${PKG_GROUP}" -o			\
	     -n "${modified_files}" -o -n "${existing_dirs}" ]
	then
		${CAT} << EOF
===========================================================================
If you won't be using ${PKGNAME} any longer, you may want to remove
EOF
		if [ -n "${PKG_USER}" ]
		then
			${CAT} << EOF

  * the \`${PKG_USER}' user
EOF
		fi
		if [ -n "${PKG_GROUP}" ]
		then
			${CAT} << EOF

  * the \`${PKG_GROUP}' group
EOF
		fi
		if [ -n "${modified_files}" ]
		then
			${CAT} << EOF

  * the following files:

EOF
			for file in ${modified_files}
			do
				${ECHO} "	${file}"
			done
		fi
		if [ -n "${existing_dirs}" ]
		then
			${CAT} << EOF

  * the following directories:

EOF
			for dir in ${existing_dirs}
			do
				${ECHO} "	${dir}"
			done
		fi
		if [ -n "${RCD_SCRIPTS}" ]
		then
			${CAT} << EOF

You many also want to remove any settings in rc.conf that you may have
made in order to use ${PKGNAME}.
EOF
		fi
		${CAT} << EOF
===========================================================================
EOF
	fi
	;;

*)
	${ECHO} "Unexpected argument: ${STAGE}"
	exit 1
	;;
esac

# end of deinstall