~cypheon/pkgsrc-wip

pkgsrc-wip/apstget/files/apst-get -rw-r--r-- 16.7 KiB
5f1bf4f5 — Johann Rudloff Subst PLIST paths for platform specific files for other architectures 8 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
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
178
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
#!/bin/sh
#
# APST-GET : Yet Another PkgSrc Tool to manage packages.
#
# AUTHOR: pancake < pancake@phreaker.net >
# DATE: 2006/04/10
#
# depends: pkg_find, pkg_tarup, awk, pkglint, pkg_chk
#
#

if [ -e "_etc_/apstget.conf" ]; then
. _etc_/apstget.conf
fi

# apstget.conf looks like:
#
# 
# CLEAN_BUILD="1"     # clean before and after every build
# PACKAGE_BUILD="0"   # build packages
# INTERACTIVE="1"     # wait user for confirmations
# QUITE="1"           # Be silent in builds
# SKIP_LICENSES="0"   # Ignore LICENSES
# IGNORE_ERRORS="0"   # Don't stop on failed build
# UPDATE_METHOD="cvs" # cvsync|cvs|sup|cvsup
# UPDATE_ARGS=""      # UPDATE_METHOD flags
# GET_FIRST="0"       # Always get first pkg on dup packages found
# PREFERED=""         # space-separated list of prefered packages (for dup)

#----->8--------------#
VERSION=20060410
MAKEFLAG="PKG_RESUME_TRANSFERS=YES" # make this as default
PREFIX=_pfx_
MAKE=_makebin_
PKGFIND=${PREFIX}/bin/pkgfind
PKGCHK=${PREFIX}/sbin/pkg_chk
PKGSRC_DIR=_psd_
PKG_DBDIR=_dbd_
DEFAULT_TARGETS="${DEFAULT_TARGETS}"
CVS_RSH=ssh

if [ "${CLEAN_BUILD}" = "" ]; then
	CLEAN_BUILD="1"
fi
if [ "${INTERACTIVE}" = "" ]; then
	INTERACTIVE="1"
fi
if [ "${IGNORE_ERRORS}" = "" ]; then
	IGNORE_ERRORS="0"
fi
if [ "${UPDATE_METHOD}" = "" ]; then
	UPDATE_METHOD="cvs"
fi
if [ "${GET_FIRST}" = "" ]; then
	GET_FIRST="0"
fi
if [ "${UPDATE_METHOD}" = "cvs" ]; then
	if [ "${UPDATE_ARGS}" = "" ]; then
	UPDATE_ARGS="-z 3"
	fi
fi
WRAPPER=_pfx_/libexec/apstget-wrapper

if [ ! -e "/dev/stdin" ]; then
	echo "/dev/stdin doesn't exist. Please create the device first."
fi
if [ ! -e "/dev/stderr" ]; then
	echo "/dev/stderr doesn't exist. Please create the device first."
fi

do_make_clean () {
	if [ "${CLEAN_BUILD}" = "1" ]; then
		echo "==> Cleaning..."
		${MAKE} clean
	fi
}

do_make_package () {
	if [ "${PACKAGE_BUILD}" = "1" ]; then
		echo "==> Generating package..."
		env PACKAGE_NOINSTALL=YES ${MAKE} ${MAKEFLAG} package
	fi
}

process_failed () {
	if [ "${IGNORE_ERRORS}" = "0" ]; then
		exit 1;
	fi
}

press_any_key () {
	if [ "${INTERACTIVE}" = "1" ]; then
		echo "==> Press Ctrl-C to cancel, any other key to proceed."
		read me
	fi
}

do_usage() {
	echo "Usage: $1 [action] [pkgtargets...]"
	echo ""
	echo "Actions:"
	echo "  install      - install/update selected packages."
	echo "  upgrade      - update the selected packages and solves dependencies."
	echo "  dist-upgrade - update the entire system."
	echo "  whereis      - returns the package containing a file."
	echo "  remove       - remove the selected packages."
	echo "  update       - update the pkgsrc/-wip tree."
	echo "  relink       - try to solve all broken libs."
	echo "  clean        - clean all build directories."
	echo "  autoclean    - remove all outdated distfiles."
	echo "  orphan       - list orphaned packages."
	echo "  show         - show DESCR of target package."
	echo "  check        - Checks MD5s of pkg files."
	echo ""
	echo "Variables (environ|_etc_/apstget.conf):"
	echo "  CLEAN_BUILD=1, INTERACTIVE=1, QUITE=0, IGNORE_ERRORS=0"
	echo "  UPDATE_METHOD=cvs, UPDATE_ARGS, GET_FIRST=0, PREFERED"
	echo "  BUILD_PACKAGES=0, SKIP_LICENSES=0"
	echo ""
	echo "VERSION=${VERSION}"
}

check_version() {
	cPKG=$1
	cDIR=$1
	if [ -n "${cDIR}" ]; then
	if [ "`echo $cPKG | grep /`" = "" ]; then
		cDIR=`${PKGFIND} -qx $cPKG`
	else
		cPKG=`echo $cPKG | awk -F / '{ print $2 }'`
	fi
		cd ${PKGSRC_DIR}/${cDIR}/
		cPKG=`${MAKE} show-var VARNAME=PKGNAME | awk -F '([.\-]*)-[0-9]' '{print $1 }'`
		IVER=`pkg_info -e $cPKG`
		if [ "$?" = "1" ]; then
			echo "missing"
		else
			cd ${PKGSRC_DIR}/${cDIR}
			DVER=`${MAKE} show-var VARNAME=PKGNAME 2> /dev/null`
			if [ ! "${DVER}" = "${IVER}" ]; then
				echo "from ${IVER} to ${DVER}"
			fi
		fi

	fi
}

do_relink() {
	if [ "$1" = "" ]; then
	echo "==> Looking for broken libs on ${PREFIX}[/bin|/sbin|/lib]"
		FILES=`find ${PREFIX}/bin ${PREFIX}/sbin ${PREFIX}/lib -type f`
	else
		lPKG=$1
		if [ !  "`echo $1 |grep /`" = "" ]; then
			cd ${PKGSRC_DIR}/$1
			lPKG="`${MAKE} show-var VARNAME=PKGNAME`"
		fi

		echo "==> Looking for unlinked binaries in package ${lPKG}"
		FILES=`pkg_info -L $lPKG 2> /dev/null | grep -e bin -e lib`
		if [ "$?" = "1" ]; then
			# pkgname not found, find by dirname
			echo "==> pkgname mismatch, walking thru the tree..."
			##
			DIR=${lPKG}
			if [ -z "`echo $lPKG | grep /`" ]; then
				DIR=`${PKGFIND} -qx $lPKG`
			fi
			# checks
			if [ -z "${DIR}" ]; then
				echo "==> Package not found"
				return
			fi
			if [ ! -d "${PKGSRC_DIR}/${DIR}" ]; then
				echo "==> Directory not found"
				return
			fi
			cd ${PKGSRC_DIR}/${DIR}
			lPKG="`${MAKE} show-var VARNAME=PKGBASE`"
			echo "==> Using ${lPKG}"
			##
			FILES=`pkg_info -L $lPKG 2> /dev/null | grep -e bin -e lib`
			if [ "$?" = "1" ]; then
				echo "==> Package ${lPKG} is not installed."
				return
			fi
		fi
	fi
	X11_TYPE=`grep -e X11_TYPE /etc/mk.conf | awk -F = '{ print $2; }'`
	if [ "${X11_TYPE}" = "" ]; then X11_TYPE=XxZzYy; fi # invalid directory

	for A in ${FILES}; do
		LIB=`ldd ${A} 2>/dev/null |grep found|awk -F = '{ print $1 }'`
		for B in ${LIB}; do
		#--
		OK="1"
		for C in ${UNRESOLVED} ; do
			if [ "${C}" = "${B}" ]; then
				OK="0"
			fi
		done
		if [ "${OK}" = "1" ]; then
		echo "==> Relinking ${B}..."
		COW="`echo ${B} |awk -F so '{ print $1 }'`so"
		RESOLVED=0
		for RELINKDIR in ${PREFIX}/lib ${PREFIX}/${X11_TYPE}/lib /lib /usr/lib ; do
		if [ ! -d "${RELINKDIR}" ]; then continue; fi
		TARGET="`ls -l ${RELINKDIR}/${COW}.* 2>/dev/null | grep -e ^- `"
		if [ "${TARGET}" = "" ]; then
			continue;
		else
			RESOLVED=1
			TARGET=`echo ${TARGET} | awk '{ print $9 }'`
			ln -s ${TARGET} ${RELINKDIR}/$B
			break;
		fi
		done # for RELINKDIR
		if [ "${RESOLVED}" = "1" ]; then
			echo " * Solved against ${TARGET}"
		else
			echo " * Unable to be resolved"
			UNRESOLVED="${UNRESOLVED} ${B}"
		fi
		#--		
		fi
		done # for A in ${files}
	done
}

required_deps() {
	STEP=1
	for A in `${MAKE} show-installed-depends` ; do
	case ${STEP} in
	"1")
		PKG="`echo $A | awk -F '>' '{print $1 }'`"
		STEP=2
		;;
	"2")
		STEP=3
		;;
	"3")
		STEP=1
		if [ -z "`echo ${A} | grep -e '-' `" ]; then
			if [ -n "`pkg_info ${A} 2> /dev/null`" ]; then
			echo ${PKG} ;
			fi
		PKG=${A}
		STEP=2
		fi
		;;
	esac
	done

	if [ "${A}" = "=>" ]; then
		echo ${PKG}
	fi
}

do_auto_relink() {
	rPKG=$1
	if [ ! "`echo $1| grep /`" = "" ]; then
		rPKG=`echo $1 | awk -F / '{ print $2 }'`
	fi
	rPKGS=`pkg_info -qR ${rPKG}`
	echo "==> Doing automatic relink for inverse deps of ${rPKG}"
	for A in ${rPKGS} ; do
		do_relink ${A}
	done
}

do_install() {
	PKG=$1
	DIR=$1
	UPD=$2 # Update flag
	if [ -z "`echo $PKG | grep /`" ]; then
		DIR=`${PKGFIND} -qx $PKG`
		if [ "${DIR}" = "" ]; then
			DIR=NOTFOUND
		fi
	else
		PKG=`echo $PKG | awk -F / '{ print $2 }'`
	fi

	if [ "${GET_FIRST}" = "1" ]; then
		DIR=`echo ${DIR} | awk '{print $1}'`
	else 
		for A in `echo ${PREFERED}`; do
			for B in ${DIR} ; do
			if [ "${A}" = "${B}" ]; then
				DIR=${A}
				echo "==> Using prefered ${A}"
				break;
			fi
			done
		done
	fi

	if [ ! -e "${PKGSRC_DIR}/${DIR}" ]; then
		if [ "`echo ${DIR}|awk '{print $2}'`" = "" ]; then
			echo "==> Error! The package $PKG was not found!"
		else
			echo "==> ${PKG} is in more than one category. Specify it:"
			echo "==> You can also use GET_FIRST or PREFERED"
			echo "==> Found at: `echo ${DIR}`"
		fi
	else

	STAT="`check_version $DIR`"
	if [ -z "${STAT}" ]; then
		echo "==> Package ${DIR} is at the latest version"
	else
	echo "==> Preparing installation for $DIR"
	cd ${PKGSRC_DIR}/${DIR}

	# Clean-UP
	REPLACE=""
	INSTALL=""

	# Get per-version dependencies
	BDEP="`required_deps`"
	REQUIRED=""
	for A in ${BDEP} ; do
		REQUIRED="${REQUIRED} `${PKGFIND} -qx ${A}`"
	done

	# Get all dependencies
	DEPS="`${MAKE} ${MAKEFLAG} show-depends-dirs`"
	for A in ${DEPS} ; do
		cd ${PKGSRC_DIR}/${DIR}
		DEPS2="${DEPS} `${MAKE} ${MAKEFLAG} show-depends-dirs`"
	done
	for A in ${DEPS2} ; do
		FOUND=0
		for B in ${DEPS}; do
			if [ "$A" = "$B" ]; then
				FOUND=1
			fi
		done
		if [ "${FOUND}" = "0" ]; then
			DEPS="${DEPS} ${A}"
		fi
	done
	DEPS="${DEPS} ${DIR}"
	for A in ${DEPS} ; do
		if [ -n "`echo ${REQUIRED} | grep ${A}`" ]; then
			IS_INSTALLED="`pkg_info ${A} 2> /dev/null`"
			if [ -z "${IS_INSTALLED}" ]; then
				CHK="preinstall"
			else
				CHK="required"
			fi
		else
			CHK=`check_version ${A}`
			if [ -n "`echo ${CHK} | grep missing`" ]; then
				CHK=missing;
			fi
		fi

		cd ${PKGSRC_DIR}/${A}/

		# package options
		PVAR=`${MAKE} show-var VARNAME=PKG_OPTIONS_VAR`
		if [ -z "${PVAR}" ]; then
			SPOP=""
			POPT=""
		else
			SPOP=`${MAKE} show-var VARNAME=${PVAR}`
			POPT="`${MAKE} show-var VARNAME=PKG_SUPPORTED_OPTIONS`"
			for X in ${POPT}; do
				WITH=1
				for Y in ${SPOP}; do
					case "${Y}" in
					"${X}")
						WITH=1
						break
						;;
					"-${X}")
						WITH=0;
						break;
						;;
					esac
				done
				if [ "${WITH}" = "1" ]; then
					PKGO="${PKGO} ${X}"
				else
					PKGO="${PKGO} -${X}"
				fi
			done
		fi

		# check actions for each package
		case "${CHK}" in
		"")
			# nothing to do here :)
			;;
		"preinstall")
			echo " [r] Required install for ${A}"
			PREINSTALL="${PREINSTALL} ${A}"
			if [ -n "${POPT}" ]; then echo "   <options> ${PKGO}"; fi
			;;
		"required")
			echo " [r] Required upgrade for ${A}"
			REPLACE="${A} ${REPLACE}"
			if [ -n "${POPT}" ]; then echo "   <options> ${PKGO}"; fi
			;;
		"missing")
			echo " [i] Enqueueing for install ${A}"
			INSTALL="${INSTALL} ${A}"
			if [ -n "${POPT}" ]; then echo "   <options> ${PKGO}" ; fi
			;;
		*)
			if [ -n "`echo ${CHK}| grep from`" ]; then
				echo " [u] Need to update ${A} ${CHK}"
				if [ ! "${POPT}" = "" ]; then
					echo "   <options> ${PKGO}"
				fi
				if [ "${UPD}" = "1" ]; then
					REPLACE="${REPLACE} ${A}"
				else
					if [ "${A}" = "${DIR}" ]; then
						REPLACE="${REPLACE} ${A}"
					fi
				fi
			fi
			;;
		esac
		# Add new deps
		cd ${PKGSRC_DIR}/${A}
		if [ "${SKIP_LICENSES}" = "1" ]; then
		ACCEPTABLE_LICENSES="`cat Makefile | grep LICENSE \
			| awk -F = '{ print $2 }' | awk '{ print $1 }'`"
		if [ -n "${ACCEPTABLE_LICENSES}" ]; then
			MAKEFLAG="${MAKEFLAG} \
			ACCEPTABLE_LICENSES=${ACCEPTABLE_LICENSES}"
			echo "==> Skipping license: ${ACCEPTABLE_LICENSES}"
			fi
		fi
		DEPS2=`${MAKE} ${MAKEFLAG} show-depends-dirs`
		for B in ${DEPS2} ; do
			if [ "`echo ${DEPS} | grep ${B}`" = "" ]; then
				DEPS="${DEPS} ${B}"
			fi
		done
	done
	fi

	press_any_key

	# required install
	if [ -n "${PREINSTALL}" ]; then
	for A in ${PREINSTALL}; do
		echo "==> Preinstalling ${A}"
		cd ${PKGSRC_DIR}/${A}
		${MAKE} ${MAKEFLAG} fetch
		do_make_clean
		${MAKE} ${MAKEFLAG} install ${UD_TARGETS} | ${WRAPPER} 2>&1
		do_make_package
		do_make_clean
		if [ ! "$?" = "0" ]; then
			echo "==> Error occurred at ${DIR}."
			process_failed
		else
			echo "==> Process finished."
		fi
	done
	fi

	# replace list
	if [ -n "${REPLACE}" ]; then
	for A in ${REPLACE}; do
		echo "==> Upgrading ${A}..."
		cd ${PKGSRC_DIR}/${A}
		${MAKE} ${MAKEFLAG} fetch
		do_make_clean
		${MAKE} ${MAKEFLAG} replace ${UD_TARGETS} | ${WRAPPER} 2>&1
		do_make_package
		do_make_clean
		if [ ! "$?" = "0" ]; then
			echo "==> Error occurred at ${DIR}."
			process_failed
		else
			echo "==> Process finished."
			do_auto_relink ${A}
		fi
	done
	fi

	# install list
	if [ -n "${INSTALL}" ]; then
	for A in ${INSTALL}; do
		echo "==> Installing ${A}"
		cd ${PKGSRC_DIR}/${A}
		${MAKE} ${MAKEFLAG} fetch
		do_make_clean
		${MAKE} ${MAKEFLAG} install ${UD_TARGETS} | ${WRAPPER} 2>&1
		do_make_package
		do_make_clean
		if [ ! "$?" = "0" ]; then
			echo "==> Error occurred at ${DIR}."
			process_failed
		else
			echo "==> Process finished."
		fi
	done
	fi

	fi # check installed
}

do_remove() {
	PKG=$1
	DIR=$1
	if [ "`echo $PKG | grep /`" = "" ]; then
		DIR=`${PKGFIND} -qx $PKG`
	else
		PKG=`echo $PKG | awk -F / '{ print $2 }'`
	fi

	FOUND="`pkg_info ${PKG} 2>/dev/null`"
	if [ "${FOUND}" = "" ]; then
	echo "==> Package $PKG not installed."
	else
		LIST="`pkg_delete -n ${PKG}`"
		DEIN="`echo ${LIST} | grep DEINSTALL`"

		pkg_delete -n ${PKG} | grep -v DEINSTALL | grep delete
		echo ""
		if [ ! "${DEIN}" = "" ]; then
		echo "==> Use 'pkg_info -k ${PKG} | more' to see the DEINSTALL script"
		fi

		press_any_key

		echo "==> Performing remove for $PKG..."
		pkg_delete "${PKG}"
	fi
}

do_update() {
	PKS=""
	WIP=""
	for A in $1 $2 ; do
		case $A in
		"pkgsrc") PKS="1";;
		"wip")    WIP="1";;
		esac
	done
	if [ "${PKS}${WIP}" = "" ]; then
		PKS="1"
		WIP="1"
	fi

	if [ "$PKS" = "1" ]; then
		CMD="${UPDATE_METHOD} ${UPDATE_ARGS}"
		echo "==> Updating pkgsrc tree using ${CMD}..."
		cd ${PKGSRC_DIR}
		if [ "${UPDATE_METHOD}" = "cvs" ]; then
			cvs ${UPDATE_ARGS} -q update -dP
		else
			${UPDATE_METHOD} ${UPDATE_ARGS}
		fi
	fi

	if [ "$WIP" = "1" ]; then
		if [ -e "${PKGSRC_DIR}/wip" ]; then
		echo "==> Updating pkgsrc-wip tree..."
		cd ${PKGSRC_DIR}/wip
		cvs -z 3 -q update -dP
		fi
	fi
}

do_clean() {
	WRKOBJDIR="`grep -e WRKOBJDIR /etc/mk.conf|awk -F = '{ print $2; }'`"
	if [ -z "${WRKOBJDIR}" ]; then
		echo "==> WRKOBJDIR not defined in mk.conf"
		cd ${PKGSRC_DIR}
		printf "==> Scanning pkgsrc tree for dirty dirs... "
	PKGTOCLEAN=`find . | grep work | awk -F / '{print $2"/"$3; }'|uniq`
		echo "DONE"
	else
		echo "Using WRKOBJDIR=${WRKOBJDIR}"
		cd ${WRKOBJDIR}
		PKGTOCLEAN=`echo */*`;
	fi

	echo "==> Cleaning all dirty builds..."
	for A in ${PKGTOCLEAN} ; do
		if [ ! -e ${PKGSRC_DIR}/${A} ]; then continue ; fi
		cd ${PKGSRC_DIR}/${A}
		printf "${A}   "
		${MAKE} clean > /dev/null 2>&1
		echo "OK"
	done
	echo "DONE"

}

do_whereis() {
	keyword=$1

	cd ${PKG_DBDIR}
	for A in * ; do 
		for B in `pkg_info -L $A 2>/dev/null`; do
			case $B in
			*${keyword}*)
				echo $A : $B
				;;
			esac
		done
	done
}

# Main procedure

case "$1" in
"")
	do_usage $0
	;;
"install"|"upgrade")
	FLAG=0
	if [ "${2}" = "" ]; then
		echo "You must give me at least one package"
		exit 1
	fi
	if [ "$1" = "upgrade" ]; then
		FLAG=1
	fi
	while : ; do
		do_install $2 ${FLAG}
		shift
		if [ "$2" = "" ]; then
		break;
		fi
	done
	;;
"whereis")
	if [ -z "${2}" ]; then
		echo "You must give me something to find"
		exit 1
	fi
	do_whereis ${2}
	;;
"remove")
	if [ "${2}" = "" ]; then
		echo "You must give me at least one package"
		exit 1
	fi
	while : ; do
		do_remove $2
		shift;
		if [ "$2" = "" ]; then
		break;
		fi
	done
	;;
"update")
	do_update $1 $2
	;;
"dist-upgrade")
	echo "==> Generating the update list..."
	LIST=`${PKGCHK} -i`

	if [ "$?" = "1" ]; then
		echo ""
		echo "WARNING: Your pkgsrc seems to be broken."
		echo "WARNING: Please check this manually."
		echo "WARNING: Not all packages will be showed here :("
		echo ""
	fi

	NAME=""
	OLDNAME=""
	LIST2=""
	for A in ${LIST}; do
		NAME=`echo ${A} | awk -F '([.\-]*)-[0-9]' '{print $1 }'`
		case ${NAME} in
		"version"|"mismatch"|"-"|"(binary"|"available)"|"package") 
			NAME="" ; ;;
		*)

		if [ "${NAME}" = "${OLDNAME}" ]; then
			LIST2="${LIST2} ${NAME}"
			NAME=""
		fi
		OLDNAME=${NAME}
		;;
		esac
	done
	LIST=${LIST2}

	if [ "${LIST}" = "" ]; then
		echo "Your system is completely updated"
	else
		echo "Upgrade list:"
		echo ${LIST}

		press_any_key

		for A in ${LIST}; do
			echo "==> Updating ${A}..."
			do_install ${A} 1
		done
	fi
	;;
"clean")
	if [ "$2" = "" ]; then
		do_clean
	else
		while : ; do
		PKG=$2
		if [ "`echo $PKG | grep /`" = "" ]; then
			DIR=`${PKGFIND} -qx $PKG`
			if [ "${DIR}" = "" ]; then
				DIR=NOTFOUND
			fi
		else
			PKG=`echo $PKG | awk -F / '{ print $2 }'`
		fi
		if [ -d "${PKGSRC_DIR}/${DIR}" ]; then
			cd ${PKGSRC_DIR}/${DIR}
			${MAKE} clean
		else
			echo "Directory for $2 not found."
		fi
		# next one
		shift;
		if [ "$2" = "" ]; then break; fi
		done
	fi
	;;
"autoclean")
	lintpkgsrc -r
	;;
"relink")
	while : ; do
		do_relink $2
		shift;
		if [ "$2" = "" ]; then break; fi
	done
	;;
"orphan")
	PKG=`pkg_info -a| awk '{ print $1 }' | grep -e lib `
	for A in $PKG ; do
		COW=`pkg_delete -nRr ${A}| grep deinstalling`
		if [ "${COW}" = "" ]; then
			echo $A
		fi
	done
	;;
"show")
	PKG=$2
	DIR=$2
	if [ "`echo $PKG | grep /`" = "" ]; then
		DIR=`${PKGFIND} -qx $PKG`
		if [ "${DIR}" = "" ]; then
			echo "Package $1 not found."
			exit 1
		fi
	fi

	if [ ! -d "${PKGSRC_DIR}/${DIR}" ]; then
		echo "Package ${PKGSRC_DIR}/${DIR} does not exist."
		exit 1
	fi

	cd ${PKGSRC_DIR}/${DIR}
	PKGNAM=`${MAKE} show-var VARNAME=PKGNAME`
	PKGOPT=`${MAKE} show-var VARNAME=PKG_SUPPORTED_OPTIONS`
	HOMEPAGE=`${MAKE} show-var VARNAME=HOMEPAGE`
	COMMENT=`${MAKE} show-var VARNAME=COMMENT`
	PKGDEP=`${MAKE} show-depends-dirs`
	echo ">> PKGNAME: ${PKGNAM}"
	echo ">> HOMEPAGE: ${HOMEPAGE}"
	echo ">> COMMENT: ${COMMENT}"
	if [ ! "${PKGOPT}" = "" ]; then
	echo ">> OPTIONS: ${PKGOPT}"
	fi
	echo ">> DESCRIPTION:"
	cat DESCR
	;;
"check")
	if [ "${2}" = "" ]; then # Check ALL packages
		echo "==> Checking all packages..."
		pkg_admin check | grep failed
	else
	while : ; do
		echo "==> Checking md5 of $2"
		pkg_admin check $2 | grep failed
		shift;
		if [ "$2" = "" ]; then
		break;
		fi
	done
	fi
	;;
*)
	do_usage $0
	;;
esac