Debian Codegraph @

misc/pkgos-alternative-bin

raw
1 #!/bin/sh
2
3 set -e
4
5 usage () {
6 echo "$0 PKG-NAME bin-name-1 [ bin-name-2 ...]"
7 exit 1
8 }
9
10 if [ $# -lt 2 ] ; then
11 usage
12 fi
13
14 PKG_NAME=${1}
15 PKG_PY2=python-${1}
16 PKG_PY3=python3-${1}
17 shift
18
19 # postinst
20 echo "#!/bin/sh
21
22 set -e
23
24 if [ \"\$1\" = \"configure\" ] ; then" >debian/$PKG_PY2.postinst
25 cp debian/$PKG_PY2.postinst debian/$PKG_PY3.postinst
26
27 # postrm
28 echo "#!/bin/sh
29
30 set -e
31
32 if [ \"\$1\" = \"remove\" ] || [ \"\$1\" = \"disappear\" ] ; then" >debian/$PKG_PY2.postrm
33 cp debian/$PKG_PY2.postrm debian/$PKG_PY3.postrm
34
35 # postrm
36 echo "#!/bin/sh
37
38 set -e
39
40 if [ \"\$1\" = \"remove\" ] ; then" >debian/$PKG_PY2.prerm
41 cp debian/$PKG_PY2.prerm debian/$PKG_PY3.prerm
42
43 RULES_ENTRY=""
44
45 while [ -n "${1}" ] ; do
46 BIN_UTIL_NAME=$1
47 shift
48 echo " update-alternatives --install /usr/bin/${BIN_UTIL_NAME} ${BIN_UTIL_NAME} /usr/bin/python2-${BIN_UTIL_NAME} 300" >>debian/$PKG_PY2.postinst
49 echo " update-alternatives --install /usr/bin/${BIN_UTIL_NAME} ${BIN_UTIL_NAME} /usr/bin/python3-${BIN_UTIL_NAME} 200" >>debian/$PKG_PY3.postinst
50 echo " update-alternatives --remove ${BIN_UTIL_NAME} /usr/bin/python2-${BIN_UTIL_NAME}" >>debian/$PKG_PY2.postrm
51 echo " update-alternatives --remove ${BIN_UTIL_NAME} /usr/bin/python3-${BIN_UTIL_NAME}" >>debian/$PKG_PY3.postrm
52 echo " update-alternatives --remove ${BIN_UTIL_NAME} /usr/bin/python2-${BIN_UTIL_NAME}" >>debian/$PKG_PY2.prerm
53 echo " update-alternatives --remove ${BIN_UTIL_NAME} /usr/bin/python3-${BIN_UTIL_NAME}" >>debian/$PKG_PY3.prerm
54 RULES_ENTRY="${RULES_ENTRY}\n\tmv \$(CURDIR)/debian/${PKG_PY2}/usr/bin/${BIN_UTIL_NAME} \$(CURDIR)/debian/${PKG_PY2}/usr/bin/python2-${BIN_UTIL_NAME}"
55 RULES_ENTRY="${RULES_ENTRY}\n\tmv \$(CURDIR)/debian/${PKG_PY3}/usr/bin/${BIN_UTIL_NAME} \$(CURDIR)/debian/${PKG_PY3}/usr/bin/python3-${BIN_UTIL_NAME}"
56 done
57
58 for i in postinst prerm postrm ; do
59 echo "fi
60
61 #DEBHELPER#
62
63 exit 0">>debian/$PKG_PY2.$i
64 echo "fi
65
66 #DEBHELPER#
67
68 exit 0">>debian/$PKG_PY3.$i
69 done
70
71 echo "I created the below maintainer scripts for you:
72 - debian/$PKG_PY2.postinst
73 - debian/$PKG_PY3.postinst
74 - debian/$PKG_PY2.postrm
75 - debian/$PKG_PY3.postrm
76 - debian/$PKG_PY2.prerm
77 - debian/$PKG_PY3.prerm
78
79 Please make sure to insert this in your debian/rules:
80 ${RULES_ENTRY}
81 "
82 exit 0