BASH   60

asterisk old

Guest on 15th May 2022 04:44:45 PM

  1. #!/bin/bash
  2.  
  3. cmd=$1
  4. app=asterisk
  5. appcli=/usr/sbin/$app
  6. apppath=/etc/$app
  7. initpath=/etc/init.d
  8.  
  9. url=https://www.ubuntu.com/pub/linux/asterisk/11.2.1/asterisk-11-current.tar.gz
  10. dirname=asterisk-11.2.1
  11.  
  12. cronfile=/var/spool/cron/crontabs/root
  13. configpath=/etc/asterisk/config
  14. sudofile=/etc/sudoers
  15. logdir=/var/log/$app
  16. logfile=$logdir/`basename $0`.log
  17. messages=/var/log/asterisk/messages
  18. logtime=`date +%Y%m%d%H%I%M%S`
  19. unix=`date +%s`
  20. dow=`date +%u`
  21.  
  22. mkdir -p $logdir
  23. touch $logfile
  24. tail -n 10000 $logfile > $logfile.tmp
  25. mv $logfile.tmp $logfile
  26.  
  27. if [ -z "$cmd" ];then
  28. echo
  29. echo Usage: ./`basename $0` cron/dialplan/restart/stop/start/peers/registry/status
  30. echo Usage: ./`basename $0` setup
  31. echo
  32. exit
  33. fi
  34.  
  35. if [ "$cmd" != "setup" ];then
  36. if [ -d "$configpath" ];then
  37. chown -R www-data:www-data $configpath
  38. fi
  39. fi
  40.  
  41. if [ "$cmd" == "active" ];then
  42. $appcli -rx 'core show channels' | grep 'active call' | cut -d ' ' -f1
  43. $appcli -rx 'core show channels'
  44. $appcli -rx 'core show channels' | grep 'Outgoing Line' | cut -d ' ' -f1
  45. exit
  46. fi
  47.  
  48. if [ "$cmd" == "status" ];then
  49. $initpath/$app status
  50. exit
  51. fi
  52.  
  53. if [ "$cmd" == "start" ];then
  54. $initpath/$app start
  55. echo "$unix|$logtime|start|" >> $logfile
  56. exit
  57. fi
  58.  
  59. if [ "$cmd" == "stop" ];then
  60. $initpath/$app stop
  61. echo "$unix|$logtime|stop|" >> $logfile
  62. exit
  63. fi
  64.  
  65. if [ "$cmd" == "reload" ];then
  66. $initpath/$app reload
  67. echo "$unix|$logtime|reload|" >> $logfile
  68. if [ -z `pidof $app` ];then
  69. $initpath/$app start
  70. /usr/sbin/service $app restart
  71. echo "$unix|$logtime|start|" >> $logfile
  72. fi
  73. exit
  74. fi
  75.  
  76. if [ "$cmd" == "restart" ];then
  77. if [ -d "$onfigpath.$dow" ];then
  78. rm -rf $configpath.$dow
  79. fi
  80. cp -Rp $configpath $configpath.$dow
  81. tail -n 1000000 $messages > $messages.tmp
  82. mv $messages.tmp $messages
  83. chown -R asterisk:asterisk $messages
  84. if [ -z `pidof $app` ];then
  85. $initpath/$app start
  86. echo "$unix|$logtime|start|" >> $logfile
  87. else
  88. /usr/sbin/service $app stop
  89. /usr/bin/killall $app
  90. /usr/sbin/service $app start
  91. if [ -z `pidof $app` ];then
  92. rm -r $apppath
  93. cp -Rp $apppath.tmp $apppath
  94. echo "$unix|$logtime|restart|" >> $logfile
  95. $initpath/$app restart
  96. /usr/sbin/service $app restart
  97. fi
  98. if [ -z `pidof $app` ];then
  99. /usr/bin/killall $app
  100. $initpath/$app start
  101. /usr/sbin/service $app restart
  102. fi
  103. if [ ! -z `pidof $app` ];then
  104. rm -r $apppath.tmp
  105. cp -Rp $apppath $apppath.tmp
  106. echo "$unix|$logtime|tmpdir|" >> $logfile
  107. fi
  108. exit
  109. fi
  110. fi
  111.  
  112. if [ "$cmd" == "dialplan" ];then
  113. $appcli -rx 'dialplan reload'
  114. exit
  115. fi
  116.  
  117. if [ "$cmd" == "registry" ];then
  118. $appcli -rx 'sip show registry'
  119. exit
  120. fi
  121.  
  122. if [ "$cmd" == "peers" ];then
  123. $appcli -rx 'sip show peers'
  124. exit
  125. fi
  126.  
  127. if [ "$cmd" == "-v" ];then
  128. $initpath/$app reload
  129. /usr/sbin/service $app reload
  130. $appcli -vvvvvr
  131. exit
  132. fi
  133.  
  134. if [ "$cmd" == "fix" ];then
  135. if [ -f "$cronfile" ];then
  136. grep -v "$0" $cronfile > $cronfile.tmp
  137. mv $cronfile.tmp $cronfile
  138. fi
  139. crontab -l > $cronfile.tmp
  140. echo "30 03 * * * $0 restart" >> $cronfile.tmp
  141. echo "00 * * * * $0 reload" >> $cronfile.tmp
  142. echo "* * * * * $0 cron" >> $cronfile.tmp
  143. crontab $cronfile.tmp
  144. rm $cronfile.tmp
  145. echo "$unix|$logtime|cron fixed|" >> $logfile
  146.  
  147. grep -v "$0" $sudofile > $sudofile.tmp
  148. mv $sudofile.tmp $sudofile
  149. echo "www-data ALL=NOPASSWD: $0" >> $sudofile
  150. chmod 0440 $sudofile
  151. echo "$unix|$logtime|sudo fixed|" >> $logfile
  152. exit
  153. fi
  154.  
  155. if [ "$cmd" == "setup" ];then
  156. cd $HOME
  157. apt-get update && apt-get upgrade --yes
  158. apt-get install gcc g++ make libncurses5-dev libxml2 libxml2-dev --yes
  159. wget -O $HOME/$dirname.tar.gz $url
  160. tar xzvf $HOME/$dirname.tar.gz
  161.  
  162. if [ -f "$cronfile" ];then
  163. grep -v "$0" $cronfile > $cronfile.tmp
  164. mv $cronfile.tmp $cronfile
  165. fi
  166. crontab -l > $cronfile.tmp
  167. echo "30 03 * * * $0 restart" >> $cronfile.tmp
  168. echo "00 * * * * $0 reload" >> $cronfile.tmp
  169. echo "* * * * * $0 cron" >> $cronfile.tmp
  170. crontab $cronfile.tmp
  171. rm $cronfile.tmp
  172. echo "$unix|$logtime|cron added|" >> $logfile
  173.  
  174. grep -v "$0" $sudofile > $sudofile.tmp
  175. mv $sudofile.tmp $sudofile
  176. echo "www-data ALL=NOPASSWD: $0" >> $sudofile
  177. chmod 0440 $sudofile
  178. echo "$unix|$logtime|sudo added|" >> $logfile
  179.  
  180. cd $HOME/$dirname
  181. ./configure --disable-xmldoc
  182. make
  183. make install
  184. make samples
  185. make config
  186. $app -vvvvvc
  187. #else
  188. #echo
  189. #echo No $dirname directory founded?
  190. #echo
  191. fi
  192. exit
  193. fi
  194.  
  195. if [ "$cmd" == "cron" ];then
  196. word=Auth
  197. if [ ! -z  "`/usr/sbin/asterisk -r -x "sip show registry" | grep $word`" ];then
  198. $initpath reload
  199. if [ -z `pidof $app` ];then
  200. echo $initpath/$app start
  201. $initpath/$app start
  202. fi
  203. echo "$unix|$logtime|reload|" >> $logfile
  204. exit
  205. fi
  206. echo "$unix|$logtime|cron|" >> $logfile
  207. tail -n 10000 $logfile > $logfile.tmp
  208. mv $logfile.tmp $logfile
  209. fi
  210.  
  211. # last check
  212. if [ -z "`pidof $app`" ];then
  213. $initpath/$app start
  214. else
  215. $initpath/$app restart
  216. fi

Raw Paste


Login or Register to edit or fork this paste. It's free.