-
Notifications
You must be signed in to change notification settings - Fork 192
/
download
executable file
·48 lines (39 loc) · 1023 Bytes
/
download
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
#!/bin/bash
cd "$(dirname "$0")"
die() {
echo >&2 $1
exit 1
}
usage() {
echo >&2 "Usage: $0 id"
exit 2
}
download_single() {
local id=$1
echo "Getting $id"
if [ -d "libs/$id" ]; then
die " --> Downloaded before. Remove it to download again."
fi
if [ ! -f "db/$1.url" ]; then
die "Invalid ID, maybe the library was fetched in an older version or added manually?"
fi
local url="$(cat "db/$1.url")"
echo " -> Location: $url"
local tmp=`mktemp -d`
echo " -> Downloading package"
wget "$url" 2>/dev/null -O $tmp/pkg.deb || die "Failed to download package from $url"
echo " -> Extracting package"
pushd $tmp 1>/dev/null
ar x pkg.deb || die "ar failed"
tar xf data.tar.* || die "tar failed"
popd 1>/dev/null
mkdir libs/$id
cp $tmp/lib/*/* libs/$id 2>/dev/null || cp $tmp/lib32/* libs/$id 2>/dev/null \
|| die "Failed to save. Check it manually $tmp"
echo " -> Package saved to libs/$id"
rm -rf $tmp
}
if [[ $# != 1 ]]; then
usage
fi
download_single "$1"