aboutsummaryrefslogtreecommitdiff
path: root/upkg
blob: 342b396036829fa6900fe6c334b045a053bf79d1 (plain)
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
#!/bin/bash

if [ "$1" = "--help" ]; then
cat <<EOF
upkg - upgrade/install/reinstall a Slackware package.

Usage: upkg <package> [<package> ...]

<package> is an installable Slackware package (.tgz, etc).

If no <package> given, the .info and SlackBuild in the current directory
are parsed to get a package filename. If this package exists, it will
be installed.

Actual package installation is done with:

upgradepkg --reinstall --install-new <package>
EOF
exit 0
fi

die() {
	echo "$( basename $0 ): $@" 1>&2
	exit 1
}

OUTPUT=${OUTPUT:-/tmp}

if [ -z "$ARCH" ]; then
  case "$( uname -m )" in
    i?86) ARCH=i686 ;;
    arm*) ARCH=arm ;;
       *) ARCH=$( uname -m ) ;;
  esac
fi

case "$ARCH" in
  i?86) ARCHES="i686 i586 i486 i386" ;;
  *) ARCHES="$ARCH" ;;
esac

# if no package name, see if we're in a SlackBuild dir. if so,
# install the package for the current dir, if one exists in $OUTPUT.
# If PRINT_PACKAGE_NAME is found in the script, use it to get
# the package filename. Otherwise, read .info file for version number
# and extract BUILD from the SlackBuild.

if [ -z "$@" ]; then
	script="$( echo *.SlackBuild)"
	[ "$script" = '*.SlackBuild' ] && die "no .SlackBuild file in current dir"
	script1=$( echo *.SlackBuild | cut -d' ' -f1 )
	[ "$script" != "$script1" ] && die "multiple .SlackBuild files found in current dir"
	if grep -q PRINT_PACKAGE_NAME $script; then
		pkgfile="$( PRINT_PACKAGE_NAME=1 sh $script )"
		if [ -e "$OUTPUT/$pkgfile" ]; then
			found="$OUTPUT/$pkgfile"
		else
			die "No $pkgfile found in $OUTPUT, build one!"
		fi
	else
		infofile=$( echo *.info )

		[ "$infofile" = '*.info' ] && die "no .info file in current dir"

		infofile1=$( echo *.info | cut -d' ' -f1 )
		[ "$infofile" != "$infofile1" ] && die "multiple .info files found in current dir"

		pkgname=$(basename $infofile .info)
		[ ! -e "$pkgname.SlackBuild" ] && die "$pkgname.SlackBuild not found in current dir"

		source ./$pkgname.info
		[ -z "$PRGNAM" -o -z "$VERSION" ] && die "bad/incomplete .info file, bailing"

		[ "$PRGNAM" != "$pkgname" ] && die "bad PRGNAM=$PRGNAM in $pkgname.info"

		buildline=$(grep "^ *BUILD=" $pkgname.SlackBuild)
		[ -z "$buildline" ] && die "missing BUILD= in $pkgname.SlackBuild"

		eval $buildline

		for myarch in noarch $ARCHES; do
			myglob="$OUTPUT/$PRGNAM-$VERSION-$myarch-$BUILD*.t?z"
			myfile=$( echo $myglob )

			if [ "$myglob" = "$myfile" ]; then
				: # do naught
			elif [ "$( /bin/ls $myfile 2>/dev/null | wc -l )" -gt "1" ]; then
				die "Multiple packages match, not installing anything: $( /bin/ls $myfile )"
			else
				if [ -n "$found" ]; then
					die "Multiple packages/arches, not installing anything: $myfile $found"
				else
					found=$myfile
					echo found $found
				fi
			fi
		done
	fi

	[ -z "$found" ] && die "No $PRGNAM-$VERSION-(noarch|$ARCH)-$BUILD*.t?z package in $OUTPUT, build one!"

	set "$found"
fi

sudo /sbin/upgradepkg --reinstall --install-new "$@"