# # Receive a file and save is locally # Script run by ssh to receive a compressed file and to save it # Works in bash and dash # # Assumes that gzip output as stdin # #set -x set -e error() { echo ERROR: $* exit 1; } # User options while getopts D arg ; do case $arg in D) set -x ;; *) error Unknown option: $arg ;; esac done shift $(($OPTIND - 1)) # User arguments fname=${1:?Need file name} dpkg="dpkg_archive" [ -d $dpkg ] || error dpkg_archive not found # # Names of working directories # metadir="$dpkg/.dpkg_archive" tmpfile="$metadir/${fname}.NEWTMP" newfile="$metadir/${fname}" # # Create package metadata directory # Ensure its writable mkdir -p "$metadir" chmod u+w "$metadir" # # unzip the file into a temp name gunzip -c -d -- > "$tmpfile" # # Now that the new file has arrived error free # Rename the temp file to the new file # chmod a+w "$newfile" || true rm -f "$newfile" mv "$tmpfile" "$newfile" # Fix up permissions on the file and directory chmod a-w "$newfile" chmod go-w "$metadir" chmod a+rx "$metadir"