stklos-install 5.66 KB
Newer Older
eg's avatar
eg committed
1 2 3 4
#!/bin/sh
# 							-*- shell-script -*-
# stklos-install		-- Install STklos extensions
# 
5
# Copyright  2001-2007 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.fr>
eg's avatar
eg committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
# 
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 
# USA.
# 
#           Author: Erick Gallesio [eg@essi.fr]
#    Creation date: 18-Mar-2005 13:26 (eg)
25
# Last file update: 12-Apr-2007 15:05 (eg)
eg's avatar
eg committed
26 27 28 29 30 31 32 33 34 35 36
#

DISTURL="http://www.stklos.net/download/extensions"
PROG=$0

opt_keep=0
opt_uninstall=0

# ----------------------------------------------------------------------
# 	Usage ...
# ----------------------------------------------------------------------
37
usage()
eg's avatar
eg committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
{
    cat <<EOF
Usage: stklos-setup [OPTIONS] package
Options:
	[--help | -h | -?]	Show a list of options
        |--keep | -k]		Keep files to fix installation problems
	[--uninstall | -u]	Uninstall previously installed package
	[--list | -l]		List installed extensions
EOF
    exit $1
}

# ----------------------------------------------------------------------
# 	trace ...
# ----------------------------------------------------------------------
53
trace()
eg's avatar
eg committed
54 55 56 57 58 59 60 61 62 63 64
{
    case $TERM in 
	vt100|xterm*|rxvt|urxvt*) begin=""; end="" ;;
	*) begin=""; end="";;
    esac
    echo "${begin}**** $1${end}" >&2
}

# ----------------------------------------------------------------------
# 	try-fetch ...
# ----------------------------------------------------------------------
65
try_fetch()
eg's avatar
eg committed
66 67 68 69 70 71 72 73 74 75 76 77
{
    pkg=$1
    trace "Package $pkg is absent. Try to fetch it from $DISTURL" 
    wget $DISTURL/${pkg}.stgz 2>/dev/null >&2
    if [ $? = 0 ] ;then
	trace "Download finished"
    fi
}

# ----------------------------------------------------------------------
# 	die ...
# ----------------------------------------------------------------------
78
die()
eg's avatar
eg committed
79 80 81 82 83 84 85 86 87
{
    echo $1 >&2
    exit 1
}


# ----------------------------------------------------------------------
# 	find_prefix ...
# ----------------------------------------------------------------------
88
find_prefix()
eg's avatar
eg committed
89
{
90
    if [ `id -u` -eq 0 ] ;then 
eg's avatar
eg committed
91 92 93 94 95 96 97 98 99 100
	echo "`stklos-config --prefix`/share/stklos/extensions"
    else
	echo $HOME/.stklos/ext/extensions
    fi
}


# ----------------------------------------------------------------------
# 	install_package ...
# ----------------------------------------------------------------------
101
install_package()
eg's avatar
eg committed
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
{
    pkg=$1
    TMP=/tmp/stklos-setup-$$
    BUILDDIR=$TMP/`basename $pkg`
    
    trace "Installing package $pkg"
    if [ ! -f ${pkg}.stgz ] ;then
	try_fetch $pkg
    fi
    
    if [ ! -f ${pkg}.stgz ] ;then
	# Not here after fetch. Signal an error 
	trace "Cannot find extension $pkg. "
	trace "Place \"$pkg.stgz\" file in current directory and run $PROG again"
	exit 1
    fi
    
119
    if [ `id -u` -eq 0 ] ;then 
eg's avatar
eg committed
120 121 122 123 124 125 126 127 128 129 130
	prefix=`stklos-config --prefix`
    else
	mkdir -p $HOME/.stklos
	prefix=$HOME/.stklos
    fi

    trace "Installation takes place in in $BUILDDIR"
    mkdir -p $TMP || die "$PROG: cannot make trmporary directory"
    cat $pkg.stgz | (cd $TMP; tar xvfz -)

    (eval "cd ${BUILDDIR}*"; 
131
     trace "Configuring package ..." && ./configure &&
eg's avatar
eg committed
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
     trace "Make package ..." &&  make && 
     trace "Installing package ..." && make install)

    if [ $? = 0 -a $opt_keep = 0 ] ;then
	/bin/rm -rf $TMP
    else
	trace "Problem while compiling package."
	trace "Look at $BUILDDIR directory for more information"
    fi
    trace "Package $pkg is successfully installed."
}


# ----------------------------------------------------------------------
# 	uninstall_package ...
# ----------------------------------------------------------------------
148
uninstall_package()
eg's avatar
eg committed
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
{
    pkg=$1
    
    trace "Unstalling package $pkg"
    
    DBDIR=`find_prefix`
    DATAFILE=`echo $DBDIR/$pkg*`
    if [ ! -f $DATAFILE ] ;then
	trace "Package $pkg was not previously installed. Quit."
	exit 1;
    fi
    echo -n "Please confirm deletion of `basename $DATAFILE`? "
    read R
    case $R in 
	y|Y) trace "Deleting files ..." 
	     cat $DATAFILE | while read file ;do
		 trace "   $file"
		 rm -f $file
	     done
	     rm -f $DATAFILE
	     trace "Package $pkg is successfully uninstalled."
	     ;;
	*) trace "No package uninstalled" ;;
   esac
}

# ----------------------------------------------------------------------
# 	list_extensions ...
# ----------------------------------------------------------------------
178
list_extensions()
eg's avatar
eg committed
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
{
    trace "Available extensions:"
    DIR=`find_prefix`
    if [ -d $DIR ] ;then
	cd $DIR
	ls | while read line ;do
	    echo "	$line"
	done
    fi
}

#
# Program starts here
#
if test $# -eq 0; then
    usage 1 1>&2
fi

while test $# -gt 0; do
    case $1 in
	--help|-h|-\?)
	    usage 0 1>&2
	    exit 0;
	    ;;
	--keep|-k)
	    opt_keep=1;
	    shift
	    ;;
	--uninstall|-u)
	    opt_uninstall=1
	    shift
	    ;;
	--list|-l) 
	    list_extensions
	    exit 0
	    ;;
	-*)
	    echo "bad option $1" 1>&2
	    usage 1 1>&2
	    exit 1
	    ;;
	*)
	    if [ $# -gt 1 ] ;then
		echo "$PROG: too much arguments: $*" 1>&2
		exit 1
	    fi
	    pkg=`basename $1 .stgz`
	    if [ $opt_uninstall = 1 ] ;then
		uninstall_package $pkg
	    else
		install_package $pkg
	    fi
	    exit 0
	    ;;
    esac
done