rpmgp 7.02 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
#!/bin/sh
# 2004-2008 (c) Etersoft www.etersoft.ru
# Author: Vitaly Lipatov <lav@etersoft.ru>
# Public domain
#
#   src.rpm-     (  ALT Linux)     .
#        
#      apt-get source 
# -c - checkonline
# -n - do not install

12 13
# load common functions, compatible with local and installed script
. `dirname $0`/../share/eterbuild/functions/common
14
load_mod rpm repl
15 16 17 18

# path to ALT Linux's repositories
REPOSITORY="files/SRPMS obsolete orphaned"

19 20 21 22 23 24
# loads repos file and fill SYSNAME and SYSURL arrays
load_systems_list()
{
	local IDX=0
	local line
	while read line ; do
25 26
		# skip comments
		echo $line | grep "^#" >/dev/null && continue
27 28 29 30
		SYSNAME[$IDX]=${line/ *.*/}
		#FTP[$IDX]=${line/.* \+/}
		SYSURL[$IDX]=$(echo $line | sed -e "s|.* \+||g")
		IDX=$(($IDX+1))
31
	done < $ETERBUILDETC/repos
32
}
33 34 35 36 37 38 39

list_systems()
{
	echo "Known systems:"
	for ((i=0; i < ${#SYSNAME[*]}; i++)) ; do
			printf "[%-17s] %s\n" ${SYSNAME[$i]} ${SYSURL[$i]}
	done
40 41
	echo
	echo "You can add system to /etc/eterbuild/repos"
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
}

html_filter()
{
	grep "src.rpm" | sed -e "s|.*href=\"||g" | sed -e "s|\".*||g"
}

list_filter()
{
	sed -e "s|.src.rpm$||g"
}

# Using: git_list idx [force]
# set LIST variable to list file
get_list()
{
	[ -n "$VERBOSE" ] && echo "get_list for $1"
	local URL=${SYSURL[$1]}
	local FORCE=$2
	local SYS=${SYSNAME[$1]}
Vitaly Lipatov's avatar
Vitaly Lipatov committed
62 63 64
	local CURL=curl

	which $CURL 2>/dev/null >/dev/null || fatal "curl command needed for download"
65 66 67 68 69
	LIST=$OURTMPDIR/tmp-rpmgpall-$SYS
	if [ ! -f "$LIST" ] || [ "$FORCE" = "force" ] ; then
		echo "Get list for $SYS from $URL"
		#curl -l $URL/ >$LIST
		# suitable for ftp and http lists
Vitaly Lipatov's avatar
Vitaly Lipatov committed
70
		$CURL -l $URL/ | html_filter >$LIST
71 72 73 74 75 76 77
	else
		echo "List for $SYS"
	fi
}

get_system_idx()
{
78 79 80
	if [ -z "$1" ] ; then
		return 1
	fi
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
	for ((i=0; i < ${#SYSNAME[*]}; i++)) ; do
		if [ ${SYSNAME[$i]} = "$1" ] ; then
			echo $i
			return 0
		fi
	done
	return 1
}

check_name()
{
	if [ -z "$1" ] ; then
		echo "Error: missed package param"
		exit 1
	fi
	NLIST=`cat $LIST | grep -i $1`
97
#	if [ `cat $LIST | list_filter | grep -i $1 | wc -l` -gt 1 ] ; then
98
		#echo "Please type a full name of the package"
99 100 101
#		print_list $NLIST
#		return 1
#	fi
102 103 104 105 106 107 108 109 110 111 112

	if [ -z "$NLIST" ] ; then
		echo "$1: Not found"
		return 1
	fi

	return 0
}

check_system()
{
113
	local i
114 115 116
	local IDX=$1
	local URL=${SYSURL[$IDX]}
	#echo "Check for $SYSTEM"
117
	get_list $IDX
118
	#ls -l $LIST
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
	check_name $NAME
	if [ "$DOWNLOADALL" ] ; then
		for i in $NLIST ; do
			wget -c $URL/$i
		done
	fi
}

update_cache_list()
{
	load_systems_list
	# if followed by system name
	IDX=`get_system_idx "$1"`
	if [ -n "$IDX" ] ; then
		get_list $IDX force
		shift
		exit 0
	fi
	# update all systems
	for ((i=0; i < ${#SYSNAME[*]}; i++)) ; do
		get_list $i force
	done
141 142
}

143 144 145 146 147
Usage="Usage: $name [options] [system] pkgname"
function mygetopts()
{
name=${0##*/}
Descr="$name - various package download operations"
148

149 150 151 152 153 154
phelp()
{
# TODO: improve description
	echog "$Descr"
	echog "$Usage"
	echog "Options:"
155 156 157
	echog "rpmgp [-a -c -n] [system] pkgname - download src.rpm from 'system' repository to RPM/SRPMS and install it"
	echog " name - installed package name or src.rpm"
	echog " system - name of system (ALT Linux by default if -a missed too)"
158 159 160 161 162 163
	echog " -a  search pkgname in all known repositories"
	echog " -b  install packages needed for build (use sudo apt-get) (need spec not package name)"
	echog " -c  check if this package exists in the ALT Linux repository"
	echog " -d  download all matched packages"
	echog " -l  list packages needed for build (in local pkg system notation) (experimental)"
	echog " -n  do not install after download, just download in current dir"
164
	echog " -r  refresh package list (download it again)"
165
	echog " -s  list all known remote repositories"
166
	exit 0
167
}
168 169

TRYINST="1"
170 171 172 173
while getopts :habcdlnrs opt; do
    case $opt in
    h) phelp; exit 0;;
    a) ALLSYSTEM=1 ;;
174
    b) INSTALLBINARY=1 ;;
175 176 177 178 179 180 181 182 183 184 185 186 187 188
    c) CHECKONLINE=1 ;;
    d) DOWNLOADALL=1 ;;
    l) LISTREQS=1 ;;
    n) TRYINST="" ;;
    r) UPDATECACHE=1 ;;
    s) load_systems_list
       list_systems
       exit 0
       ;;
    +?) 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
189

190 191 192 193
# FIXME:     (, -i, -b)
# remove args that were options
if [ $# -gt 0 ]; then 
	shift $((OPTIND - 1))
194 195
fi

196 197 198 199 200 201 202 203 204
# pass other options to RPM:
LISTARGS=$@
}

mygetopts "$@"

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

207 208 209 210
# optional arg
if [ -n "$UPDATECACHE" ] ; then
    update_cache_list $1
    exit 0
211 212
fi

213 214
test -z "$LISTARGS" && fatal "Please run with spec/package name"

215 216 217 218 219 220 221 222

#   ,  ( ?),   
#  -    
#    
#
#  - [] 

# install binary packages
223
if [ -n "$INSTALLBINARY" ] ; then
224 225 226 227 228 229 230 231 232
	parse_cmd_pre "$@"
	pack_src_rpm $LISTRPMARGS
	echog "Running apt-get for install needed packages for $LISTBUILT"
	# FIXME: ALT Specific
	$SUDO apt-get build-dep $LISTBUILT
	exit 0
fi

# lists packages for build
233
if [ -n "$LISTREQS" ] ; then
234 235 236 237 238
	print_target_buildreq $1
	exit 0
fi

# Check online
239
if [ -n "$CHECKONLINE" ] ; then
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
	if [ -f $1 ] ; then
		build_rpms_name "$1"
		SRCRPM=$NAMESRPMIN
	else
		echo $1 | grep rpm 2>/dev/null && SRCRPM=$1 ||
		SRCRPM=`rpm -q $1 --queryformat "%{SOURCERPM}\n" | tail -n 1` 
	fi
	RET="MISSED"
	for i in $REPOSITORY ; do
		echog "Checking in repository $i ..."
		rsync -n --progress $RSYNCSISYPHUS/$i/$SRCRPM  >/dev/null 2>&1 && { RET=$i; break; }
	done
	echog "Repository     Filename"
	printf "%-12s %30s\n" $RET $SRCRPM
	exit 0
fi

257 258 259 260 261
if [ -n "$2" ] && [ "$1" = "all" ] ; then
    shift
    ALLSYSTEM=1
fi

Vitaly Lipatov's avatar
Vitaly Lipatov committed
262 263 264 265 266 267 268 269
# Check concrete system
# two params: system, package
if [ -n "$2" ] ; then
	NAME=$2
	load_systems_list
	IDX=`get_system_idx "$1"`
	if [ -n "$IDX" ] ; then
		check_system $IDX
270
		print_list $NLIST
Vitaly Lipatov's avatar
Vitaly Lipatov committed
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
	else
		#fatal "Unknown system '$1', use rpmgp -s for get list"
		NAME=
	fi
	exit 0
else
	NAME=$1
fi

# Check all systems
if [ -n "$ALLSYSTEM" ] ; then
	load_systems_list
	# search throw all systems
	for ((i=0; i < ${#SYSNAME[*]}; i++)) ; do
		echo
		check_system $i
287
		print_list $NLIST
Vitaly Lipatov's avatar
Vitaly Lipatov committed
288 289 290 291 292
	done
	exit 0
fi


293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
echo
echo "########################################"
if [ -z "${1/*src.rpm/}" ]
then
	# it is src.rpm package
	SRCRPM=$1
else
	if [ -z "${1/*rpm/}" ] ; then
		# it is rpm package (locale placed?)
		SRCRPM=`rpm -qp $1 --queryformat "%{SOURCERPM}\n"`
	else
		SRCRPM=`rpm -q $1 --queryformat "%{SOURCERPM}\n"`
	fi
fi
test -z "$SRCRPM" && fatal "Cannon find package for $1"
echog "Try to download $SRCRPM"

310
test -z ${TRYINST} || { mkdir -p $RPMTOPDIR/SRPMS && cd $RPMTOPDIR/SRPMS ; }
311 312 313 314 315 316 317 318 319 320 321 322 323 324
echog "Downloading in $(pwd)"

for i in $REPOSITORY
do
	echo "--------Check in $i-----------"
	rsync -vay --partial --checksum --copy-links \
		--delete-after --progress $RSYNCSISYPHUS/$i/$SRCRPM ./$SRCRPM && break
done

test -z ${TRYINST} && exit 0
echo
echog "Installing..."
rpm -iv $SRCRPM