uninstall.in 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. #!/bin/sh
  2. # Initialize variables
  3. quiet=0
  4. prompt=0
  5. verb=0
  6. progs=0
  7. config=0
  8. start=0
  9. delusr=0
  10. delgrp=0
  11. delscpt=0
  12. force="-f"
  13. redir=1
  14. # Set file and path names
  15. NAME=@PKG_NAME@
  16. SBINDIR=@sbindir@
  17. LIBEXECDIR=@libexecdir@
  18. PLUGINSDIR=@pluginsdir@
  19. PIDDIR=@piddir@
  20. CFGDIR=@pkgsysconfdir@
  21. INIT_TYPE=@init_type@
  22. INIT_DIR=@initdir@
  23. INIT_FILE=@initname@
  24. INETD_TYPE=@inetd_type@
  25. INETD_DIR=@inetddir@
  26. INETD_FILE=@inetdname@
  27. SRC_INETD=@src_inetd@
  28. SRC_INIT=@src_init@
  29. USERID=@nrpe_user@
  30. GRPID=@nrpe_group@
  31. # Display usage message
  32. usage () {
  33. echo "Usage: $0 [-q] [-p] [-v] progs|config|startup|user|group|script|all"
  34. echo " Optional args:"
  35. echo " -q Do not print what is happening"
  36. echo " -p Prompt for each action"
  37. echo " -v Be a little more verbose about what is happening"
  38. echo " One or more of the following are required:"
  39. echo " progs Delete the program files"
  40. echo " config Delete configuration file(s)"
  41. echo " startup Delete startup files (inetd, init, etc.)"
  42. echo " user Delete the $USERID user"
  43. echo " group Delete the $GRPID group"
  44. echo " script Delete this uninstall script"
  45. echo " all Do all of the above"
  46. exit 1
  47. }
  48. get_opts () {
  49. while test $# -gt 0 ; do
  50. arg=$1
  51. shift
  52. case "$arg" in
  53. -q) quiet=1 ;;
  54. -p) prompt=1 ;;
  55. progs) progs=1 ;;
  56. config) config=1 ;;
  57. startup) start=1 ;;
  58. user) delusr=1; ;;
  59. group) delgrp=1; ;;
  60. script) delscpt=1; ;;
  61. -v) verb=1; force=""; redir=0 ;;
  62. all) progs=1; config=1; start=1 ;;
  63. *) echo "Invalid argument: $arg"; usage ;;
  64. esac
  65. done
  66. if test $prompt -eq 1 -a $quiet -eq 1 ; then
  67. echo "The -p and -q flags are mutually exclusive"
  68. echo Please specify one or the other
  69. exit 1
  70. fi
  71. if test $verb -eq 1 -a $quiet -eq 1 ; then
  72. echo "The -v and -q flags are mutually exclusive"
  73. echo Please specify one or the other
  74. exit 1
  75. fi
  76. if test $progs -eq 0 -a $config -eq 0 -a $start -eq 0 ; then
  77. usage
  78. fi
  79. }
  80. prt_msg () {
  81. if test $quiet -eq 1 ; then
  82. return 0
  83. fi
  84. case $1 in
  85. 0) indent="" ;;
  86. 1) indent=" " ;;
  87. 2) indent=" " ;;
  88. *) indent="" ;;
  89. esac
  90. shift
  91. if test $1 -eq 1 -a $verb -eq 0 -a $prompt -eq 0 ; then
  92. return 0
  93. fi
  94. shift
  95. if test $1 -eq 1 -a $prompt -eq 1 ; then
  96. shift
  97. echo -n "${indent}$*"
  98. echo -n "? [Y|n] "
  99. read yn
  100. if test "x$yn" = x -o x$yn = xy -o x$yn = xY ; then
  101. return 0
  102. else
  103. return 1
  104. fi
  105. fi
  106. shift
  107. echo "${indent}$*"
  108. return 0
  109. }
  110. rm_progs () {
  111. num=0
  112. prt_msg 1 0 0 "*** Uninstalling Progs"
  113. if test -f "$PLUGINSDIR/check_nrpe" ; then
  114. num=1
  115. prt_msg 2 0 1 "Delete $PLUGINSDIR/check_nrpe" && {
  116. rm $force "$PLUGINSDIR/check_nrpe"
  117. prt_msg 2 1 0 "Remove directory $PLUGINSDIR"
  118. if test $redir -eq 1; then
  119. rmdir "$PLUGINSDIR" 2>/dev/null
  120. else
  121. rmdir "$PLUGINSDIR"
  122. fi
  123. prt_msg 2 1 0 "Remove directory $LIBEXECDIR"
  124. if test $redir -eq 1; then
  125. rmdir "$LIBEXECDIR" 2>/dev/null
  126. else
  127. rmdir "$LIBEXECDIR"
  128. fi
  129. }
  130. fi
  131. if test -f "$SBINDIR/$NAME" ; then
  132. num=1
  133. prt_msg 2 0 1 "Delete $SBINDIR/$NAME" && {
  134. rm $force "$SBINDIR/$NAME"
  135. }
  136. fi
  137. if test -d "$PIDDIR" ; then
  138. num=1
  139. prt_msg 2 0 1 "Remove directory $PIDDIR" && {
  140. if test $redir -eq 1; then
  141. rmdir "$PIDDIR" 2>/dev/null
  142. else
  143. rmdir "$PIDDIR"
  144. fi
  145. }
  146. fi
  147. if test $num -eq 0; then
  148. prt_msg 2 0 0 "There was nothing to uninstall"
  149. fi
  150. }
  151. rm_startup () {
  152. num=0
  153. prt_msg 1 0 0 "*** Uninstalling Startup"
  154. if test "$SRC_INETD" != unknown; then
  155. if test "$INETD_TYPE" = inetd; then
  156. rc=`grep -E -q "^\W*@PKG_NAME@\s+" "$INETD_DIR/$INETD_FILE"`
  157. if test $rc -eq 0; then
  158. num=1
  159. prt_msg 2 0 1 "($INETD_TYPE) Remove entries from $INETD_DIR/$INETD_FILE" && {
  160. prt_msg 2 1 0 "($INETD_TYPE) Creating temp file: $INETD_DIR/$INETD_FILE.$NAME.unin"
  161. grep -v -q "\W*@PKG_NAME@\s+" "$INETD_DIR/$INETD_FILE" > "$INETD_DIR/$INETD_FILE.$NAME.unin"
  162. prt_msg 2 1 0 "($INETD_TYPE) Renaming original to: $INETD_DIR/$INETD_FILE.$NAME_save"
  163. mv "$INETD_DIR/$INETD_FILE" "$INETD_DIR/$INETD_FILE.$NAME_save"
  164. prt_msg 2 1 0 "($INETD_TYPE) Renaming $INETD_DIR/$INETD_FILE.unin to $INETD_DIR/$INETD_FILE"
  165. mv "$INETD_DIR/$INETD_FILE.unin" "$INETD_DIR/$INETD_FILE"
  166. prt_msg 2 0 0 "($INETD_TYPE) Old $INETD_DIR/$INETD_FILE saved as $INETD_DIR/$INETD_FILE.$NAME_save"
  167. }
  168. fi
  169. elif test -f "$INETD_DIR/$INETD_FILE"; then
  170. num=1
  171. if test "$INETD_TYPE" != xinetd; then
  172. prt_msg 2 0 1 "($INETD_TYPE) Stop and disable $NAME)" && {
  173. case "$INETD_TYPE" in
  174. systemd)
  175. systemctl stop $NAME; systemctl disable $NAME
  176. ;;
  177. upstart)
  178. if test $verb -eq 1; then
  179. stop $NAME
  180. else
  181. stop $NAME >/dev/null 2>&1
  182. fi
  183. ;;
  184. launchd)
  185. launchctl unload $INETD_FILE; launchctl remove $INETD_FILE;
  186. ;;
  187. smf*)
  188. svcadm disable -s $NAME
  189. ;;
  190. esac
  191. }
  192. fi
  193. prt_msg 2 0 1 "($INETD_TYPE) Delete $INETD_DIR/$INETD_FILE" && {
  194. rm $force "$INETD_DIR/$INETD_FILE"
  195. if test "$INETD_TYPE" = systemd; then
  196. INETD_FILE=`echo "$INETD_FILE" | sed -e 's/socket$/service/'`
  197. prt_msg 2 0 1 "($INETD_TYPE) Delete $INETD_DIR/$INETD_FILE" && {
  198. rm $force "$INETD_DIR/$INETD_FILE"
  199. }
  200. fi
  201. }
  202. fi
  203. fi
  204. if test "$SRC_INIT" != unknown; then
  205. if test -f "$INIT_DIR/$INIT_FILE"; then
  206. num=1
  207. prt_msg 2 0 1 "($INIT_TYPE) Stop and disable $NAME" && {
  208. case "$INIT_TYPE" in
  209. systemd)
  210. systemctl stop $NAME; systemctl disable $NAME
  211. ;;
  212. upstart)
  213. if test $verb -eq 1; then
  214. stop $NAME
  215. else
  216. stop $NAME >/dev/null 2>&1
  217. fi
  218. ;;
  219. launchd)
  220. launchctl unload $INIT_FILE; launchctl remove $INIT_FILE;
  221. ;;
  222. *bsd)
  223. if test -x $INIT_DIR/$INIT_FILE ; then
  224. $INIT_DIR/$INIT_FILE stop
  225. fi
  226. chmod 0644 $INIT_DIR/$INIT_FILE
  227. ;;
  228. openrc|gentoo)
  229. /sbin/start-stop-daemon --stop $NAME
  230. /sbin/rc-update del $NAME
  231. ;;
  232. smf*)
  233. svcadm disable -s $NAME
  234. ;;
  235. sysv)
  236. service stop $NAME; chkconfig --del $NAME
  237. ;;
  238. esac
  239. }
  240. prt_msg 2 0 1 "($INIT_TYPE) Delete $INIT_DIR/$INIT_FILE" && {
  241. rm $force "$INIT_DIR/$INIT_FILE"
  242. if test $INIT_TYPE = upstart; then
  243. prt_msg 2 0 1 "($INIT_TYPE) initctl reload-configuration" && {
  244. initctl reload-configuration
  245. }
  246. fi
  247. }
  248. fi
  249. fi
  250. if test $num -eq 0; then
  251. prt_msg 2 0 0 "There was nothing to uninstall"
  252. fi
  253. }
  254. rm_config () {
  255. num=0
  256. prt_msg 1 0 0 "*** Uninstalling Config"
  257. if test -f "$CFGDIR/$NAME.cfg"; then
  258. num=1
  259. prt_msg 2 0 1 "Delete $CFGDIR/$NAME.cfg" || return
  260. rm $force "$CFGDIR/$NAME.cfg"
  261. prt_msg 2 1 0 "Removing directory $CFGDIR"
  262. if test $redir -eq 1; then
  263. rmdir "$CFGDIR" 2>/dev/null
  264. else
  265. rmdir "$CFGDIR"
  266. fi
  267. fi
  268. if test $num -eq 0; then
  269. prt_msg 2 0 0 "There was nothing to uninstall"
  270. fi
  271. }
  272. rm_user () {
  273. #USERID=@nrpe_user@
  274. }
  275. rm_group () {
  276. #GRPID=@nrpe_group@
  277. }
  278. rm_script () {
  279. }
  280. get_opts $@
  281. prt_msg 0 0 0 "* * * Uninstall Starting * * *"
  282. if test $progs -eq 1 ; then rm_progs; fi
  283. if test $start -eq 1 ; then rm_startup; fi
  284. if test $config -eq 1 ; then rm_config; fi
  285. if test $delusr -eq 1; then rm_user; fi
  286. if test $delgrp -eq 1; then rm_group; fi
  287. if test $delscpt -eq 1; then rm_script; fi
  288. prt_msg 0 0 0 "* * * Uninstall Complete * * *"