| 1 | #!/bin/sh |
| 2 | # |
| 3 | # asterisk-config-custom |
| 4 | # script to help creating a 'asterisk-config-custom' .deb package |
| 5 | # |
| 6 | # |
| 7 | # Created by: Geert Stappers <[email protected]> |
| 8 | # And distributed under the terms of the GPL |
| 9 | # |
| 10 | # |
| 11 | acc_usage () |
| 12 | { |
| 13 | cat << HERE |
| 14 | |
| 15 | asterisk-config-custom {command} |
| 16 | |
| 17 | Where 'command' is 'init', 'next', 'sync' or 'help' |
| 18 | |
| 19 | init: Creates directory 'my-asterisk-config' with content |
| 20 | |
| 21 | next: Provides instruction for next step |
| 22 | |
| 23 | sync: Mostly \`rsync --archive /etc/asterisk etc_asterisk\` |
| 24 | |
| 25 | help: Prints _another_ help text |
| 26 | |
| 27 | HERE |
| 28 | } |
| 29 | |
| 30 | acc_help () |
| 31 | { |
| 32 | cat << HERE |
| 33 | |
| 34 | Program 'asterisk-config-custom' is for helping you making |
| 35 | your 'asterisk-config-custom' .deb package. |
| 36 | |
| 37 | Typical work flow is running |
| 38 | asterisk-config-custom init |
| 39 | only once. |
| 40 | |
| 41 | Now you have a directory named |
| 42 | my-asterisk-config |
| 43 | feel free to rename it |
| 44 | Important is that it has a debian/ directory |
| 45 | and an etc_asterisk/ directory |
| 46 | |
| 47 | Change working directory with |
| 48 | cd my-asterisk-config # or to what you renamed it. |
| 49 | Edit files in etc_asterisk. You may use |
| 50 | asterisk-config-custom sync |
| 51 | to get you a starting point. |
| 52 | Create the actual package with |
| 53 | dpkg-buildpackge -uc -us |
| 54 | |
| 55 | And install with |
| 56 | sudo dpkg -i ../asterisk-config-custom_*_all.deb |
| 57 | |
| 58 | This package will be considered as an upgrade to the default |
| 59 | \`asterisk-config\` package and hence that package will will be removed |
| 60 | upon isntalling the custom package. However, it will not be purged and |
| 61 | hence all configuration files in \`/etc/asterisk\` from it will remain |
| 62 | installed. In order to remove them, you'll need to purge the package |
| 63 | \`asterisk-config\'. |
| 64 | |
| 65 | Alternatively, you can install the custom package before installing |
| 66 | Asterisk. |
| 67 | |
| 68 | HERE |
| 69 | } |
| 70 | |
| 71 | acc_init () |
| 72 | { |
| 73 | # Creates a diretory and puts files in it, |
| 74 | # including the Debian packaging files. |
| 75 | |
| 76 | mkdir --parents my-asterisk-config/debian/source |
| 77 | |
| 78 | cat << HERE > my-asterisk-config/README |
| 79 | |
| 80 | In this directory you can / should run |
| 81 | |
| 82 | dpkg-buildpackage -uc -us |
| 83 | |
| 84 | to get your 'asterisk-config-custom' package build. |
| 85 | |
| 86 | If you don't have this package installed, install the package dpkg-dev . |
| 87 | |
| 88 | HERE |
| 89 | |
| 90 | cat << LastLine > my-asterisk-config/Makefile |
| 91 | # |
| 92 | # Makefile |
| 93 | # |
| 94 | all: etc_asterisk/asterisk.conf \ |
| 95 | usr/share/doc/asterisk-config/examples/configs/modules.conf.sample |
| 96 | @echo "FYI: (minimal set of) configuration files are available" |
| 97 | |
| 98 | etc_asterisk/asterisk.conf: |
| 99 | @mkdir --parents etc_asterisk |
| 100 | echo "; only a place holder" > etc_asterisk/asterisk.conf |
| 101 | |
| 102 | usr/share/doc/asterisk-config/examples/configs/modules.conf.sample: |
| 103 | @mkdir --parents usr/share/doc/asterisk-config/examples/configs |
| 104 | echo "; place holder" \\ |
| 105 | > usr/share/doc/asterisk-config/examples/configs/modules.conf.sample |
| 106 | |
| 107 | |
| 108 | install: |
| 109 | install --directory \$(DESTDIR)/usr |
| 110 | install --directory \$(DESTDIR)/etc/asterisk |
| 111 | rsync --archive --delete usr/* \$(DESTDIR)/usr |
| 112 | rsync --archive --delete etc_asterisk/* \$(DESTDIR)/etc/asterisk |
| 113 | |
| 114 | # l l |
| 115 | LastLine |
| 116 | |
| 117 | cat << LastLine > my-asterisk-config/acc.config |
| 118 | # This file will be read during \`asterisk-config-custom sync\` |
| 119 | # |
| 120 | ACC_SYNC_CONFIG_EXAMPLES=Yes |
| 121 | # another value as 'Yes' wouldn't sync the configuration examples |
| 122 | # |
| 123 | # |
| 124 | # l l |
| 125 | LastLine |
| 126 | |
| 127 | ##-------------------------------------------- |
| 128 | |
| 129 | # Those who are familiar with Debian packaging |
| 130 | # can consider the rest of this function as a dedicated `dh_make`. |
| 131 | |
| 132 | cat << LastLine > my-asterisk-config/debian/control |
| 133 | Source: asterisk-config-custom |
| 134 | Section: comm |
| 135 | Priority: optional |
| 136 | Maintainer: Me Myself <${LOGNAME}@$( hostname --fqdn )> |
| 137 | Build-Depends: debhelper (>= 9) |
| 138 | Standards-Version: 3.9.5 |
| 139 | Homepage: <insert the upstream URL, if relevant> |
| 140 | #Vcs-Git: git://anonscm.debian.org/collab-maint/asterisk-config-custom.git |
| 141 | #Vcs-Browser: http://anonscm.debian.org/?p=collab-maint/asterisk-config-custom.git;a=summary |
| 142 | |
| 143 | Package: asterisk-config-custom |
| 144 | Architecture: all |
| 145 | Depends: \${misc:Depends} |
| 146 | Recommends: asterisk |
| 147 | Conflicts: asterisk-config |
| 148 | Replaces: asterisk-config |
| 149 | Description: Custom configuration files for Asterisk |
| 150 | Package that contains custom configuration files for Asterisk. |
| 151 | . |
| 152 | It is to keep _your_ config files while upgrading Asterisk. |
| 153 | . |
| 154 | The trick is that Asterisk depends |
| 155 | on asterisk-config OR asterisk-config-custom |
| 156 | LastLine |
| 157 | |
| 158 | cat << LastLine > my-asterisk-config/debian/changelog |
| 159 | asterisk-config-custom (0.6) unstable; urgency=medium |
| 160 | |
| 161 | * Created with \`asterisk-config-custom init\` |
| 162 | |
| 163 | -- Me Myself <${LOGNAME}@$( hostname --fqdn )> $( date --rfc-2822 ) |
| 164 | |
| 165 | asterisk-config-custom (0.4) unstable; urgency=low |
| 166 | |
| 167 | * Initial release (Closes: #760032). |
| 168 | |
| 169 | -- Geert Stappers <[email protected]> Fri, 29 Aug 2014 16:25:44 +0200 |
| 170 | LastLine |
| 171 | |
| 172 | cat << LastLine > my-asterisk-config/debian/copyright |
| 173 | Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ |
| 174 | Upstream-Name: asterisk-config-custom |
| 175 | Source: <url://example.com> |
| 176 | |
| 177 | Files: * |
| 178 | Copyright: <years> <put author's name and email here> |
| 179 | <years> <likewise for another author> |
| 180 | License: <special license> |
| 181 | <Put the license of the package here indented by 1 space> |
| 182 | <This follows the format of Description: lines in control file> |
| 183 | . |
| 184 | <Including paragraphs> |
| 185 | LastLine |
| 186 | |
| 187 | cat << LastLine > my-asterisk-config/debian/rules |
| 188 | #!/usr/bin/make -f |
| 189 | # See debhelper(7) |
| 190 | # |
| 191 | # output every command that modifies files on the build system. |
| 192 | #DH_VERBOSE = 1 |
| 193 | |
| 194 | # main packaging script based on dh7 syntax |
| 195 | %: |
| 196 | dh \$@ |
| 197 | |
| 198 | # l l |
| 199 | LastLine |
| 200 | chmod a+x my-asterisk-config/debian/rules |
| 201 | |
| 202 | cat << LastLine > my-asterisk-config/debian/preinst |
| 203 | #! /bin/sh |
| 204 | # preinst script |
| 205 | # |
| 206 | # see: dh_installdeb(1) |
| 207 | |
| 208 | set -e |
| 209 | |
| 210 | # summary of how this script can be called: |
| 211 | # * <new-preinst> \`install' |
| 212 | # * <new-preinst> \`install' <old-version> |
| 213 | # * <new-preinst> \`upgrade' <old-version> |
| 214 | # * <old-preinst> \`abort-upgrade' <new-version> |
| 215 | # |
| 216 | # for details, see http://www.debian.org/doc/debian-policy/ or |
| 217 | # the debian-policy package |
| 218 | |
| 219 | case "\$1" in |
| 220 | install|upgrade) |
| 221 | # chan_modem was removed on 1.4+ |
| 222 | ;; |
| 223 | |
| 224 | abort-upgrade) |
| 225 | ;; |
| 226 | |
| 227 | *) |
| 228 | echo "preinst called with unknown argument \\\`\$1'" >&2 |
| 229 | exit 1 |
| 230 | ;; |
| 231 | esac |
| 232 | |
| 233 | # dh_installdeb will replace this with shell code automatically |
| 234 | # generated by other debhelper scripts. |
| 235 | |
| 236 | #DEBHELPER# |
| 237 | |
| 238 | exit 0 |
| 239 | LastLine |
| 240 | |
| 241 | cat << LastLine > my-asterisk-config/debian/postinst |
| 242 | #! /bin/sh |
| 243 | |
| 244 | set -e |
| 245 | |
| 246 | # summary of how this script can be called: |
| 247 | # * <postinst> \`configure' <most-recently-configured-version> |
| 248 | # * <old-postinst> \`abort-upgrade' <new version> |
| 249 | # * <conflictor's-postinst> \`abort-remove' \`in-favour' <package> |
| 250 | # <new-version> |
| 251 | # * <deconfigured's-postinst> \`abort-deconfigure' \`in-favour' |
| 252 | # <failed-install-package> <version> \`removing' |
| 253 | # <conflicting-package> <version> |
| 254 | |
| 255 | case "\$1" in |
| 256 | configure) |
| 257 | set +e # ignore errors temporarily |
| 258 | |
| 259 | # find conffiles under /etc/asterisk belonging to asterisk-config-custom |
| 260 | # and chown them to user asterisk. |
| 261 | dpkg-query -W -f='\${Conffiles}\n' asterisk-config-custom 2>/dev/null | \\ |
| 262 | sed -nr -e 's; (/etc/asterisk/.*) [0-9a-f]*;\1;p' | \\ |
| 263 | while read conffile; do |
| 264 | chown asterisk: \${conffile} 2>/dev/null |
| 265 | done |
| 266 | |
| 267 | # handle them in the end with a glob since it's way faster |
| 268 | dpkg-statoverride --quiet --list '/etc/asterisk/*' | while read STAT; do |
| 269 | chown \`echo \$STAT | cut -d' ' -f 1,2,4 | sed 's/ /:/'\` \\ |
| 270 | 2>/dev/null |
| 271 | done |
| 272 | |
| 273 | set -e |
| 274 | ;; |
| 275 | |
| 276 | abort-upgrade|abort-remove|abort-deconfigure) |
| 277 | ;; |
| 278 | |
| 279 | *) |
| 280 | echo "postinst called with unknown argument \\\`\$1'" >&2 |
| 281 | exit 1 |
| 282 | ;; |
| 283 | esac |
| 284 | |
| 285 | # dh_installdeb will replace this with shell code automatically |
| 286 | # generated by other debhelper scripts. |
| 287 | |
| 288 | #DEBHELPER# |
| 289 | |
| 290 | exit 0 |
| 291 | |
| 292 | LastLine |
| 293 | |
| 294 | cat << LastLine > my-asterisk-config/debian/lintian-overrides |
| 295 | asterisk-config-custom: non-standard-file-perm |
| 296 | LastLine |
| 297 | |
| 298 | echo 9 > my-asterisk-config/debian/compat |
| 299 | |
| 300 | echo '3.0 (native)' > my-asterisk-config/debian/source/format |
| 301 | |
| 302 | } |
| 303 | |
| 304 | acc_sync () |
| 305 | { |
| 306 | mkdir --parents etc_asterisk |
| 307 | # assuming there are files in /etc/asterisk/ |
| 308 | rsync --archive --delete /etc/asterisk/* etc_asterisk/ |
| 309 | if [ -r ./acc.config ] ; then |
| 310 | . ./acc.config |
| 311 | else |
| 312 | echo 'E: file "./acc.config" not readable' |
| 313 | echo "I: Are you in the directory that \`${0} init\` created?" |
| 314 | exit 1 |
| 315 | fi |
| 316 | if [ x${ACC_SYNC_CONFIG_EXAMPLES} = xYes ] ; then |
| 317 | ACC_EX=usr/share/doc/asterisk-config/examples |
| 318 | # using asterisk-config directory |
| 319 | mkdir --parents ${ACC_EX} |
| 320 | rsync --archive --delete /${ACC_EX}/* ${ACC_EX} |
| 321 | fi |
| 322 | } |
| 323 | |
| 324 | acc_next () |
| 325 | { |
| 326 | if ! which dpkg-buildpackage > /dev/null ; then |
| 327 | echo 'E: Program `dpkg-buildpackage` is not installed.' |
| 328 | echo 'I: It is in the Debian package `dpkg-dev`.' |
| 329 | echo 'I: Installing it with `apt-get install build-essential`,' |
| 330 | echo 'I: will also install the program `make` that is also needed.' |
| 331 | exit 1 |
| 332 | fi |
| 333 | if grep --quiet 'Package: asterisk-config-custom' debian/control ; then |
| 334 | echo 'dpkg-buildpackage -uc -us # Running this now' |
| 335 | dpkg-buildpackage -uc -us |
| 336 | else |
| 337 | echo 'E: debian/control file for package asterisk-config-custom not found' |
| 338 | echo "I: Are you in the directory that \`${0} init\` created?" |
| 339 | exit 1 |
| 340 | fi |
| 341 | } |
| 342 | |
| 343 | |
| 344 | # main() |
| 345 | |
| 346 | case $1 in |
| 347 | init) |
| 348 | acc_init |
| 349 | ;; |
| 350 | next) |
| 351 | acc_next |
| 352 | ;; |
| 353 | sync) |
| 354 | acc_sync |
| 355 | ;; |
| 356 | help) |
| 357 | acc_help |
| 358 | ;; |
| 359 | *) |
| 360 | acc_usage |
| 361 | ;; |
| 362 | esac |
| 363 | |
| 364 | # l l |