#!/bin/bash usage () { printf "\nUsage:\n" printf "\t update-scripts [options]\n\n" printf "Options:\n\n" printf "\t -c, --check Don't actually apply any changes.\n" printf "\t -n, --nodown Don't download any scripts.\n" printf "\t -h, --help Print this help text.\n\n" } parse () { while read -r col1 col2; do case $col1 in script) if [[ $scrdup = no && $scrpack = yes ]]; then if [ "$urlfnd" = "no" ]; then echo "$script has no upstream source." printf "url\t\tNo upstream source.\n" >> INDEX fi if [ "$descfnd" = "no" ]; then echo "$script has no description." printf "description\tNo description.\n\n" >> INDEX printf "%-29s No description.\n" "$script" >> debian/description-list fi fi script="$col2" urlfnd="no" descfnd="no" if ! grep -q "^$script$" .scriptlist; then scrdup="no" echo "$script --------------------" echo "$script" >> .scriptlist if grep -q "^$script$" .packagedlist; then scrpack="yes" printf "script\t\t%s\n" "$script" >> INDEX else scrpack="no" echo "$script is not included yet, skipping." echo "$script" >> .nonincludes fi else scrdup="yes" fi ;; url) urlfnd="yes" url="$col2" if [[ $scrdup = no && $scrpack = yes ]]; then if [[ $url =~ ^(https?|ftps?):// ]]; then printf "url\t\t%s\n" "$url" >> INDEX if [ "$nodown" != "yes" ]; then get_new "$script" "$url" fi else echo "$script has no upstream source." printf "url\t\tNo upstream source.\n" >> INDEX fi fi ;; description) descfnd="yes" desc="$col2" if [[ $scrdup = no && $scrpack = yes ]]; then if [ "$urlfnd" = "no" ]; then urlfnd="yes" echo "$script has no upstream source." printf "url\t\tNo upstream source.\n" >> INDEX fi if [ -z "$desc" ]; then echo "$script has no description." desc="No description." fi printf "description\t%s\n\n" "$desc" >> INDEX printf "%-29s %s\n" "$script" "$desc" >> debian/description-list fi ;; esac done <<< "$1" | tee -a update-scripts.log } get_new () { script="$1" url="$2" wget -t 5 -T 10 -qO "scripts/$script.new" "$url" || { echo "$script failed to download." rm "scripts/$script.new" return } if diff "scripts/$script" "scripts/$script.new" > /dev/null; then echo "$script is up to date." rm "scripts/$script.new" else echo "$script needs updating." echo "$script" >> .changes if [ "$noapply" != "yes" ]; then mv "scripts/$script.new" "scripts/$script" else rm "scripts/$script.new" fi fi } opts=$(getopt -o "cnh" -l "check,nodown,help" -- "$@") eval set -- "$opts" while true; do case $1 in -c|--check) noapply="yes" shift ;; -n|--nodown) nodown="yes" shift ;; -h|--help) usage exit 0 ;; --) shift break ;; esac done shopt -s extglob debclean > /dev/null 2>&1 || exit 1 ### Main indexweb=$(wget -t 5 -T 10 -qO - http://scripts.irssi.org/) && { wording="Downloaded" indexweb=$(sed -ne '/