This is a script that should allow the Devs to easily create packages for different distros at once. Currently it creates a makeself archive, full debian, debian downloader, and debian rsync installer.
Note that whoever is using this script must have the programs required to create these pacakges installed. makeself is fairly ubiquitous and is available in the package management systems of most distros. For creating deb packages, You'll need a program called dpkg installed. If you already have a debian based system (Ubuntu, Mephis, Debian, Knoppix, Freespire, etc), Then you already have dpkg. If you don't have dpkg, It might be available in your distro's package repositories (for Arch Linux it can be found in AUR).
The makeself archive generated is, for the end user, nearly identical to the current installation script. The makeself archive however, has the added advantages of self verification and easier non-interactive installation via:
legends_installer.run --noexec --target /usr/games/legends
The syntax is intended to be easy to use. All the fancy options to makeself and dpkg, etc. should be taken care of by the scripters. It would be nice to allow for optional override switches to the package creation tools though. The syntax of the script is:
legends_packager.sh –package_type -v package_version directory_to_package
package_type is one of: makeself, loki (makeself archive with a GUI), debian, debdload (automatically downloads and installs the makeself archive), debrsync (installs Legends via rsync), rpm, or all. You may specify more than one package type. The all switch will make all supported packages, although rpm is not supported yet. Note that the package_name should not contain a suffix, such that
legends_packager.sh --all -v 0.4.2.0 legends_dir/
will output:
legends_linux-0.4.2.0.runlegends_linux_gui-0.4.2.0.runlegends_linux-0.4.2.0.deblegends_linux_rsync-0.4.2.0.deblegends_linux_downloader-0.4.2.0.deblegends_linux-0.4.2.0.rpm (Note: rpm is not supported yet)
By default, the package prefix is legends_linux. You can alter this behaviour with the -f switch:
legends_packager.sh --makeself -f LinLegends -v 0.4.2.0 legends_dir/
will output:
LinLegends-0.4.2.0.run
The rsync .deb installs the update script and runs it. It expects to find the new install.sh script so that it can install the menu entries. If the new install.sh script is not on the rsync server, then the menu entries will not be created. It could be made to install the menu entries without install.sh, but using install.sh is easier to maintain as the menu entry installation is kept within install.sh and not repeated across several scripts.
This .deb installs nothing, but the postinst (post install) script downloads the makeself archive from legendsthegame.net/files/ and automatically installs it. This .deb will not work at the moment because it expects to find legends_linux-0.4.2.0.run (going from the above example). It can be tested by changing the INSTALLER_PREFIX to
files:///home/TerroX/legends_test/
and putting legends_linux-0.4.2.0.run in that directory.
#!/bin/bash # Script for newbies to autogenerate makeself archives, .deb # and .rpm packages # List of files that must be found within the directory you want to # package. This is to make sure you don't try to package the wrong # directory which could overwrite/delete important files. LEGENDS_TEST_FILES="LinLegends legends common" PKG_NAME="legends_linux" LEGENDS_DESC="Legends - Fast-paced first-person-shooter online multiplayer game with jetpacks, similar to Tribes. Up to 64 players per server. http://legendsthegame.net/ " INSTALL_DESC="Legends Installer" LEGENDS_LOKI_TAR="legends_loki_skeleton.tar.bz2" INSTALLER_PREFIX="http://legendsthegame.net/files/linux_packages/" # Directory where .deb will extract to DEB_INSTALL_DIR="/usr/games/legends/" # Directory where .deb will download to DEB_DLOAD_DIR="\$HOME/" #DEB_DLOAD_DIR="/var/cache/apt/archives/" # Dodgy hacks to make it work for lazy people that are unwilling to install # Makeself properly!!! PATH="./:$PATH" ############################################################ ############################################################ # Make the makeself archive ############################################################ MAKESELF_OPTS="--bzip2" MAKESELF_LABEL="${INSTALL_DESC}" create_makeself() { echo "Making \`makeself' archive of $PKG_DIR/" # Make sure setup script is executable chmod u+x ${PKG_DIR}/install.sh if [ ! -x ${PKG_DIR}/install.sh ]; then echo "Error: could not find ${PKG_DIR}/install.sh" echo "Aborting makeself archive." return 1 fi makeself.sh ${MAKESELF_OPTS} ${PKG_DIR} ${PKG_NAME}-${PKG_VER}.run\ "${MAKESELF_LABEL}" ./install.sh return $? } write_loki_setup_xml() { cat << EOF > $1 <?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?> <install product="legends" desc="${LEGENDS_DESC}" version="${PKG_VER}" binarypath="/usr/local/bin" reinstall="yes" promptbinaries="yes" express="no" superuser="no" splashpos="top" nopromptoverwrite="yes"> <readme> ReadMe.txt </readme> <eula> ReadMe_legals.txt </eula> <install_drop_list> /opt /usr/local/games /usr/local /usr/games /usr </install_drop_list> <option install="yes" required="true" size="${PKG_SIZE_HUMAN}"> Base Install <binary arch="any" libc="any" symlink="runlegends" binpath="bin/runlegends" icon="legends.ico" play="yes"> runlegends </binary> <files> legends.tar </files> </option> </install> EOF return $? } create_loki() { LOKI_DIR="${PKG_DIR}/loki_setup" if [ -d ${LOKI_DIR} ]; then echo "Error: $LOKI_DIR already exists. This is due to a" echo "previous packaging attempt that failed. Manually" echo "remove $LOKI_DIR and try again." return 1 else mkdir ${LOKI_DIR} || return 1 fi echo "Unpacking ${LEGENDS_LOKI_TAR}" tar jxf ${LEGENDS_LOKI_TAR} -C $LOKI_DIR || return 1 cp ${PKG_DIR}/{ReadMe_legals.txt,ReadMe.txt,legends.ico} ${LOKI_DIR} echo "Creating tarball of ${PKG_DIR}" tar --exclude "loki_setup" --exclude "debian" -C ${PKG_DIR} -cf \ ${LOKI_DIR}/legends.tar . || return 1 mkdir ${LOKI_DIR}/bin cp ${PKG_DIR}/runlegends ${LOKI_DIR}/bin/ write_loki_setup_xml "${LOKI_DIR}/setup.data/setup.xml" echo "Packaging loki_setup in makeself wrapper" makeself.sh ${MAKESELF_OPTS} ${LOKI_DIR} \ ${PKG_NAME}_gui-${PKG_VER}.run "${MAKESELF_LABEL}" \ ./setup.sh echo "Removing temporary loki_setup directory" rm -r $LOKI_DIR return $? } ############################################################ ############################################################ # Make a .deb package ############################################################ write_debian_control() { cat << EOF > $1 Package: Legends Version: $PKG_VER Section: games Priority: optional Architecture: i386 Essential: no Depends: libjpeg62, libogg0, libpng12-0, libxext6, rsync, libsdl1.2debian, libsdl-image1.2, libsdl-mixer1.2, zlib1g Installed-Size: $PKG_SIZE_BYTES Maintainer: The Ghost <theghost@hell.org> Provides: legends Description: $LEGENDS_DESC EOF return $? } write_debian_postinst() { cat << EOF > $1 #!/bin/bash echo echo "Run the update script to see if newer versions of Legends are" echo "available via rsync. As root type:" echo " cd $DEB_INSTALL_DIR" echo " ./update" echo echo "You should download BT Mappack from http://legendsthegame.net." echo "Once downloaded, Place it in your \$HOME/.legends/legends directory." echo EOF return $? } write_debian_postrm() { cat << EOF > $1 #!/bin/bash echo echo "You may also want to remove the Legends configuration folder" echo "in your home directory: \$HOME/.legends/" echo EOF return $? } create_debian() { echo "Making \`.deb' package from $PKG_DIR/" # generate necessary files for building a .deb with dpkg if [ -e $PKG_DIR/debian ]; then echo "File or directory named 'debian' found in $PKG_DIR." echo "Remove or rename this file and try again. If you did" echo "not put the 'debian' file there, then it was put there" echo "by the script. If so, then it is a bug, please report" echo "it....exiting" exit 1 fi mkdir -p $PKG_DIR/debian/DEBIAN mkdir -p $PKG_DIR/debian/$DEB_INSTALL_DIR # Temporarily move legends into the debian directory (DANGEROUS!) mv $(find $PKG_DIR -maxdepth 1 -mindepth 1 -name 'debian' -prune \ -o -print) $PKG_DIR/debian/$DEB_INSTALL_DIR write_debian_control $PKG_DIR/debian/DEBIAN/control write_debian_postinst $PKG_DIR/debian/DEBIAN/postinst write_debian_postrm $PKG_DIR/debian/DEBIAN/postrm # make scripts executable chmod +x $PKG_DIR/debian/DEBIAN/{postinst,postrm} # build the package dpkg -b $PKG_DIR/debian/ ${PKG_NAME}-$PKG_VER.deb rtn=$? # Move files back into PKG_DIR mv $(find $PKG_DIR/debian/$DEB_INSTALL_DIR -maxdepth 1 -mindepth 1) \ $PKG_DIR # Safely remove directories rm -r $PKG_DIR/debian/DEBIAN/ cd $PKG_DIR rmdir -p debian/$DEB_INSTALL_DIR cd ${OLDPWD} return $rtn } write_debdload_postinst() { cat << EOF > $1 #!/bin/bash if [ ! -f "$DEB_DLOAD_DIR/${PKG_NAME}-${PKG_VER}.run" ]; then echo "Downloading the Legends Installer to $DEB_DLOAD_DIR," echo "this might take a while." wget -P $DEB_DLOAD_DIR $INSTALLER_PREFIX/${PKG_NAME}-${PKG_VER}.run else echo "A copy of ${PKG_NAME}-${PKG_VER}.run was found in" echo "$DEB_DLOAD_DIR and will be used for the installation." echo "If you want to download a fresh copy, you must delete" echo "this file and start again." fi echo "Unpacking Legends, This may take a while." cd $DEB_DLOAD_DIR chmod +x ${PKG_NAME}-${PKG_VER}.run sh ${PKG_NAME}-${PKG_VER}.run --noexec --target $DEB_INSTALL_DIR chmod +x $DEB_INSTALL_DIR/install.sh $DEB_INSTALL_DIR/install.sh --menu-only chmod -x $DEB_INSTALL_DIR/install.sh cd \${OLD_PWD} echo echo "Run the update script to see if newer versions of Legends are" echo "available via rsync. As root type:" echo " cd $DEB_INSTALL_DIR" echo " ./update" echo echo "You should download BT Mappack from http://legendsthegame.net." echo "Once downloaded, Place it in your \$HOME/.legends/legends directory." echo EOF return $? } create_debdload() { echo "Making \`.deb' downloader package from $PKG_DIR/" # generate necessary files for building a .deb with dpkg if [ -e $PKG_DIR/debian ]; then echo "File or directory named 'debian' found in $PKG_DIR." echo "Remove or rename this file and try again. If you did" echo "not put the 'debian' file there, then it was put there" echo "by the script. If so, then it is a bug, please report" echo "it....exiting" exit 1 fi mkdir -p $PKG_DIR/debian/DEBIAN write_debian_control $PKG_DIR/debian/DEBIAN/control write_debdload_postinst $PKG_DIR/debian/DEBIAN/postinst write_debian_postrm $PKG_DIR/debian/DEBIAN/postrm # make scripts executable chmod +x $PKG_DIR/debian/DEBIAN/{postinst,postrm} # build the package dpkg -b $PKG_DIR/debian/ ${PKG_NAME}_downloader-$PKG_VER.deb rtn=$? # Safely remove directories rm -r $PKG_DIR/debian/DEBIAN/ rmdir $PKG_DIR/debian return $rtn } write_debrsync_postinst() { cat << EOF > $1 #!/bin/bash cd $DEB_INSTALL_DIR echo "Downloading Legends via rsync, this may take a while." chmod +x ./update if ( ! sh update ); then echo "Install failed, please try again or ask for help at:" echo " http://legendsthegame.net/forums/" exit 1 else chmod +x ./install.sh sh ./install.sh --menu-only chmod -x ./install.sh cd ${OLD_PWD} echo echo "You should download BT Mappack from http://legendsthegame.net." echo "Place it in your $HOME/.legends/legends directory." echo fi EOF return $? } create_debrsync() { echo "Making \`.deb' rsync package from $PKG_DIR/" # generate necessary files for building a .deb with dpkg if [ -e $PKG_DIR/debian ]; then echo "File or directory named 'debian' found in $PKG_DIR." echo "Remove or rename this file and try again. If you did" echo "not put the 'debian' file there, then it was put there" echo "by the script. If so, then it is a bug, please report" echo "it....exiting" exit 1 fi mkdir -p $PKG_DIR/debian/DEBIAN mkdir -p $PKG_DIR/debian/$DEB_INSTALL_DIR # copy over just the ./update script cp $PKG_DIR/update $PKG_DIR/debian/$DEB_INSTALL_DIR chmod u+x $PKG_DIR/debian/$DEB_INSTALL_DIR/update write_debian_control $PKG_DIR/debian/DEBIAN/control write_debrsync_postinst $PKG_DIR/debian/DEBIAN/postinst write_debian_postrm $PKG_DIR/debian/DEBIAN/postrm # make scripts executable chmod +x $PKG_DIR/debian/DEBIAN/{postinst,postrm} # build the package dpkg -b $PKG_DIR/debian/ ${PKG_NAME}_rsync-$PKG_VER.deb rtn=$? # Safely remove directories rm -r $PKG_DIR/debian/DEBIAN/ rm -r $PKG_DIR/debian/$DEB_INSTALL_DIR/update cd $PKG_DIR rmdir -p debian/$DEB_INSTALL_DIR cd ${OLDPWD} return $rtn } ############################################################ ############################################################ # Make a .rpm package ############################################################ create_rpm() { echo "Making \`.rpm' package from $PKG_DIR/" } ############################################################ ############################################################ # Print usage legends_packager_usage() { echo "Usage: `basename $0` [options] -f filename -v version pkg_dir" echo " * pkg_dir is the directory with the data to be packaged." echo " * filename is the name of the package to be created." echo " * version is the Legends version number being packaged." echo " * options can be one of:" echo " --makeself : Create a makeself archive" echo " --loki : Create a loki_setup GUI installer" echo " --loki-tar : Specify location of loki skeleton tarball" echo " --debian : Create a .deb package" echo " --debdload : Create a .deb downloader package" echo " --debrsync : Create a .deb rsync package (web install)" echo " --rpm : Create a .rpm package" echo " --all : Create all supported packages" echo " --deathwish : Allow root user to run this script" echo exit 1 } # DEPRECATED!!!! # Just use legends_packager_usage # # Print short help...well, very short :) legends_packager_help() { echo "For help, type: `basename $0` --help" exit 1 } test_executable() { if [ ! -x "$(which $1 2> /dev/null)" ]; then echo " *** Error: \`$1' could not be found ***" echo " *** Make sure you have the programs required ***" echo " *** to build this archive type installed ***" return 1 fi } test_resembles_legends() { for f in $LEGENDS_TEST_FILES; do if [ ! -e $PKG_DIR/$f ]; then echo "Error: Could not find $f in $PKG_DIR" return 1 fi done return 0 } prompt_yes_no() { while true; do echo -ne "${1} [y/n]: " read answer if echo $answer | grep -i "^y\(es\)\?$" &> /dev/null; then return 0 elif echo $answer | grep -i "^n[o]\?$" &> /dev/null; then return 1 else echo "Unrecognised option, please try again..." fi done } confirm_package_choices() { echo "You have chosen to make the following packages from $PKG_DIR" for p in $PACKAGES; do case "$p" in makeself) echo "${PKG_NAME}-${PKG_VER}.run";; loki) echo "${PKG_NAME}_gui-${PKG_VER}.run";; debian) echo "${PKG_NAME}-${PKG_VER}.deb";; debdload) echo "${PKG_NAME}_downloader-${PKG_VER}.deb";; debrsync) echo "${PKG_NAME}_rsync-${PKG_VER}.deb";; rpm) echo "${PKG_NAME}-${PKG_VER}.rpm";; esac done if ( ! prompt_yes_no "Do you wish to proceed?" ); then echo "Exiting..." exit 1 fi } ############################################################ # If no arguments given, then print usage if [ $# -eq 0 ]; then legends_packager_usage fi # Parse command line options PACKAGES="" while true do case "$1" in --help|-help|--h|-h) legends_packager_usage ;; --makeself|-makeself|--ms|-ms) PACKAGES="${PACKAGES} makeself" ;; --loki|-loki|--loki-setup|-loki-setup) PACKAGES="${PACKAGES} loki" ;; --debian|-debian|--deb|-deb) PACKAGES="${PACKAGES} debian" ;; --debdload|-debdload) PACKAGES="${PACKAGES} debdload" ;; --debrsync|-debrsync) PACKAGES="${PACKAGES} debrsync" ;; --rpm|-rpm) PACKAGES="${PACKAGES} rpm" ;; --all|-all|--a|-a) PACKAGES="makeself loki debian debdload debrsync rpm" ;; --deathwish|-deathwish|--death|-death) DEATHWISH=true ;; -f) shift PKG_NAME=$1 ;; -v) shift PKG_VER=$1 ;; --loki-tar|-loki-tar) shift LEGENDS_LOKI_TAR=$1 ;; -*) echo "Unrecognised option: $1" legends_packager_usage ;; *) break ;; esac shift done PKG_DIR="$1" # Get package size PKG_SIZE_KBYTES=$(du -s ${PKG_DIR} | awk '{print $1}') PKG_SIZE_HUMAN=$(du -hs ${PKG_DIR} | awk '{print $1}') # Test that PKG_DIR looks vaguely like Legends if ( ! test_resembles_legends ); then echo "Error: $PKG_DIR does not seem to contain Legends. Check that" echo "you specified the correct directory. Also check that the" echo "LEGENDS_TEST_FILES variable (at the top of this script) is" echo "up to date....exiting" exit 1 fi # Test for root user if [ $(id -u) -eq 0 ]; then echo "*** WARNING ***" echo "This script has not been tested sufficiently and is not" echo "considered safe enough to be used by the root user." if [ $DEATHWISH ]; then echo "Deathwish enabled: God have mercy on your soul." else echo "If you must run as root, use the --deathwish command" echo "line option." exit 1 fi fi # Test package directory and package name if [ -z "$PACKAGES" ]; then echo "Error: Please specify an package type to create" legends_packager_usage fi if [ -z "$PKG_DIR" ]; then echo "Error: Please specify a directory to package" legends_packager_usage fi if [ ! -d "$PKG_DIR" ]; then echo "Error: '$PKG_DIR' does not exist or is not a directory" legends_packager_usage fi if [ -z "$PKG_NAME" ]; then echo "Error: Please enter a name for the package" legends_packager_usage fi if [ -z "$PKG_VER" ]; then echo "Error: Please enter a version number" legends_packager_usage fi # Prompt user to confirm their choice confirm_package_choices # Make specified packages # TODO: Make it so that it doesn't make an package more than once for p in $PACKAGES; do case "$p" in makeself) if ( test_executable "makeself.sh" ); then create_makeself || \ echo "Error: makeself creation failed" else echo " *** Aborting create makeself archive ***" fi ;; loki) if ( test_executable "makeself.sh" ); then create_loki || echo "Error: loki creation failed" else echo " *** Aborting create loki_setup ***" fi ;; debian) if ( test_executable "dpkg" ); then create_debian || echo "Error: .deb creation failed" else echo " *** Aborting create .deb package ***" fi ;; debdload) if ( test_executable "dpkg" ); then create_debdload || \ echo "Error: downloader .deb creation failed" else echo " *** Aborting create .deb downloader package ***" fi ;; debrsync) if ( test_executable "dpkg" ); then create_debrsync || \ echo "Error: rsync .deb creation failed" else echo " *** Aborting create .deb rsync package ***" fi ;; rpm) if ( test_executable "noidea" ); then create_rpm || echo "Error: .rpm creation failed" else echo " *** Aborting create .rpm package ***" fi ;; esac done exit 0
loki_setup is difficult to install, and in the end not worth it. This file is a bzipped tarball of the files needed for a loki_setup. Place this file in the directory where you are running legends_packager.sh from (Don't put it in legends_dir/ or it will unnecessarily add 1.8M to the installers). Alternatively you can specify it's location with legends_packager.sh –loki-setup –loki-tar /path/to/legends_loki_skeleton.tar.bz2 -v 0.4.1.42 legends_dir/
This is a replacement for the current runlegends. It allows the script to be linked to. For example, you can create a symbolic link in /usr/local/bin which will allow you to run Legends without having to 'cd' into the legends directory. You must use this script if you want the loki_setup installer to be able to launch legends.
#!/bin/sh if [ -L $0 ]; then LEGENDS_DIR="$(dirname $(readlink $0))" else LEGENDS_DIR="$(dirname $0)" fi cd $LEGENDS_DIR export LD_LIBRARY_PATH=./ ./LinLegends $* &
This is the setup script that is called by makeself after it has extracted Legends. It is basically the same as the current installation script, with some extra colour and a check to make sure there is enough space on the hardrive before installing. It must be put into the root Legends directory (where LinLegends is) before the makeself archive is created, it also must be called install.sh. This script is also used by the .deb installers to install the menu entries.
#!/bin/sh create_menu_entry() { # Attempt to make desktop file. echo "Attempting to create menu entries for legends..." mkdir -p $startMenu touch $startMenu/legends.desktop if [ -e $startMenu/legends.desktop ]; then cat << EOF > $startMenu/legends.desktop [Desktop Entry] Encoding=UTF-8 Name=Legends Comment=Legends fast paced Freedom of Movement FPS Exec=$installDir/runlegends Icon=$installDir/legends.ico Terminal=false Type=Application Categories=Application;Game Path=$installDir EOF echo "Menu entry created. You may start legends from the start menu." return 0 else echo "Cannot create launch menu startup." return 1 fi } prompt_yes_no() { while true; do echo -ne "${1} (y or n): " read answer if echo $answer | grep -i "^y\(es\)\?$" &> /dev/null; then return 0 elif echo $answer | grep -i "^n[o]\?$" &> /dev/null; then return 1 else echo "Unrecognised option, please try again..." fi done } if [ "$1" == "--menu-only" ]; then if [ ! -z "$2" ]; then installDir=$2 else installDir="$(pwd)/$(dirname $0)" fi if [ $(id -u) -ne 0 ]; then startMenu="$HOME/.local/share/applications" else startMenu="/usr/share/applications" fi create_menu_entry exit $? fi echo -e "\nLegends installer - starting installation... please wait\n" defaultDir="/usr/games/legends" startMenu="/usr/share/applications" if [ $(id -u) -ne 0 ]; then echo "It is suggested that you run this install script as root" echo "to allow all users to play legends on this machine" if ! prompt_yes_no "Proceed anyway?"; then echo "exiting installation." exit 0 fi defaultDir="$HOME/legends" startMenu="$HOME/.local/share/applications" fi echo -ne "\nPlease enter the installation location [$defaultDir]: " read installDir if [ "$installDir" = "" ]; then installDir="$defaultDir" fi mkdir -p $installDir # Check to see if there is enough space first installDirSpace="$(df -m $installDir | tail -n 1 | awk '{print $3}')" legendsSize="$(du -s -m $(pwd)/$(dirname $0) | awk '{print $1}')" if ((installDirSpace < legendsSize)); then echo -ne "\n\E[01;31m*****************************\n"\ "\b********** WARNING **********\n"\ "\b*****************************\E[0;0m\n"\ "\bYou do not have enough space available at $installDir.\n"\ "\bLegends requires $legendsSize \bM, $installDir only has"\ "$installDirSpace \bM remaining.\n" if ! prompt_yes_no "\nDo you wish to proceed anyway?" ; then echo "exiting installation." exit 0 fi fi if [ -w $installDir ]; then if [ -d $installDir ]; then echo "Install directory ready." else echo "Install location $installDir not usable"\ "(location not a directory)." exit 1 fi else echo "Install location $installDir not usable." \ "(Cannot write to directory)." exit 1 fi # Take the bzipped tar portion of this file and pipe it to tar. cp -R "$(pwd)/$(dirname $0)" $installDir if [ $? != "0" ]; then echo "Installation failed" exit 1 fi # Stop people from shooting themselves in the foot chmod a-x ${installDir}/$0 # Check for update echo "Checking for updates...please wait" RSYNC_SERVER="update.legendsthegame.net" if ! $(ping -c 1 ${RSYNC_SERVER} &> /dev/null); then echo "Error: ${RSYNC_SERVER} is unreachable. Either the" echo "update server is down or you are not connected to" echo "the internet. Please try updating later." else RSYNC_BYTES=$( $installDir/update --size ) if [ "${RSYNC_BYTES}" != "0" ]; then echo -ne "There are updates available totalling" \ "${RSYNC_BYTES} bytes.\n" if prompt_yes_no "Do you wish to update Legends now?"; then echo "Performing update..." sh "$installDir/update" else echo "Skipping update..." fi else echo "No new updates...continuing" fi fi # Create menu entry create_menu_entry echo -ne "\nTo start legends from a command line:\n"\ "\b\t\E[01;32mcd $installDir\n"\ "\b\t./runlegends\E[0;0m\n"\ "\n"\ "\bTo update legends, change directory into $installDir then run\n"\ "\bthe command './update' to check for available updates.\n"\ "\b\nLegends installation completed.\n" exit 0
New update script that can be run from anywhere on the system. The previous update script assumed that the user ran the update script from within the Legends directory, which could result in someone downloading the entire Legends rsync repository and putting it in an arbitrary place on their system. This update script also accepts the following command line options:
–pretend: Show what would be updated–size: Print how many bytes are in the update–force-ip: Force IP mode - may resolve connection issues–deb-install: Force update for .deb installations–help: Print help
The –size switch can be used to query if there are updates available. The install.sh checks to see if the result of update –size is non-zero, if so, then there is an update available. The –deb-install switch is used to force an update on systems that used the .deb to install, because the preferred update method is to run the .deb again.
#!/bin/bash # Legends update script for Linux # See: http://legendsthegame.net/forums/showthread.php?t=1263 # # Based on a script originally written by Eric Kincl, 2005 # Released under the GPLv2 rsyncDirs="commonlegends lin32legends" print_help() { echo "Usage: `basename $0` [--pretend|-p] [--size|-s] [--force-ip|-f]" echo " [--deb-install|-d]" echo echo " -p, --pretend: Show what would be updated" echo " -s, --size: Print how many bytes are in the update" echo " -f, --force-ip: Force IP mode - may resolve connection issues" echo " -d, --deb-install: Force update for .deb installations" } print_deb_update() { echo "This script has detected that you installed Legends with the" echo "Legends .deb installer. It is recommended that you update Legends" echo "by re-running the .deb installer. If you want to use this script" echo "anyway, run this script with the --deb-install option:" echo " ./update --deb-install" echo } while true; do case "$1" in --force-ip|-force-ip|--f|-f) force_ip=true ;; --deb-install|-deb-install|--d|-d) force_deb=true ;; --size|-size|--s|-s) size=true ;; --pretend|-pretend|--p|-p) pretend=true ;; --help|-help|--h|-h) print_help exit 0 ;; -*) echo "Unrecognised option: $1" print_help exit 1 ;; *) break ;; esac shift done # Check for .deb install if [ -e $(dirname $0)/deb-install ]; then if [ ! $force_deb ]; then print_deb_update exit 1 fi fi # Check for force ip mode if [ $force_ip ]; then # Force IP mode. May solve problem as described in # http://www.legendsthegame.net/forums/showthread.php?t=1298 server="74.52.112.163" else server="update.legendsthegame.net" fi if ! $(ping -c 1 ${server} &> /dev/null); then echo "Error: ${server} is unreachable. Either the" echo "update server is down or you are not connected to" echo "the internet. Please try updating later." exit 1 elif [ $size ]; then rsyncOpts="--dry-run --stats -zrvc" for dir in $rsyncDirs; do URL="rsync://${server}/$dir" rsyncCMD="rsync ${rsyncOpts} ${URL} $(dirname $0)" ((rsyncBytes += $( $rsyncCMD 2> /dev/null | \ grep 'Total transferred file size' | \ awk '{print $5}') )) done echo $rsyncBytes exit 0 elif [ $pretend ]; then rsyncOpts="--dry-run --stats -zrvc" else rsyncOpts="--progress --stats -zrvc" fi # Try to do the rsync for dir in $rsyncDirs; do URL="rsync://${server}/$dir" rsyncCMD="rsync ${rsyncOpts} ${URL} $(dirname $0)" echo $rsyncCMD $rsyncCMD rtn=$? if [ $rtn != "0" ]; then echo "Rsync failed with error code: $rtn" exit $rtn fi done if [ $pretend ]; then echo echo "update --pretend completed succesfully" exit 0 fi # Fix for gentoo users. # See: http://www.legendsthegame.net/forums/vbugs.php?do=view&vbugs_id=73 if [ -e /etc/gentoo-release ]; then chown -R root:games $(dirname $0); chmod -R g+rx $(dirname $0); fi echo echo "Update completed succesfully."; exit 0;