-
Notifications
You must be signed in to change notification settings - Fork 1
/
eol-infos.sh
executable file
·139 lines (120 loc) · 5.15 KB
/
eol-infos.sh
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/bash
set -e
# Colorize terminal
COLOR_OFF='\033[0m'
COLOR_BLUE='\033[0;34m'
COLOR_RED='\033[0;31m'
COLOR_GREEN='\033[0;32m'
COLOR_YELLOW='\033[0;33m'
# Declare script helper
TEXT_HELPER="\nThis script aims to perform a EOL search for a given package.
Following flags are available:
-b Enable boolean mode to print 'true' when the package version is the LTS version, otherwise print 'false'.
-p Package name to perform EOL search.
-s Enable search mode to find a package.
-v Package version (cycle) to perform EOL search.
-h Print script help.\n\n"
print_help() {
printf "$TEXT_HELPER"
}
# Parse options
while getopts hbp:sv: flag; do
case "${flag}" in
b)
BOOLEAN_MODE="true";;
p)
PACKAGE_NAME=${OPTARG};;
s)
SEARCH_MODE="true";;
v)
PACKAGE_VERSION=${OPTARG};;
h | *)
print_help
exit 0;;
esac
done
# Functions
check_status() {
if [ "$(curl -o /dev/null -sL -w "%{http_code}" "https://endoflife.date/api/$PACKAGE_NAME.json")" -eq 404 ]; then
echo "Package $PACKAGE_NAME not found.\n"
exit 1
fi
}
if [ "$SEARCH_MODE" = "true" ]; then
EOL_INFOS=$(curl -sL --request GET \
--url https://endoflife.date/api/all.json \
--header 'Accept: application/json')
printf "End of life search results for package: ${COLOR_BLUE}$PACKAGE_NAME${COLOR_OFF}\n\n"
for PKG in $(echo $EOL_INFOS | jq -r --arg p "$PACKAGE_NAME" '.[] | select(test($p; "i"))'); do
printf "$PKG\n" | sed 's/^/ /'
done
elif [ -n "$PACKAGE_VERSION" ]; then
check_status
EOL_INFOS=$(curl -sL --request GET \
--url https://endoflife.date/api/$PACKAGE_NAME/$PACKAGE_VERSION.json \
--header 'Accept: application/json')
if [ "$BOOLEAN_MODE" = "true" ]; then
[[ $(echo $EOL_INFOS | jq -r '.support') > $(date '+%Y-%m-%d') ]] && echo "true" || echo "false"
else
printf "End of life infos for package: ${COLOR_BLUE}$PACKAGE_NAME (v$PACKAGE_VERSION)${COLOR_OFF} - https://endoflife.date/$PACKAGE_NAME\n
Latest version: $(echo $EOL_INFOS | jq -r '.latest') ($(echo $EOL_INFOS | jq -r '.latestReleaseDate'))
Release date: $(if ! [[ "$(echo $EOL_INFOS | jq -r '.releaseDate | select (.!=null)')" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
echo "-";
else
echo "$(echo $EOL_INFOS | jq -r '.releaseDate')";
fi)
Start of LTS: $(if ! [[ "$(echo $EOL_INFOS | jq -r '.lts | select (.!=null)')" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
echo "-";
else
echo "$(echo $EOL_INFOS | jq -r '.lts')";
fi)
End of LTS: $(if ! [[ "$(echo $EOL_INFOS | jq -r '.support | select (.!=null)')" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
echo "-";
elif [[ $(echo $EOL_INFOS | jq -r '.support') > $(date '+%Y-%m-%d') ]]; then
echo "${COLOR_GREEN}$(echo $EOL_INFOS | jq -r '.support')${COLOR_OFF}";
elif [[ $(echo $EOL_INFOS | jq -r '.support') < $(date '+%Y-%m-%d') ]]; then
echo "${COLOR_RED}$(echo $EOL_INFOS | jq -r '.support')${COLOR_OFF}";
fi)
EOL: $(if ! [[ "$(echo $EOL_INFOS | jq -r '.eol | select (.!=null)')" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
echo "-";
elif [[ $(echo $EOL_INFOS | jq -r '.eol') > $(date '+%Y-%m-%d') ]]; then
echo "${COLOR_GREEN}$(echo $EOL_INFOS | jq -r '.eol')${COLOR_OFF}";
elif [[ $(echo $EOL_INFOS | jq -r '.eol') < $(date '+%Y-%m-%d') ]]; then
echo "${COLOR_RED}$(echo $EOL_INFOS | jq -r '.eol')${COLOR_OFF}";
fi)\n"
fi
else
check_status
EOL_INFOS=$(curl -sL --request GET \
--url https://endoflife.date/api/$PACKAGE_NAME.json \
--header 'Accept: application/json')
printf "End of life infos for package: ${COLOR_BLUE}$PACKAGE_NAME${COLOR_OFF} - https://endoflife.date/$PACKAGE_NAME\n"
for EOL_CYCLE in $(echo "$EOL_INFOS" | jq -c '. | reverse | .[]'); do
printf "
Latest version: $(echo $EOL_CYCLE | jq -r '.latest') ($(echo $EOL_CYCLE | jq -r '.latestReleaseDate'))
Release date: $(if ! [[ "$(echo $EOL_CYCLE | jq -r '.releaseDate | select (.!=null)')" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
echo "-";
else
echo "$(echo $EOL_CYCLE | jq -r '.releaseDate')";
fi)
Start of LTS: $(if ! [[ "$(echo $EOL_CYCLE | jq -r '.lts | select (.!=null)')" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
echo "-";
else
echo "$(echo $EOL_CYCLE | jq -r '.lts')";
fi)
End of LTS: $(if ! [[ "$(echo $EOL_CYCLE | jq -r '.support | select (.!=null)')" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
echo "-";
elif [[ $(echo $EOL_CYCLE | jq -r '.support') > $(date '+%Y-%m-%d') ]]; then
echo "${COLOR_GREEN}$(echo $EOL_CYCLE | jq -r '.support')${COLOR_OFF}";
elif [[ $(echo $EOL_CYCLE | jq -r '.support') < $(date '+%Y-%m-%d') ]]; then
echo "${COLOR_RED}$(echo $EOL_CYCLE | jq -r '.support')${COLOR_OFF}";
fi)
EOL: $(if ! [[ "$(echo $EOL_CYCLE | jq -r '.eol | select (.!=null)')" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
echo "-";
elif [[ $(echo $EOL_CYCLE | jq -r '.eol') > $(date '+%Y-%m-%d') ]]; then
echo "${COLOR_GREEN}$(echo $EOL_CYCLE | jq -r '.eol')${COLOR_OFF}";
elif [[ $(echo $EOL_CYCLE | jq -r '.eol') < $(date '+%Y-%m-%d') ]]; then
echo "${COLOR_RED}$(echo $EOL_CYCLE | jq -r '.eol')${COLOR_OFF}";
fi)\n"
done
fi