2021-04-22 11:06:27 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-04-22 11:11:46 +02:00
|
|
|
source /etc/de-p1st-repo/arch-repo.cfg || exit
|
2021-04-22 11:06:27 +02:00
|
|
|
|
|
|
|
|
2021-04-22 11:24:04 +02:00
|
|
|
|
2021-04-22 11:06:27 +02:00
|
|
|
#
|
|
|
|
# add new packages to database
|
|
|
|
#
|
|
|
|
function add_to_db(){
|
2021-04-22 11:24:04 +02:00
|
|
|
echo "Adding new packages to db ..."
|
|
|
|
|
2021-04-25 15:22:27 +02:00
|
|
|
sort_pkgname_pkgver || return $?
|
|
|
|
|
|
|
|
echo "For each package: Add latest version to database ..."
|
2021-04-25 17:45:53 +02:00
|
|
|
for PKGNAME in db/*; do
|
|
|
|
PKGNAME=$(basename "${PKGNAME}") # strip directory and suffix from filename
|
|
|
|
|
|
|
|
# TODO
|
|
|
|
# db/* -> results in filenames db/FILE1
|
|
|
|
# => remove prefix "db/" to get FILE1
|
|
|
|
# e.g. use filename / basename (!)
|
2021-04-25 15:22:27 +02:00
|
|
|
|
|
|
|
#
|
2021-04-25 15:30:41 +02:00
|
|
|
# get latest version for $PKGNAME
|
2021-04-25 15:22:27 +02:00
|
|
|
#
|
|
|
|
|
|
|
|
local LATEST
|
2021-04-25 15:30:41 +02:00
|
|
|
# pick one random version as starting point for the latest version
|
2021-04-25 17:45:53 +02:00
|
|
|
for PKGVER in db/"${PKGNAME}"/*; do
|
|
|
|
PKGVER=$(basename "${PKGVER}") # strip directory and suffix from filename
|
2021-04-25 15:22:27 +02:00
|
|
|
LATEST="$PKGVER"
|
|
|
|
break
|
|
|
|
done
|
|
|
|
|
|
|
|
local cmp
|
2021-04-25 17:45:53 +02:00
|
|
|
for PKGVER in db/"$PKGNAME"/*; do
|
|
|
|
PKGVER=$(basename "${PKGVER}") # strip directory and suffix from filename
|
|
|
|
|
2021-04-25 15:22:27 +02:00
|
|
|
# compare the currently known latest version
|
|
|
|
# with the next version
|
|
|
|
cmp=$(vercmp "$LATEST" "$PKGVER") || return $?
|
|
|
|
# if the new version is larger, save it as LATEST
|
|
|
|
if [ "$cmp" -lt "0" ]; then
|
|
|
|
LATEST="$PKGVER"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
#
|
|
|
|
# add latest version of PKGNAME to database
|
|
|
|
#
|
2021-04-25 17:45:53 +02:00
|
|
|
PKG=$(cat "db/${PKGNAME}/${LATEST}") || return $?
|
2021-04-25 15:30:41 +02:00
|
|
|
repo-add --new "${REMOTE_DB_NAME}.db.tar.gz" "${PKG}" || return $?
|
2021-04-25 15:22:27 +02:00
|
|
|
|
|
|
|
true
|
2021-04-22 11:06:27 +02:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-25 15:22:27 +02:00
|
|
|
#
|
2021-04-25 15:30:41 +02:00
|
|
|
# create files "./db/$pkgname/$pkgver" with content "$path_to_file" = "$PKG"
|
2021-04-25 15:22:27 +02:00
|
|
|
#
|
|
|
|
function sort_pkgname_pkgver(){
|
|
|
|
echo "Sorting packages by package name and package version ..."
|
|
|
|
|
2021-04-25 17:45:53 +02:00
|
|
|
for PKG in *.pkg.tar.{xz,zst}; do
|
2021-04-25 16:01:31 +02:00
|
|
|
get_pkginfo "$PKG" || { echo "get_pkginfo failed"; return 1; }
|
2021-04-25 16:29:06 +02:00
|
|
|
get_pkgname "$PKGINFO" || { echo "get_pkgname failed"; echo "Content of PKGINFO: ${PKGINFO}"; return 1; }
|
|
|
|
get_pkgver "$PKGINFO" || { echo "get_pkgver failed"; echo "Content of PKGINFO: ${PKGINFO}"; return 1; }
|
2021-04-25 15:22:27 +02:00
|
|
|
|
2021-04-25 20:11:13 +02:00
|
|
|
echo "Creating file ./db/${PKGNAME}/${PKGVER} with content ${PKG} ..."
|
2021-04-25 15:30:41 +02:00
|
|
|
mkdir -p "db/${PKGNAME}" || return $?
|
|
|
|
echo "${PKG}" > "db/${PKGNAME}/${PKGVER}" || return $?
|
2021-04-25 15:22:27 +02:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# get .PKGINFO
|
|
|
|
#
|
|
|
|
function get_pkginfo(){
|
|
|
|
# $1: path to package file
|
|
|
|
# return: 0 on success
|
|
|
|
|
|
|
|
if endswith "$1" ".pkg.tar.xz"; then
|
2021-04-25 18:06:00 +02:00
|
|
|
PKGINFO=$(tar -xf "$1" -O .PKGINFO --force-local) || { echo "tar failed"; return 1; }
|
2021-04-25 15:22:27 +02:00
|
|
|
elif endswith "$1" ".pkg.tar.zst"; then
|
2021-04-25 18:06:00 +02:00
|
|
|
PKGINFO=$(tar -I zstd -xf "$1" -O .PKGINFO --force-local) || { echo "tar failed"; return 1; }
|
2021-04-25 15:22:27 +02:00
|
|
|
else
|
2021-04-25 15:57:10 +02:00
|
|
|
echo "$1 does not seem to be a package!"
|
2021-04-25 15:22:27 +02:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#
|
2021-04-25 16:29:06 +02:00
|
|
|
# get pkgname from $PKGINFO
|
2021-04-25 15:22:27 +02:00
|
|
|
#
|
|
|
|
function get_pkgname(){
|
2021-04-25 16:37:01 +02:00
|
|
|
# return: 0 on success; variable $PKGNAME
|
2021-04-25 15:22:27 +02:00
|
|
|
|
|
|
|
# remove "pkgname = " as well as tailing whitespace characters
|
|
|
|
local tmp
|
2021-04-25 16:33:25 +02:00
|
|
|
tmp=$(echo "${PKGINFO}" | grep '^pkgname') || { echo "grep failed"; return 1; }
|
2021-04-25 16:37:01 +02:00
|
|
|
PKGNAME=$(echo "${tmp}" | sed 's|^pkgname\s*=\s*||; s|\s*$||') || { echo "sed failed"; return 1; }
|
2021-04-25 15:22:27 +02:00
|
|
|
}
|
2021-04-25 16:29:06 +02:00
|
|
|
#
|
|
|
|
# get pkgver from $PKGINFO
|
|
|
|
#
|
|
|
|
function get_pkgver(){
|
2021-04-25 16:37:01 +02:00
|
|
|
# return: 0 on success; variable $PKGVER
|
2021-04-25 16:29:06 +02:00
|
|
|
|
|
|
|
# remove "pkgver = " as well as tailing whitespace characters
|
|
|
|
local tmp
|
2021-04-25 16:31:34 +02:00
|
|
|
tmp=$(echo "${PKGINFO}" | grep '^pkgver') || { echo "grep failed"; return 1; }
|
|
|
|
PKGVER=$(echo "${tmp}" | sed 's|^pkgver\s*=\s*||; s|\s*$||') || { echo "sed failed"; return 1; }
|
2021-04-25 16:29:06 +02:00
|
|
|
}
|
2021-04-25 15:22:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Inspired by: https://stackoverflow.com/questions/2172352/in-bash-how-can-i-check-if-a-string-begins-with-some-value/18558871#18558871
|
|
|
|
#
|
|
|
|
# $1 begins with $2
|
|
|
|
#
|
|
|
|
beginswith() { case $1 in "$2"*) true;; *) false;; esac; }
|
|
|
|
#
|
|
|
|
# $1 ends with $2
|
|
|
|
#
|
|
|
|
endswith() { case $1 in *"$2") true;; *) false;; esac; }
|
|
|
|
|
2021-04-22 11:24:04 +02:00
|
|
|
|
2021-04-22 11:06:27 +02:00
|
|
|
#
|
|
|
|
# generate index.html
|
|
|
|
#
|
|
|
|
function generate_index(){
|
2021-04-22 11:24:04 +02:00
|
|
|
echo "Generating index.html with links to all packages ..."
|
|
|
|
|
2021-04-22 11:06:27 +02:00
|
|
|
echo '<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>privacy1st.de Arch Packages</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h1>privacy1st.de Arch Packages</h1>
|
2021-04-22 11:46:18 +02:00
|
|
|
<p>The sources can be found here: <a href="https://git.privacy1st.de/langfingaz/arch-pkg">https://git.privacy1st.de/langfingaz/arch-pkg</a></p>
|
|
|
|
|
|
|
|
<ul>
|
2021-04-22 11:06:27 +02:00
|
|
|
' > index.html
|
|
|
|
|
2021-04-25 17:45:53 +02:00
|
|
|
for PKG in *.pkg.tar.{xz,zst}; do
|
2021-04-22 11:46:18 +02:00
|
|
|
echo "<li><a href=\"$PKG\">$PKG</a></li>" >> index.html;
|
2021-04-22 11:06:27 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
echo '
|
2021-04-22 11:46:18 +02:00
|
|
|
</ul>
|
|
|
|
|
2021-04-22 11:06:27 +02:00
|
|
|
</body>
|
|
|
|
</html>' >> index.html
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-22 11:24:04 +02:00
|
|
|
|
2021-04-22 11:06:27 +02:00
|
|
|
cd "${REMOTE_PKG_DIR}" || exit
|
2021-04-25 15:22:27 +02:00
|
|
|
add_to_db || exit
|
|
|
|
generate_index || exit
|