Skip to content

Commit

Permalink
Let's revert things to a buildable state. I'll need this project.
Browse files Browse the repository at this point in the history
  • Loading branch information
alganet committed Jul 1, 2024
1 parent 7312567 commit aa36308
Show file tree
Hide file tree
Showing 18 changed files with 671 additions and 1,384 deletions.
1,386 changes: 538 additions & 848 deletions .github/workflows/docker-push.yml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
FROM debian:buster-slim AS builder

# Update distro
RUN apt -y update && apt -y upgrade
RUN apt-get -y update

# Copy contents
COPY "shvr.sh" "/shvr/shvr.sh"
Expand Down
211 changes: 0 additions & 211 deletions shvr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ set -euf
SHVR_DIR_SELF="$(cd "$(dirname "$0")"; pwd)"
SHVR_DIR_SRC="${SHVR_DIR_SRC:-"/usr/src/shvr"}"
SHVR_DIR_OUT="${SHVR_DIR_OUT:-"/opt"}"
SHVR_DIR_CACHE="${SHVR_DIR_CACHE:-"${SHVR_DIR_SELF}/.cache"}"

shvr ()
{
Expand All @@ -35,61 +34,6 @@ shvr_targets ()
shvr_each targets "${@:-}"
}

shvr_semver_majors ()
{
"shvr_targets_$1" | cut -d'.' -f1 | uniq | sed 's/^'"$1"'_/'"$1"'_/'
}

shvr_semver_minors ()
{
"shvr_targets_$1" | sed -n 's/^\('"$2"'\)\([.][0-9]*\)\([.]*.*\)/\1\2/p' | uniq
}

shvr_semver_patches ()
{
"shvr_targets_$1" | sed -n 's/^\('"$2"'\)\([.][0-9]*\)\([.]*[0-9]*\)/\1\2/p' | uniq
}

shvr_versions ()
{
if test $# = 0
then set -- $(shvr_interpreters | tr '\n' ' ')
fi

while test $# -gt 0
do
. "${SHVR_DIR_SELF}/variants/${1}.sh"
majors="$(shvr_majors_$1 | head -n ${SHVR_MAJORS:-16} | tr '\n' ' ')"
if test -n "$majors"
then printf '%s ' "$1-latest"
fi
for major in $majors
do
minors="$(shvr_minors_$1 $major | head -n ${SHVR_MINORS:-16} | tr '\n' ' ')"
printf '%s ' "$major-latest"
if test -z "$minors"
then echo "$major"
fi
for minor in $minors
do
patches="$(shvr_patches_$1 $minor | sort -V -r | head -n ${SHVR_PATCHES:-1} | tr '\n' ' ')"
if test "$major " != "$minors" && test "$minor " != "$patches"
then printf '%s ' "$minor-latest"
fi
if test -z "$patches"
then
echo "$minor"
fi
for patch in $patches
do
echo "$patch"
done
done
done
shift
done
}

shvr_interpreters ()
{
find "${SHVR_DIR_SELF}/variants" -type f |
Expand Down Expand Up @@ -117,159 +61,4 @@ shvr_each ()
done
}

shvr_yml_tags ()
{
interpreter="${1%%_*}"
version="${1#"$interpreter"_}"
shvr_versions "$interpreter" |
sed -n '/'"$(echo "$version" |
sed 's/\./\\./g')"'$/p' |
tr ' ' '\n' |
sed 's/^/alganet\/shell-versions:/'
}

shvr_yml_generate_workflows ()
{
shvr_yml_header pull_request "Docker Build Pipeline" "false" > ".github/workflows/docker-build.yml"
shvr_yml_items single >> ".github/workflows/docker-build.yml"

shvr_yml_header push "Docker Push Pipeline" "true" > ".github/workflows/docker-push.yml"
shvr_yml_items multi >> ".github/workflows/docker-push.yml"
}

shvr_yml_header ()
{
cat <<-@
# Copyright (c) Alexandre Gomes Gaigalas <[email protected]>
# SPDX-License-Identifier: ISC
# THIS FILE IS AUTO-GENERATED, DO NOT EDIT
name: $2
on:
$1:
branches:
- "main"
jobs:
build:
runs-on: ubuntu-latest
continue-on-error: \${{ matrix.can_fail_build }}
steps:
- uses: actions/checkout@v3
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: \${{ secrets.DOCKER_USER }}
password: \${{ secrets.DOCKER_PASS }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: "Build Docker Image (push: $3)"
uses: docker/build-push-action@v4
with:
context: .
push: $3
tags: \${{ matrix.tags }}
labels: \${{ matrix.name }}
build-args: |
TARGETS=\${{ matrix.targets }}
strategy:
fail-fast: false
matrix:
include:
@
}

shvr_latest ()
{
shvr_versions "$1" | grep latest | sed '/beta\|alpha\|rc/ d'
}

shvr_yml_items ()
{
if test "$1" = "multi"
then
cat <<-@
##########################################
# multi
##########################################
#multi-latest
- name: multi-latest
targets: "$(SHVR_MAJORS=2 SHVR_MINORS=2 SHVR_PATCHES=1 shvr_versions | sed 's/ $//' | rev | cut -d' ' -f1 | rev | sort -V -r | tr '\n' ' ' )"
can_fail_build: false
tags: |
latest
multi-latest
@
echo
fi
shvr_interpreters | while read -r interpreter
do
cat <<-@
##########################################
# $interpreter
##########################################
@
if test "$1" = "multi"
then
targets="$(shvr_versions "$interpreter" | sed 's/ $//' | rev | cut -d' ' -f1 | rev | sort -V -r | tr '\n' ' ' )"
if test -n "$targets"
then
cat <<-@
# $interpreter-all
- name: $interpreter-all
targets: "$targets"
can_fail_build: false
tags: |
$interpreter-all
@
fi
echo
fi

targets="$(shvr_versions "$interpreter")"

echo "$targets" | while read -r target
do
if test -z "$target"
then continue
fi
cat <<-@
# $target
- name: ${target##* }
targets: "${target##* }"
can_fail_build: false
tags: |$(echo; shvr_yml_tags ${target##* } | sed 's/^/ /')
@
echo
done
if test -z "${targets:-}"
then
cat <<-@
# no buildable targets
@
fi
done
}

shvr_cache ()
{
cache_key="${SHVR_DIR_CACHE}/$1"
shift

if ! test -f "$cache_key"
then
mkdir -p "${SHVR_DIR_CACHE}"
"$@" > "$cache_key"
fi

cat "$cache_key"
}

shvr "${@:-}"
56 changes: 13 additions & 43 deletions variants/bash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,21 @@

shvr_targets_bash ()
{
shvr_cache targets_bash \
curl --no-progress-meter "https://ftp.gnu.org/gnu/bash/" |
grep -Eo 'href="[^"]*"' |
sed -n '
s/^href="bash-/bash_/
s/"$//
/^bash_[0-9][0-9]*.*\.tar\.gz$/ {
s/\.tar\.gz$//
p
}
/^bash_[0-9][0-9]*.*-patches\/$/ {
s/^bash_/bash-/
p
}
' |
while read -r possible_version
do
if test "${possible_version%"patches/"}" != "$possible_version"
then
shvr_cache "targets_bash${possible_version%'/'}" \
curl --no-progress-meter "https://ftp.gnu.org/gnu/bash/$possible_version" |
grep -Eo 'href="[^"]*"' |
sed -n '
s/^href="//
s/"$//
/^bash.*[0-9][0-9][0-9]$/ {
p
}
' |
sort -V |
cut -d'-' -f2 |
sed "s/^/${possible_version%'/'}/" |
sed 's/^bash-/bash_/; s/-patches[0]*/./'
else echo "$possible_version"
fi
done |
grep -v "^bash_[0-2]\." |
sort -u |
sort -V -r
cat <<-@
bash_5.2.15
bash_5.1.16
bash_5.0.18
bash_4.4.23
bash_4.3.48
bash_4.2.53
bash_4.1.17
bash_4.0.44
bash_3.2.57
bash_3.1.23
bash_3.0.22
@
}

shvr_majors_bash () { shvr_semver_majors bash; }
shvr_minors_bash () { shvr_semver_minors bash "$@"; }
shvr_patches_bash () { shvr_semver_patches bash "$@"; }

shvr_build_bash ()
{
version="$1"
Expand Down
44 changes: 21 additions & 23 deletions variants/busybox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,26 @@

shvr_targets_busybox ()
{
shvr_cache targets_busybox \
curl --no-progress-meter "https://busybox.net/downloads/" |
grep -Eoi 'href="[^"]*"' |
sed -n '
s/^href="busybox-/busybox_/
s/"$//
/^busybox_[0-9][0-9]*.*\.tar\.bz2$/ {
s/\.tar\.bz2$//
p
}
' |
grep "^busybox_1\.[0-9][0-9]" |
grep -v "^busybox_1\.[0-1][0-9]" |
grep -v "^busybox_1\.20\." |
sort -u |
sort -V -r
cat <<-@
busybox_1.36.0
busybox_1.35.0
busybox_1.34.1
busybox_1.33.2
busybox_1.32.1
busybox_1.31.1
busybox_1.30.1
busybox_1.29.3
busybox_1.28.4
busybox_1.27.2
busybox_1.26.2
busybox_1.25.1
busybox_1.24.2
busybox_1.23.2
busybox_1.22.1
busybox_1.21.1
@
}

shvr_majors_busybox () { shvr_semver_majors busybox; }
shvr_minors_busybox () { shvr_semver_minors busybox "$@"; }
shvr_patches_busybox () { shvr_semver_patches busybox "$@"; }

shvr_build_busybox ()
{
version="$1"
Expand Down Expand Up @@ -109,14 +107,14 @@ shvr_build_busybox ()
make allnoconfig

for conf in $unsetConfs
do
do
sed -i \
-e "s!^$conf=.*\$!# $conf is not set!" \
.config
done

for confV in $setConfs
do
do
conf="${confV%=*}"
sed -i \
-e "s!^$conf=.*\$!$confV!" \
Expand All @@ -134,7 +132,7 @@ shvr_build_busybox ()
done

for confV in $setConfs
do
do
if ! grep -q "^$confV\$" .config
then
if test "${version_major}" = 1 -a "${version_minor}" -lt 26
Expand Down
Loading

0 comments on commit aa36308

Please sign in to comment.