timidity-update 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #!/bin/sh
  2. VERSION_MJ="1"
  3. VERSION_MN="0"
  4. VERSION_RV="0000"
  5. VERSION_AP=""
  6. VERSION="${VERSION_MJ}.${VERSION_MN}${VERSION_AP}"
  7. PATCHDIR="/usr/share/timidity"
  8. # Below is the user's local patchset
  9. HOME_TARGET="$HOME/.timidity/current"
  10. TARGET="${HOME_TARGET}"
  11. show_help() {
  12. echo "$0 ${VERSION}"
  13. echo "Usage: $0 [-g] -s PATCHSET"
  14. echo " or: $0 -r"
  15. echo " or: $0 [OPTION]"
  16. echo "Set the current timidity patch set to PATCHSET."
  17. echo
  18. echo "Mandatory arguments to long options are mandatory for short options too."
  19. echo " -g Change the global patch set instead of the"
  20. echo " user's patch set"
  21. echo " -r Change current user's patch set to current"
  22. echo " system patch set"
  23. echo " -s [PATCHSET] Change to patch set PATCHSET"
  24. echo " --help display this help and exit"
  25. }
  26. show_error() {
  27. echo "$0: bad or missing argument"
  28. echo "Try '$0 --help' for more information."
  29. }
  30. set_patch() {
  31. TARGET=$1
  32. PATCHSET=$2
  33. # If something borken, no go
  34. if [ ! -L ${TARGET} -a -e ${TARGET} ] || [ ! -d ${PATCHDIR}/${PATCHSET} ]; then
  35. if [ ! -L ${TARGET} -a -e ${TARGET} ]; then
  36. echo " Error: ${TARGET} exists and is not a symlink"
  37. return -1
  38. fi
  39. if [ ! -d ${PATCHDIR}/${PATCHSET} ]; then
  40. echo " Error: patch set ${PATCHSET} does not exist"
  41. echo " Look in ${PATCHDIR}/ for patch sets"
  42. return -1
  43. fi
  44. echo " Error: Undefined error."
  45. return -1
  46. fi
  47. echo -n " * Switching to ${PATCHSET} Timidity patch set..."
  48. rm -f ${TARGET} 2>/dev/null
  49. ln -s ${PATCHDIR}/${PATCHSET} ${TARGET} 2>/dev/null
  50. echo " [ OK ]"
  51. return 0
  52. }
  53. restore_patches() {
  54. TARGET=$1
  55. echo -n " * Setting up local patch set to system global..."
  56. rm -f ${TARGET} 2>/dev/null
  57. ln -s ${PATCHDIR}/current ${TARGET}
  58. echo " [ OK ]"
  59. }
  60. ##############
  61. # Processing #
  62. #############
  63. # Make sure home directory is there
  64. if [ ! -e ${HOME}/.timidity ]; then
  65. mkdir -p ${HOME}/.timidity
  66. restore_patches $TARGET
  67. fi
  68. ################
  69. # No arguments #
  70. ###############
  71. if [ -z "$1" ]; then
  72. show_error
  73. exit 1
  74. fi
  75. #########################
  76. # Actual processing loop#
  77. ########################
  78. while [ -n "$1" ]; do
  79. case "$1" in
  80. -g)
  81. TARGET="/usr/share/timidity/current"
  82. ;;
  83. -r)
  84. restore_patches ${HOME_TARGET}
  85. exit 0
  86. ;;
  87. -s)
  88. PATCHSET="$2"
  89. shift
  90. ;;
  91. --help)
  92. show_help
  93. exit 0
  94. ;;
  95. *)
  96. show_error
  97. exit 1
  98. ;;
  99. esac
  100. shift
  101. done
  102. set_patch $TARGET $PATCHSET