Signing Files Recursively Using GnuPG

GnuPG is a great privacy tool; it makes sure that the software distribution you deployed is identical with what you deployed originally. In the Apache Software Foundation, committers have to sign all their distributions before they are mirrored to other servers such as Ibiblio.org for security reasons. However, signing each file one by one takes too much time. There has to be an easier way, and I created a shell script which signs all files recursively in one shot.

GnuPG는 훌륭한 프라이버시 툴입니다. 이것을 사용하면 업로드한 소프트웨어 배포본이 정말 여러분이 배포한 것과 일치하는지 확인할 수 있습니다. 아파치 소프트웨어 재단에서는 보안상의 이유로 개발자가 모든 소프트웨어 배포본에 서명하기 전까지는 Ibiblio.org와 같은 다른 서버로 미러링이 되지 않습니다. 그러나, 각각의 파일을 하나 하나 서명하는 것은 시간이 너무 오래 걸립니다. 좀 더 쉬운 방법이 있어야 할 것 같아서 한 방에 서브디렉토리에 있는 모든 파일을 서명하는 쉘 스크립트를 작성했습니다.

#!/bin/sh

DEFAULT_KEY=”[email protected]

echo -n “PGP Key Password: “
stty -echo
read PASSWORD
stty echo
echo “”

for FILE in $(find . -not ‘(‘ -name “*.md5″ -or -name “*.sha1″ -or -name “*.asc” ‘)’ -and -type f) ; do
    if [ -f “$FILE.asc” ]; then
        echo “Skipping: $FILE”
        continue
    fi

    echo -n “Signing: $FILE … “

    md5sum “$FILE” | cut “-d ” -f1 > “$FILE.md5″
    sha1sum “$FILE” | cut “-d ” -f1 > “$FILE.sha1″

    echo “$PASSWORD” | gpg –default-key “$DEFAULT_KEY” –detach-sign –armor –no-tty –yes –passphrase-fd 0 “$FILE” && echo done.
done