181 lines
4.7 KiB
Bash
181 lines
4.7 KiB
Bash
#!/bin/sh -e
|
|
|
|
# source this file and use these functions.
|
|
|
|
# getalpinepatches <tree>/<package> [timeout]
|
|
getalpinepatches() {
|
|
[ -n "$1" ] \
|
|
|| { echo "usage: $(basename $0) <package> [timeout]" && exit 0; }
|
|
|
|
[ "$1" != "-c" ] || { shift; cached="yes"; }
|
|
[ "$1" != "-r" ] || { shift; reparse="yes"; }
|
|
|
|
name="$1"
|
|
timeout=${2:-5}
|
|
|
|
cleanup() { [ -f "$temp" ] && rm "$temp"; }
|
|
trap cleanup EXIT
|
|
|
|
temp="$(mktemp)"
|
|
|
|
# main
|
|
#url="https://git.alpinelinux.org/aports/tree/$name?h=master"
|
|
#pre="tree listing"
|
|
#pst="<\/table"
|
|
#rex="href='.+\/([^\/]+.patch)'"
|
|
#plain="https://git.alpinelinux.org/aports/plain"
|
|
|
|
# github mirror
|
|
url="https://github.com/alpinelinux/aports/tree/master/$name"
|
|
pre="repository-content"
|
|
pst="footer container"
|
|
rex='title="([^\/]+.patch)"'
|
|
plain="https://raw.githubusercontent.com/alpinelinux/aports/master"
|
|
|
|
# extract the text between the pre and post regexes on the target webpage.
|
|
{ curl --compressed -m $timeout -L -s $url \
|
|
|| { echo "url failed" >&2 && continue; }; } \
|
|
| awk "sub(/^.*$pre/,\"\"){echo=1} /$pst/{echo=0} echo" \
|
|
> $temp
|
|
|
|
perl -n -e "/$rex/ && print \"\$1\\n\"" $temp | while read path; do
|
|
curl -LO "$plain/$name/$path"
|
|
done
|
|
}
|
|
|
|
# importalpinepatches <tree>/<package> [timeout]
|
|
importalpinepatches() {
|
|
mkdir patches-enabled patches-available
|
|
cd patches-available
|
|
getalpinepatches $1 $2
|
|
[ "$(ls)" ] || { cd .. && return 0; }
|
|
cd ../patches-enabled
|
|
ln -s ../patches-available/* .
|
|
ls
|
|
cd ..
|
|
}
|
|
|
|
# howfromalpine <tree>/<package> [lix-name [timeout]]
|
|
howfromalpine() {
|
|
alpinepkg="$1"
|
|
pkg="$2"
|
|
pkgs="${HOWROOT:-/lix-os/how}/pkg"
|
|
|
|
[ "$pkg" ] || pkg="${alpinepkg#*/}"
|
|
|
|
cd "$pkgs"
|
|
mkdir -p "$pkg/default"
|
|
cd "$pkg/default"
|
|
|
|
plain="https://raw.githubusercontent.com/alpinelinux/aports/master"
|
|
curl -LO "$plain/$alpinepkg/APKBUILD"
|
|
cp APKBUILD "conf.sh"
|
|
cp APKBUILD "make.sh"
|
|
cp APKBUILD "inst.sh"
|
|
cp "$pkgs/../default/deps" .
|
|
chmod +x *.sh
|
|
|
|
importalpinepatches "$alpinepkg" $3
|
|
|
|
cat APKBUILD | grep "source="
|
|
}
|
|
|
|
# srcnewtar <name> <version> <type> <arc url> [sig url]
|
|
srcnewtar() {
|
|
[ "$SRCROOT" != "" ] || { echo "please specify SRCROOT" && exit 1; }
|
|
|
|
if [ ! "$4" ]; then
|
|
echo "usage: $0 <name> <version> <type> <arc url> [sig url]"
|
|
exit
|
|
fi
|
|
|
|
name="$1"
|
|
version="$2"
|
|
type="$3"
|
|
arcurl="$(eval "echo \"$4\"")"
|
|
sigurl="$(eval "echo \"$5\"")"
|
|
mkdir -p $SRCROOT/pkg/$name
|
|
tmpdir="$(mktemp -d)"
|
|
|
|
arcdest="$tmpdir/$name-$version.$type"
|
|
sigdest="$tmpdir/$name-$version.$type.sig"
|
|
|
|
[ ! "$(echo "$name" | cut -d/ -f2)" ] || mkdir -p "$tmpdir/$(dirname "$name")"
|
|
|
|
curl -L -o "$arcdest" "$arcurl"
|
|
size="$(wc -c "$arcdest" | cut -d' ' -f1)"
|
|
sum="$(sha512sum "$arcdest" | cut -d' ' -f1)"
|
|
|
|
cat << EOF > $SRCROOT/pkg/$name/defaults.sh
|
|
version="$version"
|
|
type="$type"
|
|
EOF
|
|
|
|
printf "\$version\t\$type\tarc\t$4\n" >> $SRCROOT/pkg/$name/urls
|
|
printf "$version\t$type\tarc\t$size\t$sum\n" >> $SRCROOT/pkg/$name/checks
|
|
|
|
if [ "$sigurl" ]; then
|
|
curl -L -o "$sigdest" "$sigurl"
|
|
size="$(wc -c "$sigdest" | cut -d' ' -f1)"
|
|
sum="$(sha512sum "$sigdest" | cut -d' ' -f1)"
|
|
|
|
printf "\$version\t\$type\tsig\t$5\n" >> $SRCROOT/pkg/$name/urls
|
|
printf "$version\t$type\tsig\t$size\t$sum\n" >> $SRCROOT/pkg/$name/checks
|
|
fi
|
|
|
|
printf "\n$name defaults.sh\n======\n"
|
|
cat $SRCROOT/pkg/$name/defaults.sh
|
|
|
|
printf "\n$name urls\n======\n"
|
|
cat $SRCROOT/pkg/$name/urls
|
|
|
|
printf "\n$name checks\n======\n"
|
|
cat $SRCROOT/pkg/$name/checks
|
|
|
|
rm -fr "$tmpdir"
|
|
}
|
|
|
|
# srcnewgit <name> <version> <arc url>
|
|
srcnewgit() {
|
|
[ "$SRCROOT" != "" ] || { echo "please specify SRCROOT" && exit 1; }
|
|
|
|
if [ ! "$3" ]; then
|
|
echo "usage: $0 <name> <version> <arc url>"
|
|
exit
|
|
fi
|
|
|
|
name="$1"
|
|
version="$2"
|
|
arcurl="$(eval "echo \"$3\"")"
|
|
mkdir -p $SRCROOT/pkg/$name
|
|
|
|
tmpdir="$(mktemp -d)"
|
|
arcdest="$tmpdir/$name-$version"
|
|
|
|
git clone --mirror "$arcurl" "$arcdest"
|
|
|
|
cd "$arcdest"
|
|
size="$(git count-objects -vH | grep size-pack | cut -d': ' -f2)"
|
|
sum="$(find . -type f ! -path '**/.git/**' ! -name '.git' | sort | xargs sha512sum | cut -d' ' -f1 | sha512sum | cut -d' ' -f1)"
|
|
cd - >/dev/null
|
|
|
|
cat << EOF > $SRCROOT/pkg/$name/defaults.sh
|
|
version="$version"
|
|
type="git"
|
|
EOF
|
|
|
|
printf "\$version\tgit\tarc\t$3\n" >> $SRCROOT/pkg/$name/urls
|
|
printf "$version\tgit\tarc\t$size\t$sum\n" >> $SRCROOT/pkg/$name/checks
|
|
|
|
printf "\n$name defaults.sh\n======\n"
|
|
cat $SRCROOT/pkg/$name/defaults.sh
|
|
|
|
printf "\n$name urls\n======\n"
|
|
cat $SRCROOT/pkg/$name/urls
|
|
|
|
printf "\n$name checks\n======\n"
|
|
cat $SRCROOT/pkg/$name/checks
|
|
|
|
rm -fr "$tmpdir"
|
|
}
|