summaryrefslogtreecommitdiff
path: root/pkg-screenshot.sh
blob: d9f5f8c0e3c89dc45940996a4476d0e9f56b00a9 (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
#!/bin/sh

print_usage(){
	echo "Usage: pkg-screenshot.sh [options] package"
	echo ""
	echo " -h, --help     	give this help list"
	echo " --no-download		Open the image URL instead of saving an image file in /tmp/"
}

case $1 in
	-h|--help)
		print_usage
		;;

	--no-download)
		if [ -z $2 ]; then
			echo "Error: Missing package name"
			print_usage
		else
			URL=`wget -qO- https://screenshots.debian.net/json/package/$2 | jq '.screenshots[0].large_image_url' | tr -d \"`
			if [ -z $URL ]; then
				echo "Error: Package \"$2\" does not exist"
			elif [ $URL = "null" ]; then
				echo "Error: Package \"$2\" does not have any screenshots available"
			else
				xdg-open $URL
			fi
		fi
		;;

	*)
		if [ -z $1 ]; then
			echo "Error: Missing package name"
			print_usage
		else
			URL=`wget -qO- https://screenshots.debian.net/json/package/$1 | jq '.screenshots[0].large_image_url' | tr -d \"`
			if [ -z $URL ]; then
				echo "Error: Package \"$1\" does not exist"
			elif [ $URL = "null" ]; then
				echo "Error: Package \"$1\" does not have any screenshots available"
			else
				EXTENSION=`echo $URL | rev | cut -d . -f 1 | rev`
				wget -qO /tmp/pkg-screenshot.$EXTENSION $URL
				xdg-open /tmp/pkg-screenshot.$EXTENSION
			fi
		fi
		;;
esac