--- trunk/dist/distupload 2024/08/03 15:50:38 11 +++ trunk/dist/distupload 2024/08/04 13:06:22 20 @@ -3,12 +3,12 @@ # distupload -- a script to upload software distributions to a server # # This script is part of OSN Commons. Copyright (C) 2024 OSN, Inc. -# +# # OSN Commons is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # OSN Commons is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -28,7 +28,7 @@ version="1.0.0" check_requirements() { - if [ -z "$(command -v grep)" ]; then + if [ -z "$(command -v grep)" ]; then echo "$me: GNU grep is required to use this script" >&2 exit 1 fi @@ -66,7 +66,7 @@ ftp/sftp/scp. Feedback, bug reports and general questions should be sent -to <commons@lists.onesoftnet.eu.org>. +to <commons@onesoftnet.eu.org>. EOF } @@ -96,7 +96,7 @@ if echo "$1" | grep -E "^$pattern$" >/dev/null 2>&1; then return - fi + fi echo "$me: invalid domain '$1'" >&2 exit 1 @@ -111,7 +111,7 @@ } check_files() { - local output=""; + local output="" for file in "$@"; do output=$(stat "$file" 2>&1) @@ -141,7 +141,7 @@ fi echo "$me: generating GPG signature for $file" - gpg --detach-sign --armor -o - -- "$file" > "$file.sig" + gpg --detach-sign --armor -o - -- "$file" >"$file.sig" if [ $? -ne 0 ]; then echo "$me: failed to generate signature for $file" >&2 @@ -168,69 +168,69 @@ if [ $posargs -eq 0 ]; then case "$1" in - -h|-\?|--help) - show_help - exit - ;; - -v|--version) - show_version - exit - ;; - -m|--method) - check_optarg $@ - method="$2" - shift 2 - ;; - -q|--quiet) - quiet=1 - shift - ;; - -r|--remote) - check_optarg $@ - validate_domain "$2" - remote="$2" - shift 2 - ;; - -l|--location) - check_optarg $@ - location="$2" - shift 2 - ;; - -p|--password) - check_optarg $@ - password="$2" - shift 2 - ;; - -u|--username) - if [ -z "$2" ]; then - username="$USER" - else - username="$2" - fi - - shift 2 - ;; - --) - posargs=1 - shift - ;; - -*) - echo "$me: invalid option -- '$1'" >&2 - echo "Try '$me --help' for more information" >&2 - exit 1 - ;; - *) - ended=1 + -h | -\? | --help) + show_help + exit + ;; + -v | --version) + show_version + exit + ;; + -m | --method) + check_optarg $@ + method="$2" + shift 2 + ;; + -q | --quiet) + quiet=1 + shift + ;; + -r | --remote) + check_optarg $@ + validate_domain "$2" + remote="$2" + shift 2 + ;; + -l | --location) + check_optarg $@ + location="$2" + shift 2 + ;; + -p | --password) + check_optarg $@ + password="$2" + shift 2 + ;; + -u | --username) + if [ -z "$2" ]; then + username="$USER" + else + username="$2" + fi + + shift 2 + ;; + --) + posargs=1 + shift + ;; + -*) + echo "$me: invalid option -- '$1'" >&2 + echo "Try '$me --help' for more information" >&2 + exit 1 + ;; + *) + ended=1 ;; esac else ended=1 fi - if [ $ended -eq 1 ]; then + if [ $ended -eq 1 ]; then if [ ! -z "$files" ]; then files="$files " - fi + fi if echo "$file_name" | grep -q "[\ \'\"]"; then echo "$me: file names must not contain spaces or quotes" >&2 @@ -258,7 +258,7 @@ echo "$me: using $method to upload files to $target:$location" -if [ ! -z "$username" ]; then +if [ ! -z "$username" ]; then echo "$me: authenticating as $username" fi @@ -277,81 +277,81 @@ time_start=$(date +%s) case $method in - scp) - check_command scp +scp) + check_command scp - if [ ! -z "$password" ]; then - echo "$me: cannot make any use of the password provided via command line options when using scp" - echo "$me: please enter the password when asked by scp" - fi - - if [ $quiet -eq 1 ]; then - scp -- $files "$target:$location" > /dev/null 2>&1 - else - scp -- $files "$target:$location" - fi + if [ ! -z "$password" ]; then + echo "$me: cannot make any use of the password provided via command line options when using scp" + echo "$me: please enter the password when asked by scp" + fi - code=$? - - if [ $code -ne 0 ]; then - echo "$me: scp failed with exit code $code" >&2 - exit 1 - fi + if [ $quiet -eq 1 ]; then + scp -- $files "$target:$location" >/dev/null 2>&1 + else + scp -- $files "$target:$location" + fi + + code=$? + + if [ $code -ne 0 ]; then + echo "$me: scp failed with exit code $code" >&2 + exit 1 + fi ;; - ftp|sftp) - check_command $method +ftp | sftp) + check_command $method - if [ -z "$username" ]; then - echo "$me: no username provided, using 'anonymous' as default" - username=anonymous - fi + if [ -z "$username" ]; then + echo "$me: no username provided, using 'anonymous' as default" + username=anonymous + fi - batch_file=$(mktemp) + batch_file=$(mktemp) - if [ $? -ne 0 ]; then - echo "$me: failed to create temporary file" >&2 - exit 1 - fi + if [ $? -ne 0 ]; then + echo "$me: failed to create temporary file" >&2 + exit 1 + fi - if [ "$method" = "ftp" ]; then - echo "user \"$username\" \"$password\"" > "$batch_file" - echo "passive on" >> "$batch_file" - fi + if [ "$method" = "ftp" ]; then + echo "user \"$username\" \"$password\"" >"$batch_file" + echo "passive on" >>"$batch_file" + fi - echo "cd $location" >> "$batch_file" + echo "cd $location" >>"$batch_file" - for file in $files; do - echo "put $file" >> "$batch_file" - done - - echo "bye" >> "$batch_file" - - if [ "$method" = "sftp" ]; then - if [ $quiet -eq 1 ]; then - sftp -oBatchMode=no -b "$batch_file" "$target" > /dev/null 2>&1 - else - sftp -oBatchMode=no -b "$batch_file" "$target" - fi + for file in $files; do + echo "put $file" >>"$batch_file" + done + + echo "bye" >>"$batch_file" + + if [ "$method" = "sftp" ]; then + if [ $quiet -eq 1 ]; then + sftp -oBatchMode=no -b "$batch_file" "$target" >/dev/null 2>&1 else - if [ $quiet -eq 1 ]; then - cat "$batch_file" | $method -inv "$remote" > /dev/null 2>&1 - else - cat "$batch_file" | $method -inv "$remote" - fi + sftp -oBatchMode=no -b "$batch_file" "$target" fi - - code=$? - - if [ $code -ne 0 ]; then - echo "$me: $method failed with exit code $code" >&2 - exit 1 + else + if [ $quiet -eq 1 ]; then + cat "$batch_file" | $method -inv "$remote" >/dev/null 2>&1 + else + cat "$batch_file" | $method -inv "$remote" fi - ;; + fi - *) - echo "$me: unsupported method '$method'" >&2 + code=$? + + if [ $code -ne 0 ]; then + echo "$me: $method failed with exit code $code" >&2 exit 1 + fi + ;; + +*) + echo "$me: unsupported method '$method'" >&2 + exit 1 ;; esac @@ -364,4 +364,4 @@ rm -f "$sigfile" done -echo "$me: upload complete in ${time_diff}s" \ No newline at end of file +echo "$me: upload complete in ${time_diff}s"