up2date.sh 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #!/bin/sh
  2. ##########################################################################
  3. # up2date.sh
  4. # voxelands - 3d voxel world sandbox game
  5. # Copyright (C) Lisa Milne 2014 <lisa@ltmnet.com>
  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 3 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.
  15. # See the GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>
  19. ##########################################################################
  20. # Automatically check to see which repositories have older versions of voxelands
  21. #
  22. # To use, execute this script with ./up2date.sh
  23. # Parameters: 1)
  24. #
  25. # Inspired by up2date=() used with pacman-g2 FrugalBuild scripts
  26. # http://frugalware.org/docs/stable/makepkg.html#_a_simple_example
  27. ##########################################################################
  28. ###
  29. # == GETOPT STUFF
  30. # * Some derived from https://gist.github.com/hoylen/6607180
  31. # which is public domain material
  32. ###
  33. PROG=$(basename $0)
  34. getopt -T > /dev/null
  35. if [ $? -eq 4 ]; then
  36. # GNU enhanced getopt is available
  37. ARGS=$(getopt --name "$PROG" --long help,sanity-off --options hs -- "$@")
  38. else
  39. # Original getopt is available (no long option names, no whitespace, no sorting)
  40. ARGS=$(getopt hs "$@")
  41. fi
  42. if [ $? -ne 0 ]; then
  43. echo "$PROG: usage error (use -h for help)" >&2
  44. exit 2
  45. fi
  46. eval set -- "$ARGS"
  47. while [ $# -gt 0 ]; do
  48. case "$1" in
  49. -h | --help) HELP=yes;;
  50. -s | --sanity-off) SANITY_OFF=yes;;
  51. --) shift; break;; # end of options
  52. esac
  53. shift
  54. done
  55. if [ $# -gt 0 ]; then
  56. # Remaining parameters can be processed
  57. for ARG in "$@"; do
  58. echo "$PROG: argument: $ARGS"
  59. done
  60. fi
  61. ###
  62. # * Help text
  63. ###
  64. if [[ $HELP = yes ]]; then
  65. echo "Allowed options:"
  66. echo " -h, --help"
  67. echo " Show this help message and exit"
  68. echo " -s, --sanity-off"
  69. echo " Don't do sanity checks, nice if they're throwing warnings for no good reason"
  70. exit 0
  71. fi
  72. ###
  73. # == DEPENDANCY CHECK
  74. # * Make sure needed programs are installed
  75. ###
  76. depends=('lynx')
  77. for i in ${depends[@]}
  78. do
  79. # This assumes all programs listed in depends can be executed with --version
  80. eval $i --version > /dev/null 2>&1
  81. if [[ $? != 0 ]]; then
  82. echo "$i not found! You need to install $i in order to use this script"
  83. exit 1
  84. fi
  85. done
  86. ###
  87. # == REPO COMMANDS
  88. # Use a command that will fetch the current version of voxelands in a repository.
  89. # The next tidbit is from Frugalware docs: http://frugalware.org/docs/stable/makepkg.html#_a_simple_example
  90. # Which is licensed under the standard GNU free documentation license: http://frugalware.org/docs/license
  91. #
  92. # lynx -dump http://www.kyz.uklinux.net/cabextract.php |grep 'cabextract source code' |sed 's/.*-\(.*\).t.*/\1/'
  93. # Usually the command consists of three parts: a lynx -dump someurl, a grep foo, and a sed command. We use the http protocol
  94. # if possible, but sometimes we have to use ftp. In that case instead of lynx -dump you should use wget -O - -q.
  95. # Of course, you could use wget all the time, but lynx is simpler. The sed command could be replaced with the combination
  96. # of tr and cut if you prefer them instead of sed. The example used above would be the following with cut and tr:
  97. # lynx -dump http://www.kyz.uklinux.net/cabextract.php |grep 'cabextractsource code'|tr -s ' '|cut -d ' ' -f 6
  98. ###
  99. latestVersion="$(lynx --dump https://gitorious.org/minetest-classic/minetest-classic/raw/doc/changelog.txt \
  100. | grep release | tr '\n' ' ' | cut -d ':' -f1)"
  101. repo=(
  102. "source"
  103. "$(lynx -dump http://voxelands.com/download.html | grep src | cut -d '-' -f2)"
  104. "windows"
  105. "$(lynx -dump http://voxelands.com/download.html | grep win | cut -d '-' -f2)"
  106. "osx"
  107. "$(lynx -dump http://voxelands.com/download.html | grep osx | cut -d '-' -f2)"
  108. "aur"
  109. "$(lynx --dump https://aur.archlinux.org/packages/vo/voxelands/PKGBUILD | grep pkgver= | cut -d '=' -f2)"
  110. "ccr"
  111. "$(lynx --dump http://chakraos.org/ccr/pkgbuild_view.php?p=voxelands | grep pkgver= | cut -d '=' -f2)"
  112. "copr"
  113. "$(lynx --dump http://copr.fedoraproject.org/coprs/mavjs/voxelands/builds/ \
  114. | grep 'succeeded' | tr '\n' ' ' | tr -s ' ' | cut -d ' ' -f4)"
  115. "slackbuilds"
  116. "$(lynx --dump http://slackbuilds.org/repository/14.1/games/voxelands/ \
  117. | grep 'Games > voxelands' | tr ')' '(' | cut -d '(' -f2)"
  118. )
  119. ###
  120. # == PROVIDED FUNCTIONS
  121. # * RepoSanityCheck(): Tries to warn you when a repo command is broken.
  122. # Parameters: 1) repo name 2) version of voxelands in said repo
  123. ###
  124. RepoSanityCheck() {
  125. if [[ -z "$2" ]]; then
  126. echo "$PROG: ERROR: fetching $1 version failed, repo command returned nothing"
  127. elif [[ ${#2} != 7 ]]; then
  128. # voxelands version numbers are typically seven characters long
  129. echo "$PROG: WARNING: $1 version is not the typical seven character length. Returned: \"$2\""
  130. fi
  131. if [[ ! -z "$(echo "$2" | sed 's/[0-9.]//g')" ]] ; then
  132. echo "$PROG: WARNING: $1 version contains non-numerical non-period characters. Returned: \"$2\""
  133. fi
  134. }
  135. ###
  136. # == PARSE RESULTS
  137. # * Miscellaneous setup
  138. ###
  139. if [[ ! $SANITY_OFF = yes ]]; then
  140. RepoSanityCheck "latest" "$latestVersion"
  141. fi
  142. echo "voxelands latest is $latestVersion"
  143. allUp2Date=true
  144. nOutOfDateRepos=0
  145. ###
  146. # * Parse $repo
  147. ###
  148. for (( i = 1; i < "${#repo[@]}"; i = i + 2 ))
  149. do
  150. if [[ ! $SANITY_OFF = yes ]]; then
  151. RepoSanityCheck ${repo[(( i - 1 ))]} "${repo[$i]}"
  152. fi
  153. if [[ "${repo[$i]}" != "$latestVersion" ]]; then
  154. echo "voxelands ${repo[(( i - 1 ))]} is ${repo[$i]}"
  155. allUp2Date=false
  156. (( nOutOfDateRepos++ ))
  157. fi
  158. done
  159. ###
  160. # * Print a status summery
  161. ###
  162. if [[ $allUp2Date = true ]]; then
  163. echo "All known repos have voxelands latest"
  164. elif (( $nOutOfDateRepos < "${#repo[@]}" / 2 )); then
  165. echo "Other known repos have voxelands latest"
  166. else
  167. echo "All known repos have older versions of voxelands"
  168. fi