forked from bitnami/minideb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnapshot_id
executable file
·39 lines (25 loc) · 1.21 KB
/
snapshot_id
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
#!/bin/bash
set -e
set -u
set -o pipefail
snapshot_tmp_dir=$(mktemp -d)
mkdir -p "${snapshot_tmp_dir}"
get_latest_month_query() {
local -r snapshot_archive_tmp_file="${snapshot_tmp_dir}/archive.html"
curl -sSfL "https://snapshot.debian.org/archive/debian/" > "$snapshot_archive_tmp_file"
local -r month_query_regex="(\?year=\d\d\d\d&month=\d+)"
local -r month_query=$(grep -Po "${month_query_regex}" "${snapshot_archive_tmp_file}" | tail -1)
[[ -z "$month_query" ]] && echo "Not found snapshots using the following regex: ${month_query_regex}" && return 1
echo "$month_query"
}
get_latest_debian_snapshot_id() {
local -r snapshot_list_tmp_file="${snapshot_tmp_dir}/month-snapshots.html"
! month_query=$(get_latest_month_query) && return 1
curl -sSfL "https://snapshot.debian.org/archive/debian/$month_query" > "$snapshot_list_tmp_file"
local -r snapshot_id_regex="(\d+T.*Z)"
local -r snapshot_id=$(grep -Po "${snapshot_id_regex}" "${snapshot_list_tmp_file}" | tail -1)
[[ -z "$snapshot_id" ]] && echo "Not found snapshot id using the following regex: ${snapshot_id_regex}" && return 1
echo "$snapshot_id"
}
get_latest_debian_snapshot_id
rm -rf "${snapshot_tmp_dir}"