#!/bin/bash # parameters and default values ARCH='i686' DESC='i686 only' DATE=$(date +%Y.%m.%d) ISO="archlinux32-${DATE}-${ARCH}.iso" # fail on first error set -e base_dir=$( readlink -e "${0%/*}" ) usage() { >&2 echo '' >&2 echo 'update-website: update download, torrent, magnet links on' >&2 echo ' the Arch32 website' >&2 echo '' >&2 echo 'possible options:' >&2 echo ' -h|--help: Show this help and exit.' >&2 echo '' >&2 echo 'configuration options:' >&2 echo " --arch architecture of the ISO to update, default '$ARCH'." >&2 echo " --desc description of the ISO to update, default '$DESC'." >&2 echo " --iso name of ISO to be checked, default is '${ISO}'." >&2 echo ' --website-dir set website-dir to .' >&2 echo ' --mirror-dir set mirror-dir to .' >&2 echo ' --magnet-link set magnet link to for architecture --arch.' >&2 echo ' --torrent-seed set torrent seed link to $link for architecture --arch.' >&2 echo '' >&2 echo 'operations:' >&2 echo ' --update-mirrors regenerate mirror list and country flags.' >&2 echo ' --update-iso update information about ISO, too.' [ -z "$1" ] && exit 1 || exit "$1" } eval set -- "$( getopt -o h \ --long help \ --long arch: \ --long desc: \ --long iso: \ --long website-dir: \ --long mirror-dir: \ --long magnet-link: \ --long torrent-seed: \ --long update-mirrors \ --long update-iso \ -n "$(basename "$0")" -- "$@" || \ echo usage )" # cleanup hook tmp_dir="$(mktemp -d)" cleanup() { if mountpoint -q "${tmp_dir}"; then sudo umount "${tmp_dir}" fi rm -rf --one-file-system "${tmp_dir}" } trap cleanup EXIT arch="${ARCH}" desc="${DESC}" iso="${ISO}" while [ $# -gt 0 ]; do case "$1" in '--arch') shift arch="$1" ;; '--desc') shift desc="$1" ;; '--iso') shift iso="$1" ;; '--website-dir') if [ -s "${tmp_dir}/website_dir.set" ]; then printf 'Option %s given multiple times.\n' "$1" usage fi shift website_dir="$1" echo "$website_dir" > "${tmp_dir}/website_dir.set" ;; '--mirror-dir') if [ -s "${tmp_dir}/mirror_dir.set" ]; then printf 'Option %s given multiple times.\n' "$1" usage fi shift mirror_dir="$1" echo "$mirror_dir" > "${tmp_dir}/mirror_dir.set" ;; '--magnet-link') if [ -s "${tmp_dir}/magnet.link.set" ]; then printf 'Option %s given multiple times.\n' "$1" usage fi shift echo "$1" | \ tr -d '\n' > \ "${tmp_dir}/magnet.link.set" ;; '--torrent-seed') if [ -s "${tmp_dir}/torrent-seed.set" ]; then printf 'Option %s given multiple times.\n' "$1" usage fi shift echo "$1" | \ tr -d '\n' > \ "${tmp_dir}/torrent-seed.set" ;; '--update-mirrors') if [ -s "${tmp_dir}/update_mirrors.set" ]; then printf 'Option %s given multiple times.\n' "$1" usage fi echo "true" > "${tmp_dir}/update_mirrors.set" ;; '--update-iso') if [ -s "${tmp_dir}/update_iso.set" ]; then printf 'Option %s given multiple times.\n' "$1" usage fi echo "true" > "${tmp_dir}/update_iso.set" ;; '--help'|'-h') usage 0 ;; '--') shift break ;; *) >&2 printf 'Whoops, option "%s" is not yet implemented!\n' "$1" exit 42 ;; esac shift done if [ $# -gt 0 ]; then >&2 echo 'Too many arguments.' exit 2 fi # generate list of download mirrors if [ -s "${tmp_dir}/update_mirrors.set" ]; then ( printf '
\n' curl -Ss 'https://archlinux32.org/mirrorlist/?country=all&hash='"$( head -c 24 /dev/urandom | \ base64 -w0 )" | \ sed ' 0,/^$/d /^$/d /^## /{ s|^## |\n \n\n
| s|$|
\n\n
    \n| '"$( while read -r flag country; do printf \ 's|
    %s
    |
    %s
    |\n' \ "${country}" \ "${flag}" \ "${country}" \ "${country}" done < \ "${0%/*}/flag-names" )"' } /^#Server = /{ s|^#Server = \(.*//\)\([^/]*\)\(/.*\)\$arch/\$repo/\?$|'"$( printf \ ' %s\\n' \ '
  • \2
  • ' )"'| } ' | \ sed ' 0,/<\/ul>/d ' printf '
\n\n' printf '
\n' ) | \ sed -i ' :emptyLines /^\n*$/{ N bemptyLines } /^\(\s*\n\)*\s*
$/{ :a s|^.*
|| tb $!N ba :b r /dev/stdin } ' "${website_dir}/download/index.html" fi # date of the ISO date=$(echo "${iso}" \ | sed 's/^.*-\([^-]\+\)-[^-]\+$/\1/' \ | sort -u ) # update magnet links if [ -s "${tmp_dir}/magnet.link.set" ]; then sed -i ' /
  • Magnet link for \S\+ ('"${desc}"')/ s/>Magnet link for \S\+ />Magnet link for '"${date}"' / ' "${website_dir}/download/index.html" fi # update torrent links if [ -s "${tmp_dir}/torrent-seed.set" ]; then if grep -qF "archlinux32-${date}-${arch}" "${tmp_dir}/torrent-seed.set"; then sed -i ' /
  • Torrent for \S\+ ('"${desc}"')/ s/>Torrent for \S\+ />Torrent for '"${date}"' / ' "${website_dir}/download/index.html" else >&2 printf 'Torrent seed for %s is not for %s, skipping.\n' "${arch}" "${iso}" fi fi # update ISO links and information if [ -s "${tmp_dir}/update_iso.set" ]; then if [ ! -f "${mirror_dir}/archisos/${iso}" ]; then >&2 echo "Can't find iso to arch '${mirror_dir}/archisos/${iso}'." exit 1 fi kernel="$("${base_dir}"/check-iso --iso="${iso}" --output-dir "${mirror_dir}/archisos" --kernel-version)" size="$("${base_dir}"/check-iso --iso="${iso}" --output-dir "${mirror_dir}/archisos" --size)" md5="$("${base_dir}"/check-iso --iso="${iso}" --output-dir "${mirror_dir}/archisos" --md5sum)" sha512="$("${base_dir}"/check-iso --iso="${iso}" --output-dir "${mirror_dir}/archisos" --sha512sum)" sign_key="$("${base_dir}"/check-iso --iso="${iso}" --output-dir "${mirror_dir}/archisos" --sign-key)" fi # adapt release info on the top values=( 'Current Release' "${date}" 'Included Kernel' "${kernel}" 'PGP Key' ''"${sign_key}"'' ) sed -i "$( printf '/%s:/s|.*
  • | %s|\n' "${values[@]}" ) " \ "${website_dir}/download/index.html" # adapt values for each ISO values=( "ISO Size (${desc})" "${size} MB" "MD5 (${desc})" "${md5}" "SHA512 (${desc})" "${sha512}" ) sed -i "$( printf '/%s:/s|.*| %s|\n' "${values[@]}" ) " \ "${website_dir}/download/index.html" # adapt dates in signatures sed -i "$( printf '/archlinux32-[0-9.]\+-%s\.iso\.sig/s@archlinux32-[0-9.]\+-%s\.iso\.sig@archlinux32-%s-%s.iso.sig@\n' \ "${arch}" "${arch}" "${date}" "${arch}" ) " \ "${website_dir}/download/index.html" exit 0