#!/bin/bash # shellcheck source=kzcommon.sh # ----------------------------------------------------------------------------- # Controlebestanden opsplitsen. # # Geschreven door Karel Zimmer . # # Auteursrecht (c) 2016-2021 Karel Zimmer. # GNU Algemene Publieke Licentie . # # RelNum=08.00.29 # RelDat=2021-01-15 # ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------- # Global constants # ----------------------------------------------------------------------------- source "$(dirname "$0")"/kzcommon.sh readonly SEARCHDIR=$HOME/Downloads readonly HASHPROG=sha256sum # 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...] Controlebestanden opsplitsen. Opties: $OPTIONS_HELP_COMMON" # ----------------------------------------------------------------------------- # Global variables # ----------------------------------------------------------------------------- declare ISO_FILE='' declare ISO_FILE_FOUND=false # ----------------------------------------------------------------------------- # 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() { cd "$SEARCHDIR" for ISO_FILE in *.iso; do if ! [[ -f "$ISO_FILE" ]]; then continue fi ISO_FILE_FOUND=true create_checksum_file done if ! $ISO_FILE_FOUND; then warning "Geen beeldbestanden (.iso) gevonden in '$SEARCHDIR'." rm --force -- *SHA256SUMS fi } create_checksum_file() { local -i grep_rc=0 if [[ -e $ISO_FILE.sha256sum ]]; then info "Beeldbestand '$ISO_FILE' heeft al controlebestand \ '$ISO_FILE.sha256sum'.\n" return 0 else # shellcheck disable=SC2062 grep --word-regexp \ --regexp=" $ISO_FILE" \ --regexp="*$ISO_FILE" \ --exclude=*.iso \ --exclude-dir=* \ --no-filename \ -- * \ > "$ISO_FILE".sha256sum \ 2> >($LOGCMD) || grep_rc=$? if [[ $grep_rc -ne 0 ]]; then error "Geen controlesom gevonden voor '$ISO_FILE'.\n" rm --force "$ISO_FILE".sha256sum else info "Controlebestand '$ISO_FILE.sha256sum' aangemaakt.\n" fi fi } term_script() { if $ISO_FILE_FOUND; then info "Om de beeldbestanden (.iso) te controleren voer uit: ${BLUE}cd $SEARCHDIR;$HASHPROG --check *.$HASHPROG; cd -${NORMAL} En om vervolgens USB-sticks te maken voer uit: ${BLUE}kzmkusbs${NORMAL} Om de controlebestanden (.sha256sums) opnieuw te downloaden voer uit: ${BLUE}kzdlsio --checksums${NORMAL}" rm --force -- *SUM* fi QUIET=true exit $SUCCESS } # ----------------------------------------------------------------------------- # Main line # ----------------------------------------------------------------------------- main() { init_script check_input "$@" process_input term_script } main "$@" # EOF