Guest User

simutrans get_pak.sh patch

a guest
Nov 7th, 2012
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.55 KB | None | 0 0
  1. --- get_pak.sh.orig 2012-10-22 23:09:16.000000000 +0200
  2. +++ get_pak.sh  2012-11-08 02:37:22.000000000 +0100
  3. @@ -3,21 +3,26 @@
  4.  # script to fetch pak sets
  5.  #
  6.  
  7. +# make sure that non-existing variables are not ignored
  8. +set -u
  9. +
  10. +# fall back to "/tmp" if TEMP is not set
  11. +TEMP=${TEMP:-/tmp}
  12. +
  13. +
  14.  # parameter: url and filename
  15.  do_download(){
  16. -curl -h > /dev/null
  17. -if [ $? -eq 0 ]; then
  18. -    curl $1 > $2 || {
  19. +if which curl >/dev/null; then
  20. +    curl -L "$1" > "$2" || {
  21.        echo "Error: download of file $2 failed (curl returned $?)" >&2
  22. -      rm -f $2
  23. +      rm -f "$2"
  24.        exit 4
  25.      }
  26.  else
  27. -    wget --help > /dev/null
  28. -    if [ $? -eq 0 ]; then
  29. -        wget -q -N $1 -O $2 || {
  30. +    if which wget >/dev/null; then
  31. +        wget -q -N "$1" -O "$2" || {
  32.            echo "Error: download of file $2 failed (wget returned $?)" >&2
  33. -          rm -f $2
  34. +          rm -f "$2"
  35.            exit 4
  36.          }
  37.      else
  38. @@ -31,16 +36,16 @@
  39.  # two parameter, url, zipfilename
  40.  DownloadInstallZip(){
  41.    echo "downloading from $1"
  42. -  do_download $1 $TEMP/$2
  43. +  do_download "$1" "$TEMP/$2"
  44.    echo "installing from $2"
  45. -  unzip -o -C -q $TEMP/$2 -d .
  46. -  rm $TEMP/$2
  47. +  unzip -o -C -q "$TEMP/$2" -d .
  48. +  rm "$TEMP/$2"
  49.  }
  50.  
  51.  
  52.  # generated list of pak sets with well-formatted paking
  53.  paksets=( \
  54. -http://downloads.sourceforge.net/project/simutrans/pak64/112-0/simupak64-112-0.zip" \
  55. +"http://downloads.sourceforge.net/project/simutrans/pak64/112-0/simupak64-112-0.zip" \
  56.  "http://downloads.sourceforge.net/project/simutrans/pak.german/pak64.german-110-0c/simupak-german64-110-0c.zip" \
  57.  "http://downloads.sourceforge.net/project/simutrans/pak64.japan/112-0/simupak64.japan-112-0.zip" \
  58.  "http://downloads.sourceforge.net/project/simutrans/pakHAJO/pakHAJO_102-2-2/pakHAJO_0-102-2-2.zip" \
  59. @@ -73,7 +78,7 @@
  60.  let setcount=0
  61.  let choicecount=0
  62.  let "maxcount = ${#paksets[*]}"
  63. -while [ $setcount -lt $maxcount ]; do
  64. +while [ "$setcount" -lt "$maxcount" ]; do
  65.        installpak[choicecount]=0
  66.        urlname=${paksets[$setcount]}
  67.        zipname="${urlname##http*\/}"
  68. @@ -87,7 +92,7 @@
  69.  
  70.  let setcount=0
  71.  let "maxcount = ${#nosimutranspaksets[*]}"
  72. -while [ $setcount -lt $maxcount ]; do
  73. +while [ "$setcount" -lt "$maxcount" ]; do
  74.        installpak[choicecount]=0
  75.        urlname=${nosimutranspaksets[$setcount]}
  76.        zipname="${urlname##http*\/}"
  77. @@ -96,7 +101,7 @@
  78.        choices[choicecount]=$choicename
  79.        let "setcount += 1"
  80.        let "choicecount += 1"
  81. -      echo "${choicecount}) ${choicename}"
  82. +      echo "${choicecount} ${choicename}"
  83.  done
  84.  
  85.  while true; do
  86. @@ -149,24 +154,24 @@
  87.  pushd ..
  88.  let setcount=0
  89.  let "maxcount = ${#paksets[*]}"
  90. -while [ $setcount -lt $maxcount ]; do
  91. -  if [ ${installpak[$setcount]} -gt 0 ]; then
  92. +while [ "$setcount" -lt "$maxcount" ]; do
  93. +  if [ "${installpak[$setcount]}" -gt 0 ]; then
  94.      urlname=${paksets[$setcount]}
  95.      zipname="${urlname##http*\/}"
  96. -    DownloadInstallZip $urlname $zipname
  97. +    DownloadInstallZip "$urlname" "$zipname"
  98.    fi
  99.    let "setcount += 1"
  100.  done
  101.  
  102.  #for the wrong paksets, just change to simutrans folder
  103.  popd
  104. -while [ $setcount -lt $choicecount ]; do
  105. +while [ "$setcount" -lt "$choicecount" ]; do
  106.    if [ ${installpak[$setcount]} -gt 0 ]; then
  107.      let "correctcount=$setcount-$maxcount]"
  108. -    echo $correctcount
  109. +    echo "$correctcount"
  110.      urlname=${nosimutranspaksets[$correctcount]}
  111.      zipname="${urlname##http*\/}"
  112. -    DownloadInstallZip $urlname $zipname
  113. +    DownloadInstallZip "$urlname" "$zipname"
  114.    fi
  115.    let "setcount += 1"
  116.  done
Advertisement
Add Comment
Please, Sign In to add comment