-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patham-apt-update
executable file
·59 lines (57 loc) · 1.8 KB
/
am-apt-update
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
#!/bin/bash
set -o errexit # -e, exit if error occurs
set -o nounset # -u, treat unset variables and parameters as an error
set -o pipefail # fail if pipe failed
# set -x
#
_curl () {
set +o nounset
if [ -n "${3}" ]; then echo "Getting - ${3}"; fi
set -o nounset
set +o errexit
curl -sL -f -o "${2}" "${1}"
_curlError="$?"
set -o errexit
if [ "${_curlError}" -ne 0 ]; then
echo "Curl Error - ${3:-${1}}"
fi
}
#
get_distros () {
_distros=$( curl -sL "https://github.com/forwardcomputers/forwardcomputers.github.io/raw/main/distros.json" )
}
#
get_packages () {
_apt="${GITHUB_WORKSPACE}/apt"
_tmp="${GITHUB_WORKSPACE}/tmp_apt"
mkdir -p "${_tmp}" "${_apt}"
pushd "${_apt}" >/dev/null
rm -rf "${_tmp}"/*
touch apt.json
for i in $( jq -r '. | select( .distro=="apt" ).name' <<< "${_distros}" ); do
_old_version=$( jq -r --arg _name "${i}" '. | select ( .name==$_name ).version' apt.json )
if [ -z "${_old_version}" ]; then
jq -c -n --arg _name "${i}" '{name: $_name, version: "0.0"}' >> apt.json
_old_version="0.0"
fi
_new_version=$( jq -r --arg _name "${i}" '. | select( .distro=="apt" and .name==$_name ).version' <<< $_distros )
if [ -z "${_new_version##[0-9]*}" ]; then
if [ "${_new_version}" != "${_old_version}" ]; then
_curl $( jq -r --arg _name "${i}" '. | select( .distro=="apt" and .name==$_name ).url' <<< $_distros ) "${_tmp}/${i}.deb" "${i} ${_new_version}"
chmod -R u+rwx,go+rx,go-w "${_tmp}"/*
rm -rf "${i}.deb"
mv -f "${_tmp}"/* .
jq -r -c --arg _name "${i}" --arg _version "${_new_version}" '. | select ( .name==$_name ).version=$_version' apt.json > apt.json~
mv -f apt.json~ apt.json
dpkg-scanpackages -m . > Packages
fi
else
echo "Error - ${i} ${_new_version}"
fi
done
popd >/dev/null
rm -rf "${_tmp}"
}
#
get_distros
get_packages