User Controls

PGP sign posts on linux

  1. #1
    apt Tuskegee Airman
    nigger
    The following users say it would be alright if the author of this post didn't die in a fire!
  2. #2
    Lanny Bird of Courage
    Nice. Here's script for doing basically the same thing on OSX in case anyone cares, although it assumes you're using macvim it would probably be pretty easy to change it to a different editor:


    #!/usr/bin/env zsh

    PLAIN_TEMP=$(mktemp)
    CIPHR_TEMP=$(mktemp)
    EDITOR=/usr/local/Cellar/macvim/8.0-143/MacVim.app/Contents/bin/../MacOS/Vim
    declare -a EDITOR_ARGS=("-f" "-c" ":call English()")

    function usage {
    notify "Usage: $0 [--visual] file\nStarts editing of a file. Signs contents of the file in place after editor exits."
    exit 1
    }

    function notify {
    if [ $VISUAL_MODE -ne 0 ]; then
    osascript -e "tell app \"System Events\" to display alert \"$1\" with title \"Error\" as critical"
    else
    >&2 echo $1
    fi
    }

    function prompt {
    if [ 4 -gt "$#" ]; then
    title="Prompt"
    yes="Yes"
    no="No"
    else
    title=$2
    yes=$3
    no=$4
    fi

    if [ $VISUAL_MODE -ne 0 ]; then
    set -x
    ascript="tell app \"System Events\" to display dialog \"$1\" with title \"$title\" buttons{\"$yes\", \"$no\"} default button 1 cancel button 2"
    echo $ascript
    osascript -e $ascript #&> /dev/null
    response=$?
    return $(( response ^ 1 ))
    else
    echo -n "$1 [Y/n]"
    read answer
    if [ "$answer" != "${answer#[Nn]}" ] ;then
    return 0
    else
    return 1
    fi
    fi
    }

    # Transform long options to short ones
    for arg in "$@"; do
    shift
    case "$arg" in
    "--visual") set -- "$@" "-v" ;;
    "--prompt") set -- "$@" "-p" ;;
    *) set -- "$@" "$arg"
    esac
    done

    # Default behavior
    VISUAL_MODE=0
    PROMPT_SIGN=0

    # Parse short options
    OPTIND=1
    while getopts "hvp" opt
    do
    case "$opt" in
    "h") usage; exit 0 ;;
    "v") VISUAL_MODE=1 ;;
    "p") PROMPT_SIGN=1 ;;
    "?") print_usage >&2; exit 1 ;;
    esac
    done
    shift $(expr $OPTIND - 1)

    if [ -z "$1" ]; then
    notify "Missing file argument.\n"
    usage
    exit 1
    fi

    TARGET=$1

    if [ $VISUAL_MODE -ne 0 ]; then
    EDITOR_ARGS+=('-g')
    export PINENTRY_USER_DATA=""
    else
    # Force pinentry over terminal
    export PINENTRY_USER_DATA="USE_CURSES=1"
    fi


    $EDITOR $EDITOR_ARGS $TARGET
    editor_rc=$?
    if [ $editor_rc -ne 0 ]; then
    notify "Editor exited with status code: $editor_rc"
    exit 2
    fi

    cp $TARGET $PLAIN_TEMP
    cp_rc=$?

    if [ $cp_rc -ne 0 ]; then
    notify "Failed to copy edited file to: $PLAIN_TEMP"
    exit 3
    fi

    should_sign=1

    if [ $PROMPT_SIGN -ne 0 ]; then
    prompt "Should I sign you message? Refusing saves edits but does not sign." "Sign" "Sign" "Don't Sign"
    should_sign=$?
    fi

    if [ $should_sign -ne 0 ]; then
    gpg --clear-sign -u Lanny --batch --yes --output $CIPHR_TEMP $PLAIN_TEMP
    gpg_rc=$?

    if [ $gpg_rc -ne 0 ]; then
    notify "Signing failed. A temporary plaintext file is stored at: $PLAIN_TEMP"
    exit 4
    fi
    mv $CIPHR_TEMP $TARGET
    else
    mv $PLAIN_TEMP $TARGET
    fi

    exit 0

    The following users say it would be alright if the author of this post didn't die in a fire!
Jump to Top