File: git-stuff.postinst

package info (click to toggle)
git-stuff 11-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 468 kB
  • sloc: sh: 1,072; perl: 152; makefile: 128
file content (114 lines) | stat: -rw-r--r-- 3,030 bytes parent folder | download
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
#!/bin/sh

set -e

. /usr/share/debconf/confmodule

_CONFFILE="/etc/default/git-stuff"
_CRONFILE="/etc/cron.d/git-stuff"

case "${1}" in
	configure)
		db_get git-repack-repositories/enable
		GIT_REPACK_REPOSITORIES_ENABLE="${RET}" # boolean

		db_get git-repack-repositories/directories
		GIT_REPACK_REPOSITORIES_DIRECTORIES="${RET}" # string (w/ empty)

		db_get git-repack-repositories/cron
		GIT_REPACK_REPOSITORIES_CRON="${RET:-@monthly}" # string (w/o empty)

		db_get git-stuff/bash-profile
		GIT_STUFF_BASH_PROFILE="${RET}" # boolean

		db_stop


		## Defaults file handling

		if [ ! -e "${_CONFFILE}" ]
		then

cat > "${_CONFFILE}" << EOF
# /etc/default/git-stuff

GIT_REPACK_REPOSITORIES_ENABLE="${GIT_REPACK_REPOSITORIES_ENABLE}"
GIT_REPACK_REPOSITORIES_DIRECTORIES="${GIT_REPACK_REPOSITORIES_DIRECTORIES}"
EOF

		fi

		cp -a -f "${_CONFFILE}" "${_CONFFILE}.tmp"

		# If the admin deleted or commented some variables but then set
		# them via debconf, (re-)add them to the config file.

		test -z "${GIT_REPACK_REPOSITORIES_ENABLE}" || \
		grep -Eq '^ *GIT_REPACK_REPOSITORIES_ENABLE=' "${_CONFFILE}" || \
		echo "GIT_REPACK_REPOSITORIES_ENABLE=" >> "${_CONFFILE}"

		test -z "${GIT_REPACK_REPOSITORIES_DIRECTORIES}" || \
		grep -Eq '^ *GIT_REPACK_REPOSITORIES_DIRECTORIES=' "${_CONFFILE}" || \
		echo "GIT_REPACK_REPOSITORIES_DIRECTORIES=" >> "${_CONFFILE}"

		sed -e "s|^ *GIT_REPACK_REPOSITORIES_ENABLE=.*|GIT_REPACK_REPOSITORIES_ENABLE=\"${GIT_REPACK_REPOSITORIES_ENABLE}\"|" \
		    -e "s|^ *GIT_REPACK_REPOSITORIES_DIRECTORIES=.*|GIT_REPACK_REPOSITORIES_DIRECTORIES=\"${GIT_REPACK_REPOSITORIES_DIRECTORIES}\"|" \
		< "${_CONFFILE}" > "${_CONFFILE}.tmp"

		mv -f "${_CONFFILE}.tmp" "${_CONFFILE}"


		## Cron file handling

		if [ ! -e "${_CRONFILE}" ]
		then
			mkdir -p /etc/cron.d

cat > "${_CRONFILE}" << EOF
# /etc/cron.d/git-stuff

# By default this is run @monthly, see crontab(5) for more information.
${GIT_REPACK_REPOSITORIES_CRON} root if [ -x /usr/bin/git-repack-repositories-cron ]; then /usr/bin/git-repack-repositories-cron --quiet; fi
EOF

		fi

		cp -a -f "${_CRONFILE}" "${_CRONFILE}.tmp"

		# If the admin deleted or commented some variables but then set
		# them via debconf, (re-)add them to the config file.

		grep -Eq "^${GIT_REPACK_REPOSITORIES_CRON} root" "${_CRONFILE}" || \
		echo "${GIT_REPACK_REPOSITORIES_CRON} root if [ -x /usr/bin/git-repack-repositories ]; then /usr/bin/git-repack-repositories --quiet; fi" >> "${_CRONFILE}"

		sed -e "s|^ *root|${GIT_REPACK_REPOSITORIES_CRON} root|" \
		< "${_CRONFILE}" > "${_CRONFILE}.tmp"

		mv -f "${_CRONFILE}.tmp" "${_CRONFILE}"


		## Bash Profile file handling

		rm -f /etc/profile.d/git-stuff
		rm -f /etc/profile.d/git-stuff.sh

		case "${GIT_STUFF_BASH_PROFILE}" in
			true)
				ln -s /usr/share/git-stuff/git-stuff_profile.sh /etc/profile.d/git-stuff.sh
				;;
		esac
		;;

	abort-upgrade|abort-remove|abort-deconfigure)

		;;

	*)
		echo "postinst called with unknown argument \`${1}'" >&2
		exit 1
		;;
esac

#DEBHELPER#

exit 0