loginhsh 2.71 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
#!/bin/sh
# 2005-2006 (c) Etersoft www.etersoft.ru
# Author: Vitaly Lipatov <lav@etersoft.ru>
# Public domain
#
# Get shell in hasher with apt and mc
# -t - use test hasher
# -i - initialize hasher
# -M? - set target distro
# Public domain
# TODO: -r

13 14
# load common functions, compatible with local and installed script
. `dirname $0`/../share/eterbuild/functions/common
Vitaly Lipatov's avatar
Vitaly Lipatov committed
15
load_mod hasher rpm
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68

SAVEOPT=$@

#############################

Usage="Usage: $name [-t -i -h -r] bin.rpm..."
function mygetopts()
{
name=${0##*/}
Descr="$name - install package in hasher / take shell"

phelp()
{
	echog "$Descr"
	echog "$Usage"
	echog "Options:"
	echog " -i - initialize hasher"
	echog " -c - cleanup hasher"
	echog " -t - use test hasher dir"
	echog " -r - remote login to hasher"
}

while getopts :chitr opt; do
    case $opt in
    h) phelp; exit 0;;
    t) HASHERDIR=$HASHERDIR-test; TESTMODE=1 ;;
	i) INITIALIZE=1 ;;
	c) CLEANUP=1 ;;
	r) REMOTE=1 ;;
    +?) echog "$name: options should not be preceded by a '+'." 1>&2; exit 2;;
#    ?)  echog "$name: $OPTARG: bad option.  Use -h for help." 1>&2 ; exit 2;;
	?) OPTIND=$((OPTIND-1)); break;
    esac
done

# remove args that were options
if [ $# -gt 0 ]; then 
	shift $((OPTIND - 1))
fi

LISTRPMARGS=$@
}

parse_cmd_pre "$@" --

HASHERDIR=$HASHERDIR$MENVARG

HSH=/usr/bin/hsh
if [ ! -x "$HSH" ] ; then
	echo "Please install hasher package before use it"
	exit 1
fi

69 70 71 72
# export OURAPTCONF with temp. file contains correct path to sources.list
prepare_aptconfig

HASHERARG="--apt-config=$OURAPTCONF --target $DEFAULTARCH"
73 74 75 76 77 78 79 80 81 82 83 84

mygetopts $LISTARGS

if [ -n "$REMOTE" ] ; then
	check_key
	test -n "$BUILDSERVER" || fatal "Please set BUILDSERVER in config file"
	ssh -t $BUILDSERVER loginhsh ${SAVEOPT/-r/}
	exit 0
fi

if [ "$CLEANUP" = "1" ]; then
	echog "Cleanup $HASHERDIR ..."
85
	$HSH --cleanup-only $HASHERDIR $HASHERARG || fatal "cleanup"
86 87 88 89 90
	exit 0
fi

if [ ! -d $HASHERDIR -o "$INITIALIZE" = "1" ]; then
	echog "Initialize $HASHERDIR ..."
91
	mkdir -p $HASHERDIR && $HSH $HASHERARG --initroot-only $HASHERDIR || fatal "mkdir"
92 93
fi

94
SHELLHASHERARG="--mountpoints=/proc"
95 96 97 98 99 100

check_locking

echog "Prepare hasher in $HASHERDIR ..."
# there is package names in LISTRPMARGS
UTILPKG="mc"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
101
# FIXME: gnome program needs dbus-tools-gui
102
if [ -n "$TESTMODE" ] ; then
103
	UTILPKG="$UTILPKG XFree86-xauth fonts-ttf-liberation"
104 105 106
else
	UTILPKG="$UTILPKG etersoft-build-utils"
fi
107
$HSH-install $HASHERDIR --wait-lock $UTILPKG $LISTRPMARGS $LISTNAMES || fatal "Error with install"
108
echog "You are in hasher shell"
109
$HSH-shell $HASHERDIR $SHELLHASHERARG -Y --shell
110
if [ -n "$TESTMODE" ] ; then
111 112
	echo "Remove package for test preun scripts"
	$HSH-run --rooter $HASHERDIR -- rpm -e $(drop_pkg_extensions $LISTNAMES)
113 114 115
	echo "Cleanup hasher..."
	$HSH --cleanup-only $HASHERDIR
fi