1#! /bin/sh 2# Generic installation script for Ponscripter games. 3# 4# Copyright (C) 2009 Haeleth. 5# 6# Permission is hereby granted, free of charge, to any person obtaining 7# a copy of this software and associated documentation files (the 8# "Software"), to deal in the Software without restriction, including 9# without limitation the rights to use, copy, modify, merge, publish, 10# distribute, sublicense, and/or sell copies of the Software, and to 11# permit persons to whom the Software is furnished to do so, subject to 12# the following conditions: 13# 14# The above copyright notice and this permission notice shall be 15# included in all copies or substantial portions of the Software. 16# 17# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS I THE SOFTWARE. 24 25 26# Game-specific variables: 27 28GAME=narcissu2 # Name of game (used to name directory and launcher) 29TITLE="Narcissu Side 2nd" # Pretty name of game 30GAMEID=Narcissu_Side_2nd # ;gameid after Unix transformation 31GAMEVER=1.00 # Version number of game 32COPYRIGHT="Copyright (c) 2005-2007 Stage-Nana, 2005-2009 Insani/Haeleth/Agilis" 33NEEDVER=20090104 # Minimum version of Ponscripter required 34 35 36# The remainder of this file should not need customisation. 37 38# Default options 39PREFIX=/usr/local 40PONSCR= 41 42# Parse options 43prev= 44for opt 45do 46 if test -n "$prev"; then 47 eval "$prev=\$opt" 48 prev= 49 continue 50 fi 51 arg=`expr "x$opt" : 'x[^=]*=\(.*\)'` 52 case $opt in 53 --prefix=* | -prefix=*) 54 PREFIX=$arg ;; 55 --prefix | -prefix) 56 prev=PREFIX 57 ;; 58 59 --ponscr=* | -ponscr=*) 60 PONSCR=$arg ;; 61 --ponscr | -ponscr) 62 prev=PONSCR 63 ;; 64 65 -\? | -h* | --h*) 66 cat <<EOF 67Usage: $0 <options> 68 69Options: 70 --help display this message 71 --prefix=DIR install in prefix DIR (default is /usr/local) 72 --ponscr=PATH specify location of ponscr program 73 74EOF 75 exit 0 76 ;; 77 *) 78 echo "Ignoring unknown option $opt" 79 ;; 80 esac 81done 82if test -n "$prev"; then 83 opt=--`echo $prev | tr '[A-Z]_' '[a-z]-'` 84 echo "Error: missing argument to $opt" >&2 85 exit 2 86fi 87 88 89# ---------- Check environment ---------- 90 91# permission to write to PREFIX 92 93if test ! -w "$PREFIX"; then 94 cat <<EOF 95Error: cannot write to $PREFIX. 96Please either try again as root, or use --prefix. 97 98See INSTALL for further assistance. 99 100EOF 101 exit 1 102fi 103 104# existence of ponscr program 105if test -z "$PONSCR"; then 106 PONSCR=`which ponscr 2>/dev/null` 107fi 108if test -z "$PONSCR"; then 109 PONSCR=ponscr 110fi 111PSCVER=`($PONSCR --version) 2>/dev/null | awk '/version/ { print $3 }'` 112if test -z "$PSCVER"; then 113 cat <<EOF 114Error: Ponscripter not found. Please install it and try again. 115 116If you have already installed it, I can't seem to find it; please 117specify the path to the ponscr binary with the --ponscr option. 118 119See INSTALL for further assistance. 120 121EOF 122 exit 1 123fi 124if test $PSCVER -lt $NEEDVER; then 125 cat <<EOF 126Error: found Ponscripter $PSCVER, but I need version $NEEDVER or later. 127Please upgrade and try again. 128 129If you have already installed the latest version, you may have an older 130version in your PATH that's getting in the way; try specifying the path 131to the correct version with the --ponscr option. 132 133See INSTALL for further assistance. 134 135EOF 136fi 137 138# existence of previous installation 139if [ -d $PREFIX/share/games/$GAME ]; then 140 echo "It looks like you've already got $TITLE installed." 141 echo "Continuing will overwrite the existing installation." 142 if read -p "Are you sure? " CONFIRM; then :; else 143 echo 144 exit 1 145 fi 146 case `echo $CONFIRM | tr YES yes` in 147 yes | y) : ;; 148 no | n) exit 0 ;; 149 *) cat <<EOF 150I'm afraid I don't understand that answer. 151If you meant "yes", please run the installer again and say yes. 152 153Alternatively, you could uninstall the previous version (probably a 154case of typing "$GAME --uninstall"), and the problem would go away. 155 156EOF 157 exit 1 ;; 158 esac 159fi 160 161# ---------- Installation ---------- 162 163cat <<EOF 164Installing $TITLE... 165 166EOF 167 168INSTALL=util/install-sh 169RMMAN= 170 171# Game files are straightforward to install. 172$INSTALL -d $PREFIX/share/games/$GAME 173for file in data/*; do 174 FILE=`expr "x$file" : 'x.*/\(.*\)'` 175 echo $PREFIX/share/games/$GAME/$FILE 176 $INSTALL -c -m 0644 $file $PREFIX/share/games/$GAME 177done 178 179# Manpages are slightly more complicated. 180if [ ! -d $PREFIX/man ] && [ -d $PREFIX/share/man ] 181then MANDIR=$PREFIX/share/man 182else MANDIR=$PREFIX/man 183fi 184$INSTALL -d $MANDIR/man6 185for file in man/*; do 186 FILE=`expr "x$file" : 'x.*/\(.*\)'` 187 echo $MANDIR/man6/$FILE 188 RMMAN="$RMMAN $MANDIR/man6/$FILE" 189 $INSTALL -c -m 0644 $file $MANDIR/man6 190done 191if [ ! -z "$RMMAN" ]; then 192 RMMAN="rm -f$RMMAN" 193fi 194 195# And the game launcher script must be created from scratch. 196TMPSCR=/tmp/tmp-$GAME.$$ 197trap "rm $TMPSCR 2>/dev/null" 0 198 199cat > $TMPSCR <<EOF 200#! /bin/sh 201# Launcher script for the Ponscripter game "$TITLE" 202# 203# Copyright (C) 2009 Haeleth. 204# 205# Permission is hereby granted, free of charge, to any person obtaining 206# a copy of this software and associated documentation files (the 207# "Software"), to deal in the Software without restriction, including 208# without limitation the rights to use, copy, modify, merge, publish, 209# distribute, sublicense, and/or sell copies of the Software, and to 210# permit persons to whom the Software is furnished to do so, subject to 211# the following conditions: 212# 213# The above copyright notice and this permission notice shall be 214# included in all copies or substantial portions of the Software. 215# 216# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 217# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 218# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 219# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 220# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 221# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 222# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 223 224case \`echo 'x\c'\` in 225'x\c') echo_n="echo -n"; nobr= ;; 226*) echo_n="echo"; nobr="\c" ;; 227esac 228 229PLAY=true 230WINDOW= 231SAVE= 232DEBUG= 233 234# Parse options 235prev= 236for opt 237do 238 if test -n "\$prev"; then 239 eval "\$prev=\\\$opt" 240 prev= 241 continue 242 fi 243 arg=\`expr "x\$opt" : 'x[^=]*=\\(.*\\)'\` 244 case \$opt in 245 --uninstall | -uninstall) 246 PLAY=false ;; 247 248 --window | -window) 249 WINDOW=--window ;; 250 251 --fullscreen | -fullscreen) 252 WINDOW=--fullscreen ;; 253 254 --save=* | -save=*) 255 SAVE=\$arg ;; 256 --save | -save) 257 prev=SAVE ;; 258 259 --debug | -debug | -d) 260 DEBUG="\$DEBUG -d" ;; 261 262 --version | -version | -v) 263 echo "$TITLE version $GAMEVER" 264 echo "$COPYRIGHT" 265 echo 266 \$echo_n "Game engine: \$nobr" 267 $PONSCR --version 268 exit 0;; 269 270 -\\? | -h* | --h*) 271 cat <<ENDHELP 272$TITLE launcher 273Usage: $GAME <options> 274 275Options: 276 --debug -d enable debugging output (very verbose!) 277 --window start in windowed mode 278 --fullscreen start in fullscreen mode 279 --save DIR put saves and settings in DIR 280 (default: \$HOME/.$GAMEID) 281Information: 282 --help -h display this message 283 --version -v display version and copyright information 284 285Administration: 286 --uninstall uninstall $TITLE 287 288ENDHELP 289 exit 0 290 ;; 291 *) 292 echo "Ignoring unknown option \$opt" 293 ;; 294 esac 295done 296if test -n "\$prev"; then 297 opt=--\`echo \$prev | tr '[A-Z]_' '[a-z]-'\` 298 echo "Error: missing argument to \$opt" >&2 299 exit 2 300fi 301 302if \$PLAY; then 303 if [ ! -z "\$SAVE" ]; then SAVE="--save \$SAVE"; fi 304 exec $PONSCR \\ 305 -r $PREFIX/share/games/$GAME \\ 306 \$WINDOW \$SAVE \$DEBUG 307fi 308 309if test ! -w $PREFIX/share/games; then 310 cat <<ENDERR 311Cannot uninstall: you don't have the necessary privileges. 312Please try again as root. 313ENDERR 314 exit 1 315fi 316 317if read -p "Really uninstall $TITLE? " CONFIRM; then :; else 318 echo 319 exit 1 320fi 321case \`echo \$CONFIRM | tr YES yes\` in 322 yes | y) : ;; 323 *) exit 0 ;; 324esac 325 326rm -rf $PREFIX/share/games/$GAME 327rm -f $PREFIX/bin/$GAME 328$RMMAN 329 330echo $TITLE has been uninstalled. 331if test -d \$HOME/.$GAMEID; then 332 cat <<NOTE 333 334Your saved games have not been removed. You can delete them manually 335with the command 336 337 rm -rf \$HOME/.$GAMEID 338 339NOTE 340fi 341EOF 342 343echo $PREFIX/bin/$GAME 344$INSTALL -c $TMPSCR $PREFIX/bin/$GAME 345echo 346echo Installation complete. 347 348# Different message depending on whether the launcher is in $PATH or 349# not. 350BIN=$PREFIX/bin 351case $PATH in 352 $BIN | $BIN:* | *:$BIN | *:$BIN:*) 353 cat <<EOF 354You can now play the game with the \`$GAME' command. 355 356EOF 357 ;; 358 *) 359 if [ "x`whoami`" = "xroot" ]; then 360 cat <<EOF 361You can now play the game by typing \`$BIN/$GAME'. 362(Or you may be able to run \`$GAME' directly, 363if $BIN is in your PATH). 364 365EOF 366 else 367 cat <<EOF 368You can now play the game by typing \`$BIN/$GAME'. 369(Or you could run \`$GAME' directly after adding 370$BIN to your PATH). 371 372EOF 373 fi 374esac 375