plaiter 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937
  1. #!/bin/bash
  2. # Plaiter -- front end to mpg123 et al
  3. #
  4. # Copyright (C) 2005, 2006 Stephen Jungels
  5. #
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful, but
  13. # WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. # General Public License for more details.
  16. #
  17. # See COPYING for the full text of the license.
  18. #
  19. # See README.plaiter for supported platforms and installation
  20. # instructions.
  21. #
  22. # To contact the author: sjungels@gmail.com
  23. usage ()
  24. {
  25. echo "Usage is:"
  26. echo " \"plaiter [options] [file, playlist, directory or stream ...]\""
  27. echo "Options:"
  28. echo " --daemon,-d -- daemon mode"
  29. echo " --queue,-q -- add tracks to queue"
  30. echo " --enqueue -- add tracks to queue"
  31. echo " --random -- random shuffle"
  32. echo " --play -- play"
  33. echo " --pause -- toggle pause mode"
  34. echo " --stop,-s -- stop"
  35. echo " --latch [on|off] -- toggle or set stop after current track"
  36. echo " --next,-n [n] -- skip forward [n tracks]"
  37. echo " --prev [n] -- skip backward [n tracks]"
  38. echo " --search <str> -- search in playlist"
  39. echo " --rsearch <str> -- reverse search in playlist"
  40. echo " --reset,-r -- play track 1"
  41. echo " --loop [on|off] -- toggle or set loop mode"
  42. echo " --quit -- quit daemon"
  43. echo " --status -- show status"
  44. echo " --list,-l -- show playlist"
  45. echo " --help -- show help"
  46. echo " --version -- show version"
  47. echo " -v -- be verbose"
  48. }
  49. version ()
  50. {
  51. echo "Plaiter v 1.4.2"
  52. echo "Written by Stephen Jungels (sjungels@gmail.com)"
  53. echo ""
  54. echo "Copyright (c) 2005, 2006 by Stephen Jungels. Released under the GPL."
  55. echo "Latest version and more info at http://jungels.net/projects/plait/"
  56. }
  57. maybe_install ()
  58. {
  59. mkdir -p "$HOME/.plait"
  60. if ! test -f "$HOME/.plait/helpers" || test $INSTALL -gt 0
  61. then
  62. echo Detecting helper applications...
  63. rm -f "$HOME/.plait/helpers"
  64. touch "$HOME/.plait/helpers"
  65. ogg=`which ogg123 2>/dev/null`
  66. if ! test "-$ogg-" = "--"
  67. then
  68. echo "ogg:ogg123" >> "$HOME/.plait/helpers"
  69. echo "httpogg:ogg123" >> "$HOME/.plait/helpers"
  70. echo "flac:ogg123" >> "$HOME/.plait/helpers"
  71. fi
  72. mpg=`which mpg123-esd 2>/dev/null`
  73. if ! test "-$mpg-" = "--"
  74. then
  75. echo "mp3:mpg123-esd" >> "$HOME/.plait/helpers"
  76. echo "httpmp3:mpg123-esd" >> "$HOME/.plait/helpers"
  77. echo "http:mpg123-esd" >> "$HOME/.plait/helpers"
  78. else
  79. mpg=`which mpg123 2>/dev/null`
  80. if ! test "-$mpg-" = "--"
  81. then
  82. echo "mp3:mpg123" >> "$HOME/.plait/helpers"
  83. echo "httpmp3:mpg123" >> "$HOME/.plait/helpers"
  84. echo "http:mpg123" >> "$HOME/.plait/helpers"
  85. else
  86. mpg=`which mpg321 2>/dev/null`
  87. if ! test "-$mpg-" = "--"
  88. then
  89. echo "mp3:mpg321" >> "$HOME/.plait/helpers"
  90. echo "httpmp3:mpg321" >> "$HOME/.plait/helpers"
  91. echo "http:mpg321" >> "$HOME/.plait/helpers"
  92. fi
  93. fi
  94. fi
  95. echo Wrote $HOME/.plait/helpers
  96. fi
  97. if ! test -f "$HOME/.plait/key.awk" || test $INSTALL -gt 0
  98. then
  99. cat > "$HOME/.plait/key.awk" <<EOF
  100. {
  101. n = split (\$0, protocol, "://");
  102. if (n > 1) {
  103. mime = protocol[1];
  104. n = split (\$0, suffix, ".");
  105. if (suffix[n]=="mp3" || suffix[n]=="ogg") {
  106. mime = mime suffix[n];
  107. }
  108. } else {
  109. n = split (\$0, suffix, ".");
  110. mime = suffix[n];
  111. }
  112. print mime
  113. }
  114. EOF
  115. fi
  116. }
  117. next_track ()
  118. {
  119. if test "-$1-" = "--"
  120. then
  121. jump=1
  122. else
  123. jump=$1
  124. fi
  125. maxindex=`cat "$HOME/.plait/plaiter.m3u" | wc -l`
  126. j2=`expr $jump % $maxindex`
  127. if test $j2 -ne 0
  128. then
  129. track=`expr $listindex + $j2`
  130. if test $track -gt $maxindex
  131. then
  132. if test $loopmode = 0
  133. then
  134. track=$maxindex
  135. else
  136. track=`expr $track % $maxindex`
  137. fi
  138. fi
  139. else
  140. track=$listindex
  141. fi
  142. }
  143. prev_track ()
  144. {
  145. if test "-$1-" = "--"
  146. then
  147. jump=1
  148. else
  149. jump=$1
  150. fi
  151. maxindex=`cat "$HOME/.plait/plaiter.m3u" | wc -l`
  152. j2=`expr $jump % $maxindex`
  153. if test $j2 -ne 0
  154. then
  155. track=`expr $listindex - $j2`
  156. if test $track -lt 1
  157. then
  158. if test $loopmode = 0
  159. then
  160. track=1
  161. else
  162. track=`expr $maxindex + $track`
  163. fi
  164. fi
  165. else
  166. track=$listindex
  167. fi
  168. }
  169. play_current_song ()
  170. {
  171. while true
  172. do
  173. song=`cat "$HOME/.plait/plaiter.m3u" | awk "{if (FNR==$listindex) print}"`
  174. if ! test "-$song-" = "--"
  175. then
  176. key=`echo "$song" | awk -f "$HOME/.plait/key.awk"`
  177. HELPER=`cat "$HOME/.plait/helpers" | awk -v key=$key \
  178. 'BEGIN{FS=":"}{if (tolower(key) ~ tolower($1)) {print $2; exit}}'`
  179. if ! test "-$HELPER-" = "--"
  180. then
  181. $HELPER "$song" &
  182. playerpid=$!
  183. HELPERNAME=`echo "$HELPER" | awk '{print $1}'`
  184. if test $VERBOSE -gt 0
  185. then
  186. echo Ran command $HELPER $song
  187. echo "playerpid = $playerpid"
  188. echo helpername = $HELPERNAME
  189. fi
  190. break
  191. else
  192. if test $VERBOSE -gt 0
  193. then
  194. echo "I don't have a helper for the key $key"
  195. fi
  196. next_track
  197. if test $listindex = $track
  198. then
  199. paused=1
  200. break
  201. else
  202. listindex=$track
  203. fi
  204. fi
  205. else
  206. if test $VERBOSE -gt 0
  207. then
  208. echo No current song
  209. fi
  210. paused=1
  211. break
  212. fi
  213. done
  214. }
  215. handle_interrupt ()
  216. {
  217. # if HELPER exited, restart it on the next track
  218. if test $paused = 0 && ! test $playerpid = 0
  219. then
  220. tries=0
  221. while true
  222. do
  223. tmpfile="$(mktemp /tmp/plait.XXXXXX)"
  224. ps -p $playerpid > $tmpfile
  225. foo=`grep "$HELPERNAME" $tmpfile`
  226. if test "-$foo-" = "--"
  227. then
  228. if test $VERBOSE -gt 0
  229. then
  230. echo Did not find $HELPERNAME
  231. echo Selecting next track
  232. fi
  233. playerpid=0
  234. next_track
  235. if test $listindex = $track
  236. then
  237. if test $VERBOSE -gt 0
  238. then
  239. echo Reached end of playlist
  240. fi
  241. paused=1
  242. else
  243. listindex=$track
  244. if test $stoplatch = 0
  245. then
  246. play_current_song
  247. else
  248. stoplatch=0
  249. paused=1
  250. fi
  251. fi
  252. break
  253. else
  254. if test $tries -ge 1
  255. then
  256. if test $VERBOSE -gt 0
  257. then
  258. echo Found $HELPERNAME, giving up after second try
  259. fi
  260. break
  261. else
  262. if test $VERBOSE -gt 0
  263. then
  264. echo Found $HELPERNAME, trying again
  265. fi
  266. tries=`expr $tries + 1`
  267. sleep 1
  268. fi
  269. fi
  270. done
  271. fi
  272. }
  273. maybe_kill_player ()
  274. {
  275. if ! test $playerpid = 0
  276. then
  277. kill -9 >/dev/null 2>&1 $playerpid
  278. playerpid=0
  279. return 1
  280. else
  281. return 0
  282. fi
  283. }
  284. do_quit ()
  285. {
  286. maybe_kill_player
  287. rm -f $HOME/.plait/pdaemon
  288. exit 0
  289. }
  290. write_status ()
  291. {
  292. if test -e "$HOME/.plait/plaiter.m3u"
  293. then
  294. numtracks=`cat "$HOME/.plait/plaiter.m3u" | wc -l`
  295. else
  296. numtracks=0
  297. fi
  298. if test $playerpid = 0
  299. then
  300. status="STOPPED on track $listindex of $numtracks"
  301. elif test $paused = 1
  302. then
  303. status="PAUSED on track $listindex of $numtracks"
  304. else
  305. status="PLAYING track $listindex of $numtracks"
  306. fi
  307. if test $loopmode = 1
  308. then
  309. status="$status -- Loop on"
  310. fi
  311. if test $stoplatch = 1
  312. then
  313. status="$status -- Latch on"
  314. fi
  315. echo $listindex > "$HOME/.plait/status"
  316. echo $status >> "$HOME/.plait/status"
  317. }
  318. daemon_mode ()
  319. {
  320. if test -e "$HOME/.plait/pdaemon"
  321. then
  322. echo Daemon seems to be running
  323. sleep 3 &
  324. echo nop > "$HOME/.plait/pdaemon"
  325. if test $? = 0
  326. then
  327. kill $!
  328. echo Yes, it is running, exiting
  329. exit 1
  330. else
  331. echo No response from daemon, cleaning up
  332. rm "$HOME/.plait/pdaemon"
  333. fi
  334. fi
  335. mkfifo "$HOME/.plait/pdaemon"
  336. trap "echo Got SIGINT, cleaning up; do_quit" INT
  337. stoplatch=0
  338. loopmode=0
  339. playerpid=0
  340. listindex=1
  341. paused=1
  342. while true
  343. do
  344. write_status
  345. while true
  346. do
  347. read cmd args < $HOME/.plait/pdaemon
  348. if test $? -ne 0
  349. then
  350. if test $VERBOSE -gt 0
  351. then
  352. echo Got interrupt
  353. fi
  354. handle_interrupt
  355. write_status
  356. else
  357. break
  358. fi
  359. done
  360. if test $VERBOSE -gt 0
  361. then
  362. echo Read command $cmd
  363. fi
  364. case "$cmd" in
  365. play)
  366. if test $playerpid = 0
  367. then
  368. play_current_song
  369. paused=0
  370. elif test $paused = 1
  371. then
  372. paused=0
  373. kill -s CONT $playerpid
  374. fi
  375. ;;
  376. pause)
  377. if ! test $playerpid = 0
  378. then
  379. if test $paused = 0
  380. then
  381. paused=1
  382. kill -s STOP $playerpid
  383. if test $VERBOSE -gt 0
  384. then
  385. echo Pausing
  386. fi
  387. else
  388. paused=0
  389. kill -s CONT $playerpid
  390. if test $VERBOSE -gt 0
  391. then
  392. echo Unpausing
  393. fi
  394. fi
  395. fi
  396. ;;
  397. stoplatch)
  398. if test "-$args-" = "-on-"
  399. then
  400. stoplatch=1
  401. elif test "-$args-" = "-off-"
  402. then
  403. stoplatch=0
  404. elif test $stoplatch = 0
  405. then
  406. stoplatch=1
  407. else
  408. stoplatch=0
  409. fi
  410. if test $VERBOSE -gt 0
  411. then
  412. echo Setting stop latch: $stoplatch
  413. fi
  414. ;;
  415. stop)
  416. maybe_kill_player
  417. if test $? = 1
  418. then
  419. paused=1
  420. if test $VERBOSE -gt 0
  421. then
  422. echo Stopping
  423. fi
  424. fi
  425. ;;
  426. next)
  427. maybe_kill_player
  428. if test $? = 1
  429. then
  430. next_track $args
  431. if test $track = $listindex
  432. then
  433. paused=1
  434. else
  435. listindex=$track
  436. play_current_song
  437. fi
  438. else
  439. next_track $args
  440. listindex=$track
  441. fi
  442. if test $VERBOSE -gt 0
  443. then
  444. echo New track: $listindex
  445. fi
  446. ;;
  447. prev)
  448. maybe_kill_player
  449. if test $? = 1
  450. then
  451. prev_track $args
  452. if test $listindex = $track
  453. then
  454. paused=1
  455. else
  456. listindex=$track
  457. play_current_song
  458. fi
  459. else
  460. prev_track $args
  461. listindex=$track
  462. fi
  463. if test $VERBOSE -gt 0
  464. then
  465. echo New track: $listindex
  466. fi
  467. ;;
  468. search)
  469. track=`cat "$HOME/.plait/plaiter.m3u" | awk -v a="$args" -v li=$listindex \
  470. '{if (tolower($0) ~ tolower(a) && (track==0 || (track<=li && FNR > li)) && FNR!=li) track=FNR}END{print track}'`
  471. if ! test $track = 0
  472. then
  473. maybe_kill_player
  474. listindex=$track
  475. if test $VERBOSE -gt 0
  476. then
  477. echo New track: $listindex
  478. fi
  479. play_current_song
  480. fi
  481. ;;
  482. rsearch)
  483. track=`cat "$HOME/.plait/plaiter.m3u" | awk -v a="$args" -v li=$listindex \
  484. '{if (tolower($0) ~ tolower(a) && (FNR<li || track==0 || track>li) && FNR!=li) track=FNR}END{print track}'`
  485. if ! test $track = 0
  486. then
  487. maybe_kill_player
  488. listindex=$track
  489. if test $VERBOSE -gt 0
  490. then
  491. echo New track: $listindex
  492. fi
  493. play_current_song
  494. fi
  495. ;;
  496. reset)
  497. maybe_kill_player
  498. listindex=1
  499. paused=0
  500. stoplatch=0
  501. play_current_song
  502. if test $VERBOSE -gt 0
  503. then
  504. echo New track: $listindex
  505. fi
  506. ;;
  507. loop)
  508. if test "-$args-" = "-on-"
  509. then
  510. loopmode=1
  511. elif test "-$args-" = "-off-"
  512. then
  513. loopmode=0
  514. elif test $loopmode = 0
  515. then
  516. loopmode=1
  517. else
  518. loopmode=0
  519. fi
  520. if test $VERBOSE -gt 0
  521. then
  522. echo Setting loop mode: $loopmode
  523. fi
  524. ;;
  525. quit)
  526. if test $VERBOSE -gt 0
  527. then
  528. echo Quitting
  529. fi
  530. do_quit
  531. ;;
  532. nop)
  533. ;;
  534. *)
  535. if test $VERBOSE -gt 0
  536. then
  537. echo Ignoring unknown command $cmd
  538. fi
  539. ;;
  540. esac
  541. done
  542. }
  543. start_daemon ()
  544. {
  545. if test $VERBOSE -gt 0
  546. then
  547. echo Starting daemon
  548. fi
  549. plaiter --daemon > /dev/null 2>&1 &
  550. # pause a moment to let the daemon start up
  551. for i in 1 2 3 4; do for j in 1 2 3 4; do echo > /dev/null; done; done
  552. while true
  553. do
  554. if test -e "$HOME/.plait/pdaemon"
  555. then
  556. break
  557. fi
  558. sleep 1
  559. done
  560. }
  561. controller_mode ()
  562. {
  563. if test $QUEUE = 0 && ! test "-$1-" = "--"
  564. then
  565. rm -f "$HOME/.plait/plaiter.m3u"
  566. fi
  567. rm -f "$HOME/.plait/plaiter0.m3u"
  568. while test $# -gt 0
  569. do
  570. if test $VERBOSE -gt 0
  571. then
  572. echo Adding $1 to playlist
  573. fi
  574. if test -d "$1"
  575. then
  576. odir="`pwd`"
  577. cd "$1"
  578. dir="`pwd`"
  579. cd "$odir"
  580. find "$dir" -type f | sort >> "$HOME/.plait/plaiter0.m3u"
  581. elif test -f "$1"
  582. then
  583. case "$1" in
  584. *.m3u|*.M3U|*.m3U|*.M3u)
  585. cat "$1" | awk '{if ($0 !~ /^#/) print}' >> "$HOME/.plait/plaiter0.m3u"
  586. ;;
  587. *)
  588. odir="`pwd`"
  589. cd "`dirname \"$1\"`"
  590. dir="`pwd`"
  591. cd "$odir"
  592. file="`basename \"$1\"`"
  593. echo "$dir/$file" >> "$HOME/.plait/plaiter0.m3u"
  594. ;;
  595. esac
  596. else
  597. case "$1" in
  598. http*)
  599. echo "$1" >> "$HOME/.plait/plaiter0.m3u"
  600. ;;
  601. esac
  602. fi
  603. shift
  604. done
  605. touch "$HOME/.plait/plaiter0.m3u"
  606. # possibly shuffle the playlist
  607. if test $ORDER = "random"
  608. then
  609. tmpfile="$(mktemp /tmp/plait.XXXXXX)"
  610. cat "$HOME/.plait/plaiter0.m3u" | awk 'BEGIN{srand()} {print rand() "\t" $0}' | \
  611. sort -n | cut -f "2-" > $tmpfile
  612. mv $tmpfile "$HOME/.plait/plaiter0.m3u"
  613. fi
  614. cat "$HOME/.plait/plaiter0.m3u" >> "$HOME/.plait/plaiter.m3u"
  615. # before sending a command, make sure daemon is active
  616. if ! test -e "$HOME/.plait/pdaemon"
  617. then
  618. start_daemon
  619. fi
  620. # --status is a pseudo command that doesn't get sent to the daemon
  621. # Loop to pretty print
  622. if test $DOSTATUS -gt 0; then
  623. if test -e "$HOME/.plait/status"; then
  624. # First load up the configuration file
  625. if test -f "$HOME/.plait/config"
  626. then
  627. . "$HOME/.plait/config"
  628. fi
  629. # Now start the loop
  630. loopcounter=1
  631. listindex=`head -n 1 "$HOME/.plait/status"`
  632. echo `tail -n 1 "$HOME/.plait/status"`
  633. while read line
  634. do
  635. line=${line#"$MUSICDIR"/}
  636. if [ $loopcounter -eq $listindex ]; then
  637. echo "$line" | sed "s/^/> /"
  638. else
  639. echo "$line" | sed "s/^/ /"
  640. fi
  641. ((loopcounter++))
  642. done < "$HOME/.plait/plaiter.m3u"
  643. fi
  644. fi
  645. # --list is a pseudo command that doesn't get sent to the daemon
  646. if test $DOLIST -gt 0
  647. then
  648. if test -e "$HOME/.plait/plaiter.m3u"
  649. then
  650. cat "$HOME/.plait/plaiter.m3u"
  651. fi
  652. fi
  653. # there are default commands in certain cases
  654. if test $QUEUE = 0 && test "-$COMMAND-" = "--" && test $DOSTATUS = 0 && test $DOLIST = 0
  655. then
  656. COMMAND=reset
  657. elif test $QUEUE -gt 0 && test "-$COMMAND-" = "--" && test $DOSTATUS = 0 && test $DOLIST = 0
  658. then
  659. COMMAND=play
  660. fi
  661. if ! test "-$COMMAND-" = "--"
  662. then
  663. while true
  664. do
  665. if test $VERBOSE -gt 0
  666. then
  667. echo Sending command $COMMAND
  668. fi
  669. sleep 3 &
  670. echo $COMMAND > "$HOME/.plait/pdaemon"
  671. if test $? = 0
  672. then
  673. kill $!
  674. break
  675. else
  676. if test $VERBOSE -gt 0
  677. then
  678. echo Had to clean up pipe, trying again
  679. fi
  680. rm "$HOME/.plait/pdaemon"
  681. start_daemon
  682. fi
  683. done
  684. fi
  685. }
  686. QUEUE=0
  687. DAEMONMODE=0
  688. COMMAND=""
  689. VERBOSE=0
  690. INSTALL=0
  691. DOSTATUS=0
  692. DOLIST=0
  693. ORDER="sort"
  694. while test $# -gt 0
  695. do
  696. case "$1" in
  697. --queue|--enqueue|-q)
  698. QUEUE=1
  699. shift
  700. ;;
  701. --play)
  702. COMMAND=play
  703. shift
  704. ;;
  705. --pause)
  706. COMMAND=pause
  707. shift
  708. ;;
  709. --latch)
  710. if test "-$2-" = "-on-" || test "-$2-" = "-off-"
  711. then
  712. COMMAND="stoplatch $2"
  713. shift
  714. else
  715. COMMAND=stoplatch
  716. fi
  717. shift
  718. ;;
  719. --stop|-s)
  720. COMMAND=stop
  721. shift
  722. ;;
  723. --next|-n)
  724. if test "-$2-" = "--"
  725. then
  726. COMMAND="next"
  727. else
  728. if test 2>/dev/null $2 -gt -1
  729. then
  730. COMMAND="next $2"
  731. shift
  732. else
  733. COMMAND=next
  734. fi
  735. fi
  736. shift
  737. ;;
  738. --prev)
  739. if test "-$2-" = "--"
  740. then
  741. COMMAND="prev"
  742. else
  743. if test 2>/dev/null $2 -gt -1
  744. then
  745. COMMAND="prev $2"
  746. shift
  747. else
  748. COMMAND=prev
  749. fi
  750. fi
  751. shift
  752. ;;
  753. --search)
  754. COMMAND="search $2"
  755. shift
  756. shift
  757. ;;
  758. --rsearch)
  759. COMMAND="rsearch $2"
  760. shift
  761. shift
  762. ;;
  763. --reset|-r)
  764. COMMAND=reset
  765. shift
  766. ;;
  767. --loop)
  768. if test "-$2-" = "-on-" || test "-$2-" = "-off-"
  769. then
  770. COMMAND="loop $2"
  771. shift
  772. else
  773. COMMAND=loop
  774. fi
  775. shift
  776. ;;
  777. --quit)
  778. COMMAND=quit
  779. shift
  780. ;;
  781. --random)
  782. ORDER=random
  783. shift
  784. ;;
  785. --status)
  786. DOSTATUS=1
  787. shift
  788. ;;
  789. --list|-l)
  790. DOLIST=1
  791. shift
  792. ;;
  793. --daemon|-d)
  794. DAEMONMODE=1
  795. shift
  796. ;;
  797. --install)
  798. INSTALL=1
  799. shift
  800. ;;
  801. --help)
  802. usage
  803. exit 0
  804. ;;
  805. --version)
  806. version
  807. exit 0
  808. ;;
  809. -v)
  810. VERBOSE=1
  811. shift
  812. ;;
  813. -*)
  814. echo Ignoring bad option $1
  815. shift
  816. ;;
  817. *)
  818. break
  819. ;;
  820. esac
  821. done
  822. CYGWIN=`uname -s | grep -ic CYGWIN`
  823. if test $CYGWIN -ge 1
  824. then
  825. echo Sorry, plaiter does not run on Cygwin
  826. exit 0
  827. fi
  828. maybe_install
  829. if test $INSTALL = 1
  830. then
  831. exit 0
  832. elif test $DAEMONMODE = 1
  833. then
  834. daemon_mode
  835. exit 0
  836. else
  837. controller_mode "$@"
  838. exit 0
  839. fi