mk.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/bin/bash
  2. sep="================================================================================"
  3. echo "I will build the files necessary for fortune-mod, and optionally install them.
  4. $sep"
  5. get_input() {
  6. # $1: list of choices
  7. # $2: default, if the user presses return (ignored if empty)
  8. if [[ "x$2" == "x" ]]
  9. then
  10. defaultstring="no default"
  11. else
  12. defaultstring="Enter=$2"
  13. fi
  14. while true
  15. do
  16. read -p "=> your choice (Enter=$2): " input
  17. for i in $1 ; do
  18. if [[ "$input" == "$i" ]]
  19. then
  20. echo "$i"
  21. break 2
  22. fi
  23. done
  24. if [[ "$input" == "" ]] && [[ "x$2" != "x" ]]
  25. then
  26. echo "$2"
  27. break
  28. fi
  29. done
  30. }
  31. STRF="$(which strfile)"
  32. [[ "$STRF" == "" ]] && echo "strfile is not found in \$PATH. This most probably means that fortune-mod is not installed. Cannot continue." && exit 1
  33. sourcefile="./cbbl"
  34. [[ "$(file -b --mime-type "$sourcefile")" != "text/plain" ]] && echo "The file $sourcefile cannot be found or is not a plain text file. Are you sure you are calling this script from the fortune-mod-cbbl repo base directory?" && exit 1
  35. mkdir -p build
  36. buildfile="./build/cbbl"
  37. datfile="./build/cbbl.dat"
  38. cp -f "$sourcefile" "$buildfile"
  39. choices="f n"
  40. echo "Do you want to build the folded or the normal version ($choices)?"
  41. case "$(get_input "$choices" n)" in
  42. f) FLD="$(which fold)"
  43. if [[ "x$FLD" == "x" ]] ; then
  44. echo "fold is not found in \$PATH. This most probably means that coreutils is not installed. Cannot continue."
  45. exit 1
  46. fi
  47. echo "How many columns (1-160)?"
  48. $FLD -s -w "$(get_input "$(seq -s' ' 160)" 80)" cbbl > "$buildfile"
  49. ;;
  50. n) true
  51. ;;
  52. esac
  53. echo "
  54. $sep
  55. building the fortune-mod database
  56. $STRF $buildfile $datfile"
  57. $STRF "$buildfile" "$datfile" || exit 1
  58. # optional: install
  59. installpath="/usr/share/games/fortunes"
  60. choices="y n"
  61. echo "$sep
  62. Done. Do you want to install the two files $buildfile $datfile
  63. to a directory of your choice?
  64. If you do NOT install, you have to call fortune with the path to the folder
  65. containing the compiled cookies, e.g.
  66. \"fortune $PWD/build\" or
  67. \"fortune $PWD/build/cbbl\".
  68. If you DO install, you should install it to a path where the fortune program can
  69. find it.
  70. On debian systems, this is $installpath, on other systems it might be
  71. /usr/share/fortune or something else.
  72. So, do you want to install (y/n)?"
  73. if [[ "$(get_input "$choices" n)" == "y" ]]
  74. then
  75. input=""
  76. echo "Please enter install path - must be an existing directory."
  77. while [ ! -d "$input" ]
  78. do
  79. read -p "=> your choice (Enter=$installpath): " input
  80. [[ "x$input" == "x" ]] && input="$installpath"
  81. done
  82. user="$($(which ls) -ld "$input" | awk '{print $3}')"
  83. echo "$sep
  84. Copying $buildfile to $input/cbbl"
  85. sudo -u "$user" cp -i "$buildfile" "$input/cbbl"
  86. echo "Copying $datfile to $input/cbbl.dat"
  87. sudo -u "$user" cp -i "$datfile" "$input/cbbl.dat"
  88. else
  89. echo "Not installing."
  90. fi
  91. echo "Done. Here's a taste:
  92. $sep"
  93. fortune build/cbbl
  94. echo "$sep"