#! /bin/sh # lk - Lazy Kwench's Syllable software installer # GLOBAL VARIABLES respository="http://syllable.q52.eu/software/all" # the repo is now very small, I'll try to copy over all of Kaj's files # Kaj, wanna set up an official server for this? simulate=0 verbose=0 # GET OPTIONS usage() { cat << EOF usage: $0 - lk 2009-02-21-1: Lazy Kwenchs Syllable software installation tool File format of the software is automagically detected. Applications (.application) and resources (.resource) are installed according to their suffix. All other suffices (e.g., .zip or .7z) are regarded as an archive with an install.sh file which will be run. If that fails, configure && make && make install will be run. The following naming convention is mandatory for resources: --..resource like agg-2.5-1.i586.resource The location of the file is automagically detected in the following order: local, network respository* and network URL (using cURL). Current (hardcoded) respository = $respository Options: -v Be verbose -s Just simulate (useful with -v) -u update (i.e.,remove former package and install specified one) -r remove downloaded or extracted temporary files* -h this help *) not yet implemented Author: Ruwen Boehm License: BSD EOF } ### populate settings via bash getopts ### while getopts ":vsurh:" options; do case $options in v ) verbose=1;; s ) simulate=1;; u ) update=1;; r ) tidayup=1;; h ) usage; exit;; \? ) usage; exit;; * ) echo "error: unknown option" && usage; exit;; esac done ### The long if-statements clobber the program code ### Please REWRITE this with the shortest possible conditional execution clause if [ $simulate = 1 ] then echo "Simulation Mode, no commands will be executed" fi ### ### INSTALLATION FUNCTIONS ### ### ### get_package $url ### ### Checks whether a URL is local, otherwise tries to get the URL from the web via cURL get_package() { url=$1 if [ $verbose = 1 ] then echo -n "Getting \"$url\" from ..." fi if [ -f "$url" ] then if [ $verbose = 1 ] then echo "local computer" fi eval "$2=$url" return 1 fi ### get last path of URL (hopefully the filename) lfile=${url##*\/} if [ $verbose = 1 ] then echo "curl \"$url\" -o $lfile" fi curl "$url" -o $lfile if [ -f $lfile ] then if [ $verbose = 1 ] then echo "from the web" fi eval "$2=$lfile" return 1 fi curl "$respository/$url" -o $lfile if [ -f $lfile ] then if [ $verbose = 1 ] then echo "getting $lfile from respository $respository" fi eval "$2=$lfile" return 1 fi } ### handle_alien $extracted_archive_directory ### ### Installs the extracted package by shell commands (currently install.sh and GNU configure / make etc. ### Please REWRITE this to be more interactive (-i flag?) and more configurable handle_alien() { pkgdir=$1 if [ ! -d $pkgdir ] then echo "no package directory found, aborting installation of this package" return 0 fi workingdir=`pwd` cd $pkgdir installpath=`find . -name install.sh -print` configurepath=`find . -name configure -print` if [ $verbose = 1 ] then echo "installing package by install.sh or make && configure" echo "--- package content ---" ls --color -sh echo "--- end of package content ---" echo "path to install.sh (if any): \"$installpath\"" echo "path to configure (if any): \"$configurepath\"" fi if [ -f $installpath ] then cd `dirname $installpath` if [ $simulate = 1 ] then echo "pwd: $PWD" echo "./install.sh" else ./install.sh fi elif [ -f $configurepath ] then cd `dirname $configurepath` if [ $simulate = 1 ] then echo "pwd: $PWD" echo "configure && make && make install" else ./configure && make && make install fi else echo "no install.sh or configure found, aborting installation of this package" cd $workingdir return 0 fi cd $workingdir return 1 # fix me! } ### install_package $local_filename ### ### Choses installation method and installs the local file. install_package() { fname=$1 ### The following is a lazy hack to get a proper basename or resource name. ### Please REWRITE it with some nice regular expressions! ### fname_base=`basename $1 | cut -s -d'.' -f1` rname_base=`basename $1 | cut -s -d'.' -f1 | cut -s -d'-' -f1` ### if [ $verbose = 1 ] then echo "Unpacking \"$fname\" (packagename \"$fname_base\", resource name \"$rname_base\",suffix \"${fname##*.}\")" fi if [ "${1##*.}" = "tar" ] then echo "(uncompressed tar)" tar tvf $1 elif [ "${1##*.}" = "gz" ] then echo "(gzip-compressed tar)" tar tzvf $1 elif [ "${1##*.}" = "application" ] then echo "(Syllable/Application)" if [ $simulate = 1 ] then echo "unzip $fname -d /Applications/$fname_base" else unzip $fname -d /Applications/$fname_base fi elif [ "${1##*.}" = "7z" ] then echo "(7zip/archive)" if [ $simulate = 1 ] then echo "7z x $fname -o$fname_base" else 7z x $fname -o$fname_base ### can't 7zip not also process ordinary ZIP files, so we could merge this and the following block of code? ### 7zip for Windows can, what are the flags for p7zip? fi handle_alien $fname_base elif [ "${1##*.}" = "zip" ] then echo "(zip/archive)" if [ $simulate = 1 ] then echo "unzip $fname -d $fname_base" else unzip $fname -d $fname_base fi handle_alien $fname_base elif [ "${1##*.}" = "resource" ] then echo "(Syllable/Resource)" if [ -f /usr/$rname_base ] then if [ $update = 1 ] then echo "removing already installed package..." if [ $simulate = 1 ] then echo "package unregister $rname_base" echo "rm -r /usr/$rname_base" else package unregister $rname_base rm -r /usr/$rname_base sync fi else echo "package already installed, use -u to update (delete current, install specified)" return 0 fi fi if [ $simulate = 1 ] then echo "unzip $fname -d /usr/$rname_base" echo "package register $rname_base" else unzip $fname -d /usr/$rname_base package register $rname_base sync fi elif [ "${1##*.}" = "bz2" ] then echo "(bzip2-compressed tar)" tar tbvf $fname else echo "(unknown) aborting installation of that package" fi } ### add_package $url ### ### Combines package retrival function and installation functions; called from main program ### This function is probably obsolete, REWRITE it add_package() { url=$1 if [ $verbose = 1 ] then echo "add_package: \"$url\"..." fi get_package $url pkgname install_package $pkgname } ### Only root can perform these operations on the filesystem. ### Let's find out, who we are and continue or stop. if [ "$USER" != "root" ] then echo "The installation is not being run by the administrative user." echo "Installation aborted." echo "You can log in as the \"root\" user and try again." exit 1 fi ### Show all arguments (verbose debug message) or ### loop all non-options and call add_package if [ $verbose = 1 ] then echo "v: lk called with \"$@\"..." fi for software in $@ do if [ `expr $software : -` = 1 ] then if [ $verbose = 1 ] then echo "v: skipping option $software..."; fi else echo "Processing package \"$software\" ...\n" add_package $software fi done