Welcome to mirror list, hosted at ThFree Co, Russian Federation.

version.sh « Scripts « advanced - github.com/pi-hole/pi-hole.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 271665071b1be0c276fc99b7903589d59b4fcc94 (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env bash
# Pi-hole: A black hole for Internet advertisements
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
# Network-wide ad blocking via your own hardware.
#
# shows version numbers
#
# This file is copyright under the latest version of the EUPL.
# Please see LICENSE file for your rights under this license.



# Flags:
latest=false
current=false

DEFAULT="-1"

normalOutput() {
	piholeVersion=$(cd /etc/.pihole/ \
	                && git describe --tags --abbrev=0)
	webVersion=$(cd /var/www/html/admin/ \
	             && git describe --tags --abbrev=0)

	piholeHash=$(cd /etc/.pihole/ \
	             && git rev-parse --short HEAD)
	webHash=$(cd /var/www/html/admin/ \
	          && git rev-parse --short HEAD)

	piholeVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | \
	                      grep -Po '"tag_name":.*?[^\\]",' | \
	                      perl -pe 's/"tag_name": "//; s/^"//; s/",$//')
	webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | \
	                   grep -Po '"tag_name":.*?[^\\]",' | \
	                   perl -pe 's/"tag_name": "//; s/^"//; s/",$//')

  piholeHashLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/commits/master | \
                     grep sha | \
                     head -n1 | \
                     awk -F ' ' '{ print $2}' | \
                     tr -cd '[[:alnum:]]._-')

  piholeHashLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/commits/master | \
                     grep sha | \
                     head -n1 | \
                     awk -F ' ' '{ print $2}' | \
                     tr -cd '[[:alnum:]]._-')

	echo "::: Pi-hole version is ${piholeVersion} (Latest version is ${piholeVersionLatest:-${DEFAULT}})"
	echo "::: Web-Admin version is ${webVersion} (Latest version is ${webVersionLatest:-${DEFAULT}})"
}

webOutput() {
	for var in "$@"; do
		case "${var}" in
			"-l" | "--latest"    ) latest=true;;
			"-c" | "--current"   ) current=true;;
			*                    ) echo "::: Invalid Option!"; exit 1;
		esac
	done

	if [[ "${latest}" == true && "${current}" == false ]]; then
		webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | grep -Po '"tag_name":.*?[^\\]",' |  perl -pe 's/"tag_name": "//; s/^"//; s/",$//')
		echo "${webVersionLatest:--1}"
	elif [[ "${latest}" == false && "${current}" == true ]]; then
		webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0)
		echo "${webVersion}"
	else
		webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0)
		webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | grep -Po '"tag_name":.*?[^\\]",' |  perl -pe 's/"tag_name": "//; s/^"//; s/",$//')
		echo "::: Web-Admin version is ${webVersion} (Latest version is ${webVersionLatest:-${DEFAULT}})"
	fi
}

coreOutput() {
	for var in "$@"; do
		case "${var}" in
			"-l" | "--latest"    ) latest=true;;
			"-c" | "--current"   ) current=true;;
			*                    ) echo "::: Invalid Option!"; exit 1;
		esac
	done

	if [[ "${latest}" == true && "${current}" == false ]]; then
		piholeVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | grep -Po '"tag_name":.*?[^\\]",' |  perl -pe 's/"tag_name": "//; s/^"//; s/",$//')
		echo "${piholeVersionLatest:--1}"
	elif [[ "${latest}" == false && "${current}" == true ]]; then
		piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0)
		echo "${piholeVersion}"
	else
		piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0)
		piholeVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | grep -Po '"tag_name":.*?[^\\]",' |  perl -pe 's/"tag_name": "//; s/^"//; s/",$//')
		echo "::: Pi-hole version is ${piholeVersion} (Latest version is ${piholeVersionLatest:-${DEFAULT}})"
	fi
}

helpFunc() {
	cat << EOM
:::
::: Show Pi-hole/Web Admin versions
:::
::: Usage: pihole -v [ -a | -p ] [ -l | -c ]
:::
::: Options:
:::  -a, --admin          Show both current and latest versions of web admin
:::  -p, --pihole         Show both current and latest versions of Pi-hole core files
:::  -l, --latest         (Only after -a | -p) Return only latest version
:::  -c, --current        (Only after -a | -p) Return only current version
:::  -h, --help           Show this help dialog
:::
EOM
	exit 0
}

if [[ $# = 0 ]]; then
	normalOutput
fi

for var in "$@"; do
	case "${var}" in
	"-a" | "--admin"     ) shift; webOutput "$@";;
	"-p" | "--pihole"    ) shift; coreOutput "$@" ;;
	"-h" | "--help"      ) helpFunc;;
	esac
done