#!/bin/bash set -e mirror_dir='/mnt/archlinux32' website_dir='/usr/src/archlinux32/website' usage() { >&2 echo '' >&2 echo 'get-package-updates: check for packages that need to be built,' >&2 echo ' and build a list in the proper build order' >&2 echo '' >&2 echo 'possible options:' >&2 echo ' -h|--help: Show this help and exit.' >&2 echo ' --magnet-i686 $link:' >&2 echo ' Set archiso-i686 magnet link to $link.' >&2 echo ' --magnet-dual $link:' >&2 echo ' Set archiso-dual magnet link to $link.' >&2 echo ' --torrent-seed-i686 $link:' >&2 echo ' Set archiso-i686 torrent link to $link.' >&2 echo ' --torrent-seed-dual $link:' >&2 echo ' Set archiso-dual torrent link to $link.' >&2 echo ' --website-dir $dir:' >&2 echo ' Set website-dir to $dir.' >&2 echo ' --mirror-dir $dir:' >&2 echo ' Set mirror-dir to $dir.' >&2 echo ' --update-iso:' >&2 echo ' Update information about iso, too.' [ -z "$1" ] && exit 1 || exit "$1" } eval set -- "$( getopt -o h \ --long help \ --long magnet-i686: \ --long magnet-dual: \ --long torrent-seed-i686: \ --long torrent-seed-dual: \ --long mirror-dir: \ --long website-dir: \ --long update-iso \ -n "$(basename "$0")" -- "$@" || \ echo usage )" 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 while [ $# -gt 0 ]; do case "$1" in '--magnet-i686') if [ -s "${tmp_dir}/magnet.i686" ]; then printf 'Option %s given multiple times.\n' "$1" usage fi shift echo "$1" | \ tr -d '\n' > \ "${tmp_dir}/magnet.i686" ;; '--magnet-dual') if [ -s "${tmp_dir}/magnet.dual" ]; then printf 'Option %s given multiple times.\n' "$1" usage fi shift echo "$1" | \ tr -d '\n' > \ "${tmp_dir}/magnet.dual" ;; '--torrent-seed-i686') if [ -s "${tmp_dir}/torrent-seed.i686" ]; then printf 'Option %s given multiple times.\n' "$1" usage fi shift echo "$1" | \ tr -d '\n' > \ "${tmp_dir}/torrent-seed.i686" ;; '--torrent-seed-dual') if [ -s "${tmp_dir}/torrent-seed.dual" ]; then printf 'Option %s given multiple times.\n' "$1" usage fi shift echo "$1" | \ tr -d '\n' > \ "${tmp_dir}/torrent-seed.dual" ;; '--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" ;; '--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" ;; '--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 ( printf '