configfolder_script.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #!/bin/bash
  2. # A simple tool-script to change things in the ./config folder with ease.
  3. # Run "sh configfolder_script.sh --all" to auto-accept "yes" as the answer to
  4. # all questions in this script.
  5. # This is the main AssaultCube folder:
  6. PATHTOACDIR=~/AssaultCube/AC
  7. # This is the docs folder (which holds reference.xml):
  8. ABSOLUTEPATHTODOCS=$PATHTOACDIR/docs
  9. # Path to "official" folder:
  10. MAPSPATH="$PATHTOACDIR/packages/maps/official"
  11. echo "Generate an updated ./config/securemaps.cfg (Y/N)?"
  12. if [ "$1" != "--all" ]; then
  13. read ANSR
  14. fi
  15. if [ "$ANSR" = "y" ] || [ "$ANSR" = "Y" ] || [ "$ANSR" = "yes" ] || [ "$ANSR" = "YES" ] || [ "$1" = "--all" ]; then
  16. cd $PATHTOACDIR
  17. echo "resetsecuremaps" > ./config/securemaps.cfg
  18. find ./packages/maps/official/*.cgz | \
  19. xargs -i basename {} .cgz | \
  20. xargs -i echo "securemap" {} | \
  21. sort -u >> ./config/securemaps.cfg
  22. echo -e "DONE.\n"
  23. else
  24. echo -e "\a\E[1mNOTE:\E[0m ./config/securemaps.cfg hasn't been updated.\n"
  25. fi
  26. echo "Generate an updated ./config/docs.cfg (Y/N)?"
  27. if [ "$1" != "--all" ]; then
  28. read ANSR
  29. fi
  30. if [ "$ANSR" = "y" ] || [ "$ANSR" = "Y" ] || [ "$ANSR" = "yes" ] || [ "$ANSR" = "YES" ] || [ "$1" = "--all" ]; then
  31. cd $ABSOLUTEPATHTODOCS
  32. xsltproc -o $PATHTOACDIR/config/docs.cfg ./xml/cuberef2cubescript.xslt ./reference.xml
  33. echo -e "DONE.\n"
  34. else
  35. echo -e "\a\E[1mNOTE:\E[0m ./config/docs.cfg hasn't been updated.\n"
  36. fi
  37. echo "Strip all \"official\" maps configs of cruft, leaving top-of-file comments alone (Y/N)?"
  38. if [ "$1" != "--all" ]; then
  39. read ANSR
  40. fi
  41. if [ "$ANSR" = "y" ] || [ "$ANSR" = "Y" ] || [ "$ANSR" = "yes" ] || [ "$ANSR" = "YES" ] || [ "$1" = "--all" ]; then
  42. cd $PATHTOACDIR
  43. bash config/convert_pre_v1.2_mapconfig.sh -osp ./packages/maps/official/*.cfg
  44. echo -e "DONE.\n"
  45. else
  46. echo -e "\a\E[1mNOTE:\E[0m Map config files have been left alone.\n"
  47. fi
  48. echo "Strip all config files of trailing spaces/tabs (Y/N)?"
  49. if [ "$1" != "--all" ]; then
  50. read ANSR
  51. fi
  52. if [ "$ANSR" = "y" ] || [ "$ANSR" = "Y" ] || [ "$ANSR" = "yes" ] || [ "$ANSR" = "YES" ] || [ "$1" = "--all" ]; then
  53. cd $PATHTOACDIR/config
  54. sed -i 's/^M$//' *.cfg *.txt
  55. sed -i 's/[ \t]*$//' *.cfg *.txt
  56. cd $PATHTOACDIR/config/autostart
  57. sed -i 's/^M$//' *.cfg *.txt
  58. sed -i 's/[ \t]*$//' *.cfg *.txt
  59. cd $PATHTOACDIR/config/opt
  60. sed -i 's/^M$//' *.cfg *.txt
  61. sed -i 's/[ \t]*$//' *.cfg *.txt
  62. echo -e "DONE.\n"
  63. else
  64. echo -e "\a\E[1mNOTE:\E[0m Config files haven't had leading whitespace stripped.\n"
  65. fi
  66. # Auto-generates a list of maps:
  67. MAPSLIST=`cd "$MAPSPATH" && find ./*.cgz | xargs -i basename {} .cgz | sort -u | sed 's/\n/ /g'`
  68. # Currently listed CTF maps:
  69. CURCTFMAPS="$(cd $PATHTOACDIR/config && sed -n 's/const ctfmaps \[//p' menus.cfg | sed 's/\]//g')"
  70. # List of non-CTF maps:
  71. NONCTFLIST=`echo " " "$CURCTFMAPS" " " "$MAPSLIST" " " | sed "s/ /\n/g" | sed '/^$/d' | sort | uniq -u`
  72. read
  73. echo "Update all menus with current \"official\" maps (Y/N)?"
  74. if [ "$1" != "--all" ]; then
  75. read ANSR
  76. fi
  77. if [ "$ANSR" = "y" ] || [ "$ANSR" = "Y" ] || [ "$ANSR" = "yes" ] || [ "$ANSR" = "YES" ] || [ "$1" = "--all" ]; then
  78. cd $PATHTOACDIR/config
  79. # Replacement text for "const defaultmaps":
  80. DEFLTMAPS=`echo "const defaultmaps [" $MAPSLIST "]"`
  81. sed -i 's/const defaultmaps..*/'"$DEFLTMAPS"'/g' menus.cfg
  82. echo "The following official maps are NOT listed for CTF mode currently:"
  83. echo $NONCTFLIST
  84. echo "Add a map to this list (Y/N)?"
  85. read ANSR
  86. if [ "$ANSR" = "y" ] || [ "$ANSR" = "Y" ] || [ "$ANSR" = "yes" ] || [ "$ANSR" = "YES" ]; then
  87. echo "Please type the names of maps to add to the CTF menu, seperated by spaces."
  88. read NEWCTFMAPS
  89. # List of CTF maps, with new additions:
  90. CTFLIST="$(echo " " "$CURCTFMAPS" " " "$NEWCTFMAPS" " " | sed "s/ /\n/g" | sed '/^$/d' | sort -u | sed "s/\n/ /g")"
  91. # Replacement text for "const ctfmaps":
  92. CTFMAPS="$(echo "const ctfmaps [" $CTFLIST "]")"
  93. sed -i 's/const ctfmaps..*/'"$CTFMAPS"'/g' menus.cfg
  94. echo -e "DONE.\n"
  95. else
  96. echo -e "\a\E[1mNOTE:\E[0m DONE... no changes were made to the CTF maps list."
  97. fi
  98. else
  99. echo -e "\a\E[1mNOTE:\E[0m No map menus have been updated."
  100. fi