1#!/bin/bash 2# 3# starts @progtitle@ from the installation directory 4 5# set -x 6 7INSTALL=@rpmroot@@prefix@/games/@progname@ 8 9#find old configuration 10if test @enable_etc@ = yes ; then 11 CONFIG=@rpmroot@/etc/@prognamebase@ 12else 13 CONFIG=$INSTALL/config 14fi 15 16if test -r $INSTALL/.config.orig ; then 17 CONFIG_ORIG=$INSTALL/.config.orig 18 CONFIG_OLD=$INSTALL/config 19else 20 if test -r @rpmroot@/etc/@prognamebase@/.orig ; then 21 CONFIG_ORIG=@rpmroot@/etc/@prognamebase@/.orig 22 CONFIG_OLD=@rpmroot@/etc/@prognamebase@ 23 else 24 if test -r $INSTALL/config/.orig ; then 25 CONFIG_ORIG=$INSTALL/config/.orig 26 CONFIG_OLD=$INSTALL/config 27 fi 28 fi 29fi 30 31NEW_CONFIG_ORIG=$CONFIG/.orig 32CONFIG_USER=$CONFIG/.user 33CONFIG_NEW=$CONFIG/.new 34 35BIN=@rpmroot@@prefix@/bin 36 37FORCE=n 38 39STARTSERVER=NO 40STARTMASTER=NO 41 42UPDATE=no 43 44if test -r $INSTALL/bin/@progname@ ; then 45 if test ! "$1" = "-f" -a ! "$1" = "-u" ; then 46 echo "Installation aborted; detected previous installation." 47 echo "Use \"install -f\"/\"make install_force\" to force installation ( previous version will get overwritten )" 48 echo "or \"install -u\"/\"make update\" ( your configuration files will be kept; requires diff3 )." 49 exit 1 50 else 51 if test -r ./rc.d/@prognamebase@ ; then 52 FORCE=y 53 $INSTALL/rc.d/@prognamebase@ status && STARTSERVER=yes 54 $INSTALL/rc.d/@prognamebase@-master status && STARTMASTER=yes 55 fi 56 57 install -m 755 -d $CONFIG 58 59 # make backup of old configuration 60 rm -rf $CONFIG_USER.old 61 test -d $CONFIG_USER && mv $CONFIG_USER $CONFIG_USER.old 62 mkdir $CONFIG_USER 63 test -r $CONFIG_OLD/settings.cfg && cp $CONFIG_OLD/* $CONFIG_USER 64 rm -f $CONFIG_USER/*~ 65 66 if test "$1" = "-u"; then 67 UPDATE=yes 68 fi 69 fi 70fi 71 72 73echo 74echo "Making directories..." 75install -m 755 -d $BIN || { echo "Installation failed. Bin folder does not exist and cannot be created."; exit 1; } 76 77install -m 755 -d $INSTALL/log || { echo "Installation failed. Install folder does not exist and cannot be created."; exit 1; } 78 79install -m 755 -d $CONFIG || { echo "Installation failed. Configuration folder does not exist and cannot be created."; exit 1; } 80 81 82if test $STARTSERVER = yes ; then 83 ./rc.d/@prognamebase@ stop 84fi 85 86if test $STARTMASTER = yes ; then 87 ./rc.d/@prognamebase@-master stop 88fi 89 90if test "@rpmroot@" = "dddd" ; then 91 if ! install -m 755 -d @rpmroot@ ; then 92 echo "Installation failed. RPM root folder does not exist and cannot be created." 93 exit 1 94 fi 95fi 96 97echo "Copying data..." 98rm -rf $INSTALL/doc 99rm -rf $INSTALL/bin/* 100cp -R * $INSTALL || { echo "Installation failed. Either the installation target is write protected or your disk is full."; exit 1; } 101 102rm -rf $INSTALL/install 103rm -rf $INSTALL/bin/starter 104rm -rf $INSTALL/bin/stat 105 106echo "Installing scripts..." 107install -m 755 bin/starter $BIN/@progname@ || { echo "Installation failed. Could not install launcher. You may have insufficient rights to $BIN."; exit 1 ;} 108 109install -m 755 bin/stat $BIN/@prognamebase@-stat || { echo "Installation failed. Could not install server browser. . You may have insufficient rights to $BIN."; exit 1; } 110 111#copy new configuration 112if test @enable_etc@ = yes ; then 113 test -d $CONFIG || mkdir $CONFIG 114 cp $INSTALL/config/* $CONFIG 115fi 116 117rm -rf $CONFIG_NEW 118mkdir $CONFIG_NEW 119cp $CONFIG/* $CONFIG_NEW 120 121if test "$UPDATE" = "yes" && test -d $CONFIG_ORIG; then 122 echo "Integrating user changes..." #"from $CONFIG_USER to $CONFIG_ORIG and $CONFIG..." 123 test -r $CONFIG_USER || mkdir $CONFIG_USER 124 test -r $CONFIG_ORIG || mkdir $CONFIG_ORIG 125 126 chmod 755 $CONFIG_ORIG 127 128 PWD_OLD=$( pwd ) 129 cd $CONFIG_USER 130 for f in *; do 131 if test ! "$f" = "*" ; then 132 if test ! -r $CONFIG/$f || test ! -r $CONFIG_ORIG/$f ; then 133 echo " " Copying $f... 134 cp $f $CONFIG 135 else 136 echo " " Merging $f... 137 diff3 -m -L "Your version follows:" $f -L "Original version follows:" $CONFIG_ORIG/$f -L "New version above." $CONFIG_NEW/$f > $CONFIG/$f || { echo -e "\nWarning: conflicts during configuration merge of config/$f.\nYou should check it manually.\n" ; WARN=ON; } 138 fi 139 fi 140 done 141 cd $PWD_OLD 142fi 143 144rm -rf $CONFIG_ORIG 145rm -rf $NEW_CONFIG_ORIG 146mv $CONFIG_NEW $NEW_CONFIG_ORIG 147chmod 755 $NEW_CONFIG_ORIG 148chmod 400 $NEW_CONFIG_ORIG/* 149echo -e "Don't change anything in this directory; it will be needed exactly as it is now\nwhen you upgrate to a new version." >> $NEW_CONFIG_ORIG/README 150 151#delete obsolete configuration 152if test @enable_etc@ = yes ; then 153 rm -rf $INSTALL/config* 154else 155 rm -rf @rpmroot@/etc/@prognamebase@ 156fi 157 158if test $STARTMASTER = yes ; then 159 ./rc.d/@prognamebase@-master start 160fi 161 162if test $STARTSERVER = yes ; then 163 ./rc.d/@prognamebase@ start 164fi 165 166echo -e "Installation complete! Just type @progname@ to start.\n" 167if test "$WARN" = "ON"; then 168 echo -e "Check the above output for warnigs first!\n" 169fi 170