wobblyhead hg > wobbly_ssg
comparison tools/make_dist.sh @ 0:71dd8d58a8e5 default tip
cleaned up re-init from net_wobblyhead_www project tooling
| author | ark |
|---|---|
| date | 2026-10-22 14:59 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:71dd8d58a8e5 |
|---|---|
| 1 #!/bin/sh | |
| 2 | |
| 3 USAGE="$0 [-m] <name> <url> | |
| 4 | |
| 5 pack the build directory into an archive for the site address <url> and | |
| 6 print the path of the archive. run from the site root. | |
| 7 | |
| 8 the archive is written to dist/ as <build dir>-<name>-<version>.tar.gz. it | |
| 9 holds the build directory under its own name. the version comes from | |
| 10 get_version.sh -f. | |
| 11 | |
| 12 the generated pages contain absolute urls built from site_url in config.txt. | |
| 13 when <url> is a different address, site_url is replaced with <url> in every | |
| 14 html file of a copy of the build directory. the build directory itself is | |
| 15 not changed. | |
| 16 | |
| 17 options: | |
| 18 -m, --make run make_site.py -c first | |
| 19 -h, --help print this help | |
| 20 | |
| 21 positional: | |
| 22 name symbolic name of the target, such as test or prod | |
| 23 url public address of the target, without a trailing slash | |
| 24 " | |
| 25 | |
| 26 MAKE=0 | |
| 27 NAME= | |
| 28 URL= | |
| 29 | |
| 30 while [ "$#" != 0 ] | |
| 31 do | |
| 32 case $1 in | |
| 33 -m|--make) MAKE=1 ;; | |
| 34 -h|--help) echo "$USAGE"; exit 0 ;; | |
| 35 -*) echo "unrecognized option '$1'" >&2; exit 1 ;; | |
| 36 *) | |
| 37 if [ -z "$NAME" ] ; then | |
| 38 NAME="$1" | |
| 39 elif [ -z "$URL" ] ; then | |
| 40 URL="$1" | |
| 41 else | |
| 42 echo "unrecognized argument '$1'" >&2 | |
| 43 exit 1 | |
| 44 fi | |
| 45 ;; | |
| 46 esac | |
| 47 shift | |
| 48 done | |
| 49 | |
| 50 if [ -z "$NAME" ] || [ -z "$URL" ] ; then | |
| 51 echo "missing name or url" >&2 | |
| 52 exit 1 | |
| 53 fi | |
| 54 | |
| 55 if [ ! -f config.txt ] ; then | |
| 56 echo "no config.txt in the current directory" >&2 | |
| 57 exit 1 | |
| 58 fi | |
| 59 | |
| 60 TROOT="$(dirname "$0")" | |
| 61 URL="${URL%/}" | |
| 62 | |
| 63 if [ "$MAKE" = 1 ] ; then | |
| 64 "$TROOT"/make_site.py -c || exit 1 | |
| 65 fi | |
| 66 | |
| 67 # values from config.txt, without surrounding whitespace or trailing slashes | |
| 68 SITE_URL=$(sed -n 's/^site_url:[[:space:]]*//p' config.txt | | |
| 69 sed 's|[/[:space:]]*$||') && | |
| 70 if [ -z "$SITE_URL" ] ; then | |
| 71 echo "no site_url in config.txt" >&2 | |
| 72 exit 1 | |
| 73 fi | |
| 74 | |
| 75 BUILD_DIR=$(sed -n 's/^build_dir:[[:space:]]*//p' config.txt | | |
| 76 sed 's|[/[:space:]]*$||') | |
| 77 : "${BUILD_DIR:=www}" | |
| 78 BUILD_NAME=$(basename "$BUILD_DIR") | |
| 79 | |
| 80 if [ ! -d "$BUILD_DIR" ] ; then | |
| 81 echo "no build directory '$BUILD_DIR', build first or use -m" >&2 | |
| 82 exit 1 | |
| 83 fi | |
| 84 | |
| 85 VERSION=$("$TROOT"/get_version.sh -f) && | |
| 86 ARCHIVE="dist/$BUILD_NAME-$NAME-$VERSION.tar.gz" && | |
| 87 mkdir -p dist && | |
| 88 | |
| 89 STAGE=$(mktemp -d) || exit 1 | |
| 90 trap 'rm -rf "$STAGE"' EXIT | |
| 91 | |
| 92 cp -Rp "$BUILD_DIR" "$STAGE/$BUILD_NAME" && | |
| 93 | |
| 94 if [ "$URL" != "$SITE_URL" ] | |
| 95 then | |
| 96 # dots in the url are literal, not sed wildcards | |
| 97 PATTERN=$(printf '%s' "$SITE_URL" | sed 's/[.]/\\./g') && | |
| 98 find "$STAGE" -type f -name '*.html' | | |
| 99 while IFS= read -r FILE | |
| 100 do | |
| 101 sed "s|$PATTERN|$URL|g" "$FILE" > "$FILE.tmp" && | |
| 102 mv "$FILE.tmp" "$FILE" || | |
| 103 exit 1 | |
| 104 done | |
| 105 fi && | |
| 106 | |
| 107 tar -czf "$ARCHIVE" \ | |
| 108 --no-xattrs --no-mac-metadata \ | |
| 109 --exclude='.DS_Store' \ | |
| 110 -C "$STAGE" "$BUILD_NAME" && | |
| 111 | |
| 112 echo "$ARCHIVE" |
