aboutsummaryrefslogtreecommitdiff
path: root/sbodl
blob: def7c7e1b17f2eb480d0f4d1d9ab5285e1debe00 (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
106
107
108
109
#!/bin/bash

# sbodl, initial public release.

# 20170306 bkw: add caching

SELF=$( basename $0 )

CACHEDIR=/home/urchlay/slackbuilds

usage() {
	cat <<EOF
$SELF - download the sources for a slackbuilds.org build.
version 20170306, public release, with cachedir
(c) 2014 B. Watson (yalhcru at gmail dawt cawm)
Licensed under the WTFPL: Do WTF you want with this.

Usage: $SELF [-f] <wget-options>

Execute $SELF in the directory that contains the .info and .SlackBuild
files. It will use wget to download the source file(s), then check their
md5sums.

$SELF options:

-h, --help: Show this help message.

-f: Ignore locally cached files, always download.

Any other options you pass to it will be passed to wget.
EOF
	exit 0
}

die() {
	echo "$SELF: $*" 2>&1
	exit 1
}

# check for our one argument
case "$1" in
	-h|-help|-\?|--help) usage ;;
	-f) FORCEDL="yes" ; shift ;;
esac

source ./$( basename $( pwd ) ).info \
	|| die "No .info file, are you sure this is a SBo directory? Try '$SELF --help'"

# This stanza copied from the SBo template for 14.1:
if [ -z "$ARCH" ]; then
  case "$( uname -m )" in
    i?86) ARCH=i586 ;;
    arm*) ARCH=arm ;;
       *) ARCH=$( uname -m ) ;;
  esac
fi

if [ "$ARCH" = "x86_64" ]; then
	DL=${DOWNLOAD_x86_64:-$DOWNLOAD}
	SUM=${MD5SUM_x86_64:-$MD5SUM}
else
	DL=$DOWNLOAD
	SUM=${MD5SUM}
fi

if [ -z "$DL" ]; then
	die "Bad .info file (no DOWNLOAD= or DOWNLOAD_x86_64=)."
fi

# save passed-in command line args for use with wget
WGETARGS="$@"

set $SUM

for dl in $DL; do
	EXTRAWGETARGS="--content-disposition "
	case "$dl" in
		*sourceforge.net/*|*.sf.net/*) EXTRAWGETARGS="--user-agent wget" ;;
		*) ;;
	esac

	FILE=$( echo "$dl" | sed 's,.*/,,' )
	[ "$FORCEDL" = "yes" ] && rm -f "$FILE"

	if [ -e "$FILE" ]; then
		# don't do anything
		:
	elif [ "$FORCEDL" != "yes" ] && [ -e "$CACHEDIR/$FILE" ]; then
		ln -s "$CACHEDIR/$FILE" "$FILE"
	else
		wget $WGETARGS $EXTRAWGETARGS "$dl" || die "Download failed"
		if [ -e "$FILE" ]; then
			mv -b "$FILE" "$CACHEDIR"
			ln -s "$CACHEDIR/$FILE" "$FILE"
		fi
	fi

	if [ -e "$FILE" ]; then
		GOTSUM="$( md5sum "$FILE" | cut -d' ' -f1 )"
		if [ "$1" != "$GOTSUM" ]; then
			echo "WARN: md5sum doesn't match, expected $1, got $GOTSUM"
		else
			echo "md5sum matches OK: $1"
		fi
	else
		echo "WARN: can't find downloaded file $FILE"
	fi
	shift
done