📄 ishencrypt
字号:
#!/bin/sh## Description: signs and/or encrypt the input file and moves the pgp .asc# output to the output file#ECHO=echoDASHN="-n"PGP=pgpMYNAME=`basename $0`usage(){ $ECHO "" $ECHO "Usage: $MYNAME -i infile -o outfile [-u uname] [-s] [-e -r recipient-list]" $ECHO " -s : sign" $ECHO " -e : encrypt (requires recipient-list)" $ECHO " At least one of -s and -e should be present" $ECHO "" $ECHO "*** Press return to continue ***" read ANS}# defaultsUSER=""INPUT=""OUTPUT=""SIGN=""ENCR=""RECLIST=""MIME=""BOUNDARY=""## Parse arguments#while test X"$1" != Xdo case "$1" in -i) INPUT=$2; shift 2;; -o) OUTPUT=$2; shift 2;; -u) USER=$2; shift 2;; -s) SIGN="yes"; shift;; -e) ENCR="yes" shift;; -r) RECLIST=$2; shift 2;; -m) MIME="yes"; shift;; -b) BOUNDARY=$2; MIME="yes" shift 2;; -h) usage; exit 0;; *) usage; exit 1;; esacdone## Check argument validity## Make sure an action is selectedif test -z "$SIGN" -a -z "$ENCR"then usage exit 1fi# I/O should be definedif test -z "$INPUT" -o -z "$OUTPUT"then usage exit 1fi# For encryption, recepient list must be presentif test -n "$ENCR" -a -z "$RECLIST"then usage exit 1fi# Check for sign-onlyif test -n "$SIGN" -a -z "$ENCR"then SIGNONLY="yes"fi# Construct the PGP command lineARGS="-fat"if test -n "$USER"then ARGS="${ARGS} -u '$USER'"fiif test -n "$SIGN"then ARGS="${ARGS} -s"fiif test -n "$ENCR"then ARGS="${ARGS} -e"fi# Produce detached signature for MIME messagesif test -n "$MIME" -a -n "$SIGNONLY"then ARGS="${ARGS} -b"fiCOMMAND="$PGP $ARGS $RECLIST < $INPUT >> $OUTPUT"# Remove the output file(s)rm -f $OUTPUT $OUTPUT.headif test -n "$MIME"then # Headers - in a separate file if test -n "$SIGNONLY" then $ECHO "Content-Type: multipart/signed;" >> $OUTPUT.head $ECHO " boundary=\"$BOUNDARY\";" >> $OUTPUT.head $ECHO " micalg=pgp-md5;" >> $OUTPUT.head $ECHO " protocol=\"application/pgp-signature\"" >> $OUTPUT.head else $ECHO "Content-Type: multipart/encrypted;" >> $OUTPUT.head $ECHO " boundary=\"$BOUNDARY\";" >> $OUTPUT.head $ECHO " protocol=\"application/pgp-encrypted\"" >> $OUTPUT.head fi # MIME boundary $ECHO "--$BOUNDARY" >> $OUTPUT # Output the body first if needed if test -n "$SIGNONLY" then cat $INPUT >> $OUTPUT $ECHO "" >> $OUTPUT $ECHO "--$BOUNDARY" >> $OUTPUT $ECHO "Content-Type: application/pgp-signature" >> $OUTPUT else $ECHO "Content-Type: application/pgp-encrypted" >> $OUTPUT $ECHO "" >> $OUTPUT $ECHO "--$BOUNDARY" >> $OUTPUT $ECHO "Content-Type: application/octet-stream" >> $OUTPUT fi # Prepare for the PGP part $ECHO "" >> $OUTPUTfi## Run the command and save the status#$ECHO "Executing $COMMAND"eval $COMMANDPGPSTAT=$?if test -n "$MIME"then # Final MIME boundary $ECHO "" >> $OUTPUT $ECHO "--$BOUNDARY--" >> $OUTPUTfi## Allow user to confirm#if test $PGPSTAT -eq 0then DEFANS="Y"else DEFANS="N"fiANS=""$ECHO ""$ECHO ""while [ "$ANS" != "y" -a "$ANS" != "Y" -a "$ANS" != "n" -a "$ANS" != "N" ]do $ECHO $DASHN "Was the PGP operation successful (y/n)[$DEFANS]?" read ANS test -z "$ANS" && ANS=$DEFANSdoneif [ "$ANS" = "n" -o "$ANS" = "N" ]then test $PGPSTAT -eq 0 && PGPSTAT=1fiexit $PGPSTAT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -