#!/bin/bash # shellcheck source=kzcommon.sh # ----------------------------------------------------------------------------- # Webbestanden valideren. # # Geschreven door Karel Zimmer . # # Auteursrecht (c) 2012-2021 Karel Zimmer. # GNU Algemene Publieke Licentie . # # RelNum=11.00.26 # RelDat=2021-01-15 # ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------- # Global constants # ----------------------------------------------------------------------------- source "$(dirname "$0")"/kzcommon.sh readonly CSS_DIR=$HOME/uploads/karelzimmer.nl/httpdocs/css readonly HTML_DIR=$HOME/uploads/karelzimmer.nl/httpdocs/html readonly HOME_URL=https://karelzimmer.nl readonly CSS_URL=$HOME_URL/css readonly HTML_URL=$HOME_URL/html readonly CSS_VALIDATOR_URL='http://jigsaw.w3.org/css-validator/validator?uri=' readonly HTML_VALIDATOR_URL='http://validator.w3.org/check?uri=' # Bij aanpassingen ook .completion aanpassen! readonly OPTIONS_SHORT=$OPTIONS_SHORT_COMMON readonly OPTIONS_LONG=$OPTIONS_LONG_COMMON readonly USAGE="Gebruik: $PROGNAME $OPTIONS_USAGE_COMMON" readonly HELP="Gebruik: $PROGNAME [OPTIE...] Webbestanden valideren. Opties: $OPTIONS_HELP_COMMON" # ----------------------------------------------------------------------------- # Global variables # ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------- # Functions # ----------------------------------------------------------------------------- check_input() { local -i getopt_rc=0 local parsed='' parsed=$( getopt --alternative \ --options "$OPTIONS_SHORT" \ --longoptions "$OPTIONS_LONG" \ --name "$PROGNAME" \ -- "$@" ) || getopt_rc=$? if [[ $getopt_rc -ne 0 ]]; then printf '%s\n' "$USAGELINE" >&2 QUIET=true exit $ERROR fi eval set -- "$parsed" process_general_options "$@" while true; do case $1 in --) shift break ;; *) shift ;; esac done if [[ "$*" ]]; then printf "$PROGNAME: %s\n%s\n" 'geen argumenten opgeven' "$USAGELINE" >&2 QUIET=true exit $ERROR fi # Een non-gui script gestart met optie gui. if $OPTION_GUI; then OPTION_GUI=false TERMINAL=true fi check_user } process_input() { local dir='' for dir in "$CSS_DIR" "$HTML_DIR"; do if ! [[ -d $dir ]]; then error "Map '$dir' bestaat niet." QUIET=true exit $ERROR fi done if ! pgrep 'chrome' &> /dev/null; then warning 'Google Chrome webrowser is nog niet gestart, start nu eerst de Google Chrome webrowser.' read -rp "Druk op Enter-toets wanneer Google Chrome webrowser is \ gestart [Enter]: " < /dev/tty if ! pgrep 'chrome' &> /dev/null; then error 'Google Chrome webrowser is niet gestart.' QUIET=true exit $ERROR fi fi validate_css validate_html } validate_css() { local filename='' cd "$CSS_DIR" for filename in *.css; do google-chrome "$CSS_VALIDATOR_URL$CSS_URL/$filename" |& $LOGCMD done } validate_html() { local filename='' cd "$HTML_DIR" for filename in *.html; do google-chrome "$HTML_VALIDATOR_URL$HTML_URL/$filename" |& $LOGCMD done } term_script() { info 'Controleer de tabbladen in Google Chrome.' QUIET=true exit $SUCCESS } # ----------------------------------------------------------------------------- # Main line # ----------------------------------------------------------------------------- main() { init_script check_input "$@" process_input term_script } main "$@" # EOF