asterisk.spec 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. ##
  2. ## asterisk.spec -- OpenPKG RPM Package Specification
  3. ## Copyright (c) 2000-2009 OpenPKG Foundation e.V. <http://openpkg.net/>
  4. ##
  5. ## Permission to use, copy, modify, and distribute this software for
  6. ## any purpose with or without fee is hereby granted, provided that
  7. ## the above copyright notice and this permission notice appear in all
  8. ## copies.
  9. ##
  10. ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  11. ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  12. ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  13. ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
  14. ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  15. ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  16. ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  17. ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  18. ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  19. ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  20. ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  21. ## SUCH DAMAGE.
  22. ##
  23. # package version
  24. %define V_opkg 1.6.1.6
  25. %define V_asterisk 1.6.1.6
  26. %define V_asterisk_addons 1.6.1.1
  27. %define V_asterisk_sounds_core_en 1.4.16
  28. %define V_asterisk_sounds_core_de current
  29. %define V_asterisk_sounds_extra_en 1.4.9
  30. %define V_chan_capi 1.1.4
  31. # package information
  32. Name: asterisk
  33. Summary: Private Branch Exchange (PBX)
  34. URL: http://www.asterisk.org/
  35. Vendor: Mark Spencer et al.
  36. Packager: OpenPKG Foundation e.V.
  37. Distribution: OpenPKG Community
  38. Class: BASE
  39. Group: VoIP
  40. License: GPL
  41. Version: %{V_opkg}
  42. Release: 20090915
  43. # package options
  44. %option with_dahdi no
  45. %option with_capi no
  46. %option with_ogg no
  47. %option with_mp3 no
  48. %option with_fax no
  49. %option with_avcodec no
  50. %option with_ldap no
  51. %option with_radius no
  52. %option with_sqlite no
  53. %option with_lua no
  54. %option with_jabber no
  55. %option with_imap no
  56. %option with_odbc no
  57. # list of sources
  58. Source0: http://downloads.asterisk.org/pub/telephony/asterisk/releases/asterisk-%{V_asterisk}.tar.gz
  59. Source1: http://downloads.asterisk.org/pub/telephony/asterisk/releases/asterisk-addons-%{V_asterisk_addons}.tar.gz
  60. Source2: http://downloads.asterisk.org/pub/telephony/sounds/releases/asterisk-core-sounds-en-alaw-%{V_asterisk_sounds_core_en}.tar.gz
  61. Source3: http://downloads.asterisk.org/pub/telephony/sounds/releases/asterisk-extra-sounds-en-alaw-%{V_asterisk_sounds_extra_en}.tar.gz
  62. Source4: http://www.amooma.de/asterisk/sprachbausteine/asterisk-core-sounds-de-gsm-%{V_asterisk_sounds_core_de}.tar.gz
  63. Source5: ftp://ftp.chan-capi.org/chan-capi/chan_capi-%{V_chan_capi}.tar.gz
  64. Source6: asterisk.txt
  65. Source7: rc.asterisk
  66. Patch0: asterisk.patch
  67. # build information
  68. Prefix: %{l_prefix}
  69. BuildRoot: %{l_buildroot}
  70. BuildPreReq: OpenPKG, openpkg >= 20040130, bison, gcc, make, grep
  71. PreReq: OpenPKG, openpkg >= 20040130, MTA
  72. BuildPreReq: zlib, curl, openssl, ncurses, speex, popt, gmime22
  73. PreReq: zlib, curl, openssl, ncurses, speex, popt, gmime22
  74. %if "%{with_ogg}" == "yes"
  75. BuildPreReq: vorbis-libs
  76. PreReq: vorbis-libs
  77. %endif
  78. %if "%{with_mp3}" == "yes"
  79. PreReq: mpg123
  80. %endif
  81. %if "%{with_imap}" == "yes"
  82. BuildPreReq: imap
  83. PreReq: imap
  84. %endif
  85. %if "%{with_sqlite}" == "yes"
  86. BuildPreReq: sqlite
  87. PreReq: sqlite
  88. %endif
  89. %if "%{with_lua}" == "yes"
  90. BuildPreReq: lua
  91. PreReq: lua
  92. %endif
  93. %if "%{with_fax}" == "yes"
  94. BuildPreReq: spandsp, tiff, jpeg, zlib
  95. PreReq: spandsp, tiff, jpeg, zlib
  96. %endif
  97. %if "%{with_avcodec}" == "yes"
  98. BuildPreReq: ffmpeg
  99. PreReq: ffmpeg
  100. %endif
  101. %if "%{with_ldap}" == "yes"
  102. BuildPreReq: openldap
  103. PreReq: openldap
  104. %endif
  105. %if "%{with_radius}" == "yes"
  106. BuildPreReq: radiusclient
  107. PreReq: radiusclient
  108. %endif
  109. %if "%{with_jabber}" == "yes"
  110. BuildPreReq: iksemel
  111. PreReq: iksemel
  112. %endif
  113. %if "%{with_odbc}" == "yes"
  114. BuildPreReq: unixodbc, sqlite, sqlite::with_odbc = yes
  115. PreReq: unixodbc, sqlite, sqlite::with_odbc = yes
  116. %endif
  117. AutoReq: no
  118. AutoReqProv: no
  119. %description
  120. Asterisk is a complete Private Branch Exchange (PBX) in software.
  121. It provides all of the features you would expect from a PBX and
  122. more. Asterisk does Voice over IP (VoIP) in many protocols. Asterisk
  123. provides Voicemail services with Directory, Call Conferencing,
  124. Interactive Voice Response and Call Queuing. It has support for
  125. three-way calling, caller ID services, ADSI, SIP, etc. Asterisk
  126. needs no additional hardware for VoIP.
  127. %track
  128. prog asterisk = {
  129. version = %{V_asterisk}
  130. url = http://downloads.asterisk.org/pub/telephony/asterisk/releases/
  131. regex = asterisk-(\d+\.\d+(\.\d+)+)\.tar\.gz
  132. }
  133. prog asterisk:addons = {
  134. version = %{V_asterisk_addons}
  135. url = http://downloads.asterisk.org/pub/telephony/asterisk/releases/
  136. regex = asterisk-addons-(\d+\.\d+(\.\d+)+)\.tar\.gz
  137. }
  138. prog asterisk:sounds_core_en = {
  139. version = %{V_asterisk_sounds_core_en}
  140. url = http://downloads.asterisk.org/pub/telephony/sounds/releases/
  141. regex = asterisk-core-sounds-en-alaw-(\d+\.\d+(\.\d+)+)\.tar\.gz
  142. }
  143. prog asterisk:sounds_extra_en = {
  144. version = %{V_asterisk_sounds_extra_en}
  145. url = http://downloads.asterisk.org/pub/telephony/sounds/releases/
  146. regex = asterisk-extra-sounds-en-alaw-(\d+\.\d+(\.\d+)+)\.tar\.gz
  147. }
  148. prog asterisk:sounds_core_de = {
  149. version = %{V_asterisk_sounds_core_de}
  150. url = http://www.amooma.de/asterisk/sprachbausteine/
  151. regex = asterisk-core-sounds-de-gsm-(__VER__)\.tar\.gz
  152. }
  153. prog asterisk:chan_capi = {
  154. version = %{V_chan_capi}
  155. url = ftp://ftp.chan-capi.org/chan-capi/
  156. regex = chan_capi-(__VER__)\.tar\.gz
  157. }
  158. %prep
  159. %setup -q -n asterisk-%{V_asterisk}
  160. %setup -q -n asterisk-%{V_asterisk} -D -T -a 1
  161. %setup -q -n asterisk-%{V_asterisk} -D -T -a 5
  162. %patch -p0
  163. exit 0
  164. cp %{SOURCE2} %{SOURCE3} sounds/
  165. %{l_shtool} subst \
  166. -e 's;\(CORE_SOUNDS_VERSION\):=.*$;\1:=%{V_asterisk_sounds_core_en};' \
  167. -e 's;\(EXTRA_SOUNDS_VERSION\):=.*$;\1:=%{V_asterisk_sounds_extra_en};' \
  168. sounds/Makefile
  169. %{l_shtool} subst \
  170. -e 's;-lradiusclient-ng;-lradiusclient;g' \
  171. -e 's;radiusclient-ng\.h;radiusclient.h;g' \
  172. configure cdr/cdr_radius.c
  173. %build
  174. # sanity check
  175. %if "%{with_dahdi}" == "yes"
  176. dahdi_prefix=""
  177. case "%{l_platform -t}" in
  178. *-linux* )
  179. if [ ! -f /usr/include/linux/dahdi.h ]; then
  180. echo "option \"with_dahdi\" requires DAHDI Linux drivers installed" 1>&2; exit 1
  181. fi
  182. dahdi_prefix=/usr
  183. ;;
  184. *-freebsd* )
  185. if [ ! -f /usr/local/include/dahdi/dahdi.h ]; then
  186. echo "option \"with_dahdi\" requires DAHDI FreeBSD drivers installed" 1>&2; exit 1
  187. fi
  188. dahdi_prefix=/usr/local
  189. ;;
  190. * ) echo "option \"with_dahdi\" supported under Linux and FreeBSD only" 1>&2; exit 1 ;;
  191. esac
  192. %endif
  193. # re-configure music-on-hold to find mpg123
  194. %if "%{with_mp3}" == "yes"
  195. mpg123="%{l_prefix}/bin/mpg123"
  196. %else
  197. mpg123="`which false`"
  198. %endif
  199. %{l_shtool} subst \
  200. -e "s;/usr/local/bin/mpg123;$mpg123;" \
  201. -e "s;/usr/bin/mpg123;$mpg123;" \
  202. res/res_musiconhold.c apps/app_mp3.c
  203. # build program
  204. %{l_shtool} subst \
  205. -e 's;-llua5\.1;-llua;' \
  206. -e 's;lua5\.1/lua\.h;lua/lua.h;' \
  207. -e 's;ffmpeg/avcodec\.h;libavcodec/avcodec.h;' \
  208. configure
  209. ( echo "ac_cv_prog_CONFIG_GMIME=%{l_prefix}/bin/gmime-config"
  210. ) >config.cache
  211. cflags="%{l_cflags -O}"
  212. cppflags="%{l_cppflags ncurses lua .}"
  213. ldflags="%{l_ldflags}"
  214. libs=""
  215. cppflags="$cppflags `pkg-config gmime-2.0 --cflags-only-I`"
  216. ldflags="$ldflags `pkg-config gmime-2.0 --libs-only-L`"
  217. libs="$libs `pkg-config gmime-2.0 --libs-only-l`"
  218. %if "%{with_ogg}" == "yes"
  219. libs="$libs -logg -lm"
  220. %endif
  221. %if "%{with_avcodec}" == "yes"
  222. libs="$libs -lavcodec -lavutil"
  223. %endif
  224. %if "%{with_ldap}" == "yes"
  225. libs="$libs -lldap -llber -lssl -lcrypto"
  226. %endif
  227. %if "%{with_dahdi}" == "yes"
  228. cppflags="$cppflags -I$dahdi_prefix/include"
  229. ldflags="$ldflags -L$dahdi_prefix/lib"
  230. %endif
  231. CC="%{l_cc}" \
  232. CFLAGS="$cflags" \
  233. CPPFLAGS="$cppflags" \
  234. LDFLAGS="$ldflags" \
  235. LIBS="$libs" \
  236. ./configure \
  237. --cache-file=./config.cache \
  238. --prefix=%{l_prefix} \
  239. --mandir=%{l_prefix}/man \
  240. --sysconfdir=%{l_prefix}/etc \
  241. --localstatedir=%{l_prefix}/var/asterisk \
  242. --with-curl=%{l_prefix} \
  243. --with-ncurses \
  244. --with-gsm="internal" \
  245. --with-popt=%{l_prefix} \
  246. %if "%{with_sqlite}" == "yes"
  247. --with-sqlite3=%{l_prefix} \
  248. %else
  249. --without-sqlite3 \
  250. %endif
  251. --with-speex=%{l_prefix} \
  252. --with-speexdsp=%{l_prefix} \
  253. --with-ssl=%{l_prefix} \
  254. --with-gmime=%{l_prefix} \
  255. --with-z=%{l_prefix} \
  256. %if "%{with_ogg}" == "yes"
  257. --with-ogg=%{l_prefix} \
  258. --with-vorbis=%{l_prefix} \
  259. %else
  260. --without-ogg \
  261. --without-vorbis \
  262. %endif
  263. %if "%{with_jabber}" == "yes"
  264. --with-iksemel=%{l_prefix} \
  265. %else
  266. --without-iksemel \
  267. %endif
  268. %if "%{with_lua}" == "yes"
  269. --with-lua=%{l_prefix} \
  270. %else
  271. --without-lua \
  272. %endif
  273. %if "%{with_dahdi}" == "yes"
  274. --with-dahdi=$dahdi_prefix \
  275. --with-tonezone=$dahdi_prefix \
  276. %else
  277. --without-dahdi \
  278. --without-tonezone \
  279. %endif
  280. %if "%{with_avcodec}" == "yes"
  281. --with-avcodec=%{l_prefix} \
  282. %else
  283. --without-avcodec \
  284. %endif
  285. %if "%{with_ldap}" == "yes"
  286. --with-ldap=%{l_prefix} \
  287. %else
  288. --without-ldap \
  289. %endif
  290. %if "%{with_radius}" == "yes"
  291. --with-radius=%{l_prefix} \
  292. %else
  293. --without-radius \
  294. %endif
  295. %if "%{with_imap}" == "yes"
  296. --with-imap=%{l_prefix} \
  297. %else
  298. --without-imap \
  299. %endif
  300. %if "%{with_odbc}" == "yes"
  301. --with-odbc=%{l_prefix} \
  302. %else
  303. --without-odbc \
  304. %endif
  305. --without-netsnmp \
  306. --without-isdnnet \
  307. --without-misdn \
  308. --without-kde \
  309. --without-nbs \
  310. --without-newt \
  311. --without-asound \
  312. --without-oss \
  313. --without-qt \
  314. --without-sqlite \
  315. --without-postgres \
  316. --without-tds \
  317. --without-osptk \
  318. --without-pri \
  319. --without-suppserv \
  320. --without-vpb \
  321. --without-sdl \
  322. --without-x11 \
  323. --without-gtk \
  324. --without-gtk2
  325. %{l_make} %{l_mflags} \
  326. CC="%{l_cc} $cflags -I. -I./include -I../include -I../../include $cppflags"
  327. # build addon modules
  328. ( cd asterisk-addons-*
  329. ASTERISK_DIR="`pwd`/.." \
  330. CC="%{l_cc}" \
  331. CFLAGS="%{l_cflags -O}" \
  332. CPPFLAGS="%{l_cppflags ncurses tiff .}" \
  333. LDFLAGS="%{l_ldflags}" \
  334. %if "%{with_fax}" == "yes"
  335. LIBS="-ltiff -ljpeg -lz -lm" \
  336. %else
  337. LIBS="-lm" \
  338. %endif
  339. ./configure \
  340. --prefix=%{l_prefix} \
  341. --mandir=%{l_prefix}/man \
  342. --sysconfdir=%{l_prefix}/etc \
  343. --localstatedir=%{l_prefix}/var/asterisk \
  344. --with-ncurses \
  345. --with-asterisk \
  346. --without-mysqlclient \
  347. %if "%{with_fax}" == "yes"
  348. --with-spandsp=%{l_prefix}
  349. %else
  350. --without-spandsp
  351. %endif
  352. %{l_make} %{l_mflags} \
  353. CC="%{l_cc} %{l_cflags -O} -I. %{l_cppflags ncurses tiff .}"
  354. ) || exit $?
  355. %if "%{with_capi}" == "yes"
  356. ( cd chan_capi-*
  357. ln -s ../include/asterisk .
  358. ln -s ../include/asterisk.h .
  359. %{l_make} %{l_mflags} \
  360. INSTALL_PREFIX=%{l_prefix} \
  361. ASTERISK_HEADER_DIR="`pwd`"
  362. ) || exit $?
  363. %endif
  364. %install
  365. # install program
  366. rm -rf $RPM_BUILD_ROOT
  367. %{l_make} %{l_mflags} install \
  368. DESTDIR=$RPM_BUILD_ROOT \
  369. INSTALL_PREFIX=%{l_prefix}
  370. # install addon modules
  371. ( cd asterisk-addons-*
  372. %{l_make} %{l_mflags} install \
  373. DESTDIR=$RPM_BUILD_ROOT \
  374. INSTALL_PREFIX=%{l_prefix}
  375. ) || exit $?
  376. %if "%{with_capi}" == "yes"
  377. ( cd chan_capi-*
  378. %{l_make} %{l_mflags} install \
  379. INSTALL_PREFIX=$RPM_BUILD_ROOT%{l_prefix} \
  380. INSTALL="%{l_shtool} install -c" \
  381. MODULES_DIR='$(INSTALL_PREFIX)/lib/asterisk/modules'
  382. ) || exit $?
  383. %endif
  384. # install addon sounds
  385. %{l_shtool} mkdir -f -p -m 755 \
  386. $RPM_BUILD_ROOT%{l_prefix}/share/asterisk/sounds/de
  387. ( cd $RPM_BUILD_ROOT%{l_prefix}/share/asterisk/sounds/de
  388. %{l_gzip} -d -c %{SOURCE4} | %{l_tar} xf -
  389. ) || exit $?
  390. # strip down installation
  391. rm -f $RPM_BUILD_ROOT%{l_prefix}/sbin/autosupport >/dev/null 2>&1 || true
  392. rm -f $RPM_BUILD_ROOT%{l_prefix}/sbin/safe_asterisk >/dev/null 2>&1 || true
  393. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man8/autosupport.8 >/dev/null 2>&1 || true
  394. rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man8/safe_asterisk.8 >/dev/null 2>&1 || true
  395. rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/asterisk/firmware >/dev/null 2>&1 || true
  396. rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/asterisk/images >/dev/null 2>&1 || true
  397. rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/asterisk/sounds/.asterisk* >/dev/null 2>&1 || true
  398. rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/asterisk/sounds/en/CREDIT* >/dev/null 2>&1 || true
  399. rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/asterisk/sounds/en/CHANGES* >/dev/null 2>&1 || true
  400. rmdir $RPM_BUILD_ROOT%{l_prefix}/share/asterisk/sounds/es >/dev/null 2>&1 || true
  401. rmdir $RPM_BUILD_ROOT%{l_prefix}/share/asterisk/sounds/fr >/dev/null 2>&1 || true
  402. # create additional directories
  403. %{l_shtool} mkdir -f -p -m 755 \
  404. $RPM_BUILD_ROOT%{l_prefix}/var/asterisk/db
  405. # post-adjust installation
  406. strip $RPM_BUILD_ROOT%{l_prefix}/sbin/* >/dev/null 2>&1 || true
  407. mv $RPM_BUILD_ROOT%{l_prefix}/share/asterisk/agi-bin \
  408. $RPM_BUILD_ROOT%{l_prefix}/lib/asterisk/agi-bin
  409. for bin in $RPM_BUILD_ROOT%{l_prefix}/lib/asterisk/agi-bin/*.*; do
  410. mv $bin `echo $bin | sed -e 's;\.[^.]*$;;'`
  411. done
  412. # install default configuration
  413. for name in `grep "^<file" %{SOURCE asterisk.txt} | sed -e 's;^.*name=";;' -e 's;".*$;;'`; do
  414. %if "%{with_dahdi}" == "no"
  415. [ ".$name" = ".chan_dahdi.conf" ] && continue
  416. %endif
  417. %if "%{with_capi}" == "no"
  418. [ ".$name" = ".capi.conf" ] && continue
  419. %endif
  420. %if "%{with_sqlite}" == "no"
  421. [ ".$name" = ".cdr_sqlite3_custom.conf" ] && continue
  422. %endif
  423. %if "%{with_odbc}" == "no"
  424. [ ".$name" = ".res_odbc.conf" ] && continue
  425. [ ".$name" = ".func_odbc.conf" ] && continue
  426. %endif
  427. (echo ""; cat %{SOURCE asterisk.txt}; echo "") |\
  428. sed -e "1,/^<file name=\"$name\">/d" -e "/<\/file>/,\$d" >$name
  429. %{l_shtool} install -c -m 644 %{l_value -s -a} \
  430. $name $RPM_BUILD_ROOT%{l_prefix}/etc/asterisk/
  431. done
  432. # install run-command script
  433. %{l_shtool} mkdir -f -p -m 755 \
  434. $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
  435. %{l_shtool} install -c -m 755 %{l_value -s -a} \
  436. %{SOURCE rc.asterisk} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
  437. # determine installation files
  438. %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
  439. %{l_files_std} \
  440. '%config %attr(640,%{l_mgrp},%{l_rgrp}) %{l_prefix}/etc/asterisk/*' \
  441. '%attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/asterisk'
  442. %files -f files
  443. %clean
  444. rm -rf $RPM_BUILD_ROOT
  445. %post
  446. %if "%{with_dahdi}" == "yes"
  447. if [ $1 -eq 1 ]; then
  448. case "%{l_platform -t}" in
  449. *-freebsd* )
  450. ( echo "To allow Asterisk to use the DAHDI /dev/dahdi/pseudo device(s)"
  451. echo "you have add the following entry to /etc/devfs.rules:"
  452. echo ""
  453. echo "[openpkg_asterisk=10]"
  454. echo "add path 'dahdi/pseudo*' mode 0664 user %{l_rusr} group %{l_rgrp}"
  455. echo ""
  456. ) | %{l_rpmtool} msg -b -t notice
  457. ;;
  458. esac
  459. fi
  460. %endif
  461. %if "%{with_odbc}" == "yes"
  462. # after install, optionally link into ODBC and create database
  463. if $RPM_INSTALL_PREFIX/bin/odbcinst -q -s -n "asterisk-sqlite" >/dev/null 2>&1; then
  464. :
  465. else
  466. ( echo "[asterisk-sqlite]"
  467. echo "Description = Asterisk SQLite Database"
  468. echo "Driver = SQLite3"
  469. echo "Database = $RPM_INSTALL_PREFIX/var/asterisk/db/asterisk.sqlite"
  470. echo "Timeout = 2000"
  471. ) | $RPM_INSTALL_PREFIX/bin/odbcinst -i -s -l -n "asterisk-sqlite" -r >/dev/null 2>&1 || true
  472. fi
  473. if [ ! -f $RPM_INSTALL_PREFIX/var/asterisk/run/asterisk.db ]; then
  474. ( umask 007
  475. echo "CREATE TABLE map (key TEXT, val TEXT);" | $RPM_INSTALL_PREFIX/bin/isql "asterisk-sqlite" -b
  476. chown %{l_rusr}:%{l_rgrp} $RPM_INSTALL_PREFIX/var/asterisk/db/asterisk.sqlite >/dev/null 2>&1 || true
  477. ) || exit $?
  478. fi
  479. %endif
  480. # after upgrade, restart service
  481. [ $1 -eq 2 ] || exit 0
  482. eval `%{l_rc} asterisk status 2>/dev/null`
  483. [ ".$asterisk_active" = .yes ] && %{l_rc} asterisk restart
  484. exit 0
  485. %preun
  486. # before erase, stop service and remove log files
  487. [ $1 -eq 0 ] || exit 0
  488. %{l_rc} asterisk stop 2>/dev/null
  489. rm -f $RPM_INSTALL_PREFIX/var/asterisk/log/* >/dev/null 2>&1 || true
  490. rm -f $RPM_INSTALL_PREFIX/var/asterisk/log/cdr-*/* >/dev/null 2>&1 || true
  491. rm -f $RPM_INSTALL_PREFIX/var/asterisk/run/* >/dev/null 2>&1 || true
  492. rm -f $RPM_INSTALL_PREFIX/var/asterisk/spool/*/* >/dev/null 2>&1 || true
  493. rm -f $RPM_INSTALL_PREFIX/var/asterisk/db/* >/dev/null 2>&1 || true
  494. %if "%{with_odbc}" == "yes"
  495. # before erase, optionally unlink from ODBC and destroy database
  496. $RPM_INSTALL_PREFIX/bin/odbcinst -u -s -l -n "asterisk-sqlite" >/dev/null 2>&1 || true
  497. %endif
  498. exit 0