diff --git a/Makefile b/Makefile index d67ced2b..7481dcf6 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,13 @@ default: help help: - @echo "minify - makes JavaScript download and run faster" - @echo "lint - checks JavaScript files for style issues" - @echo "test - runs JavaScript unit tests" + @echo "minify - makes JavaScript download and run faster" + @echo "lint - checks JavaScript files for style issues" + @echo "test - runs JavaScript unit tests" + @echo "ext-chr-gmail - creates the Google Chrome / Google Mail extension" + +ext-chr-gmail: + @./scripts/create_extension.sh lint: @echo See http://code.google.com/closure/utilities/ diff --git a/scripts/create_extension.sh b/scripts/create_extension.sh new file mode 100755 index 00000000..8d5a34cf --- /dev/null +++ b/scripts/create_extension.sh @@ -0,0 +1,27 @@ +#!/bin/bash +################################################################################ +# OpenPGP.js browser extension build script +# +# @author Alex +################################################################################ + +echo "Setup..." +dir_extension="plugins/chrome/" +dir_webcode="webmail/googlemail.com/" +dir_target="`mktemp -d browserext.XXX`" +dir_build="build/"; +sh_pack="./scripts/pack.sh" +file_key="resources/openpgpjs.pem" +file_extension="build/openpgpjs.crx" +mkdir -p "$dir_build" + +echo "Copying files..." +cp -R "$dir_extension"/* "$dir_target" +cp -R "$dir_webcode"/* "$dir_target" + +echo "Creating extension..." +$sh_pack "$dir_target" "$file_key" + +echo "Cleaning up..." +rm -rf "$dir_target" +mv "$dir_target".crx "$file_extension" diff --git a/scripts/pack.sh b/scripts/pack.sh new file mode 100755 index 00000000..76db149c --- /dev/null +++ b/scripts/pack.sh @@ -0,0 +1,44 @@ +#!/bin/bash -e +# +# Purpose: Pack a Chromium extension directory into crx format + +if test $# -ne 2; then + echo "Usage: crxmake.sh " + exit 1 +fi + +dir=$1 +key=$2 +name=$(basename "$dir") +crx="$name.crx" +pub="$name.pub" +sig="$name.sig" +zip="$name.zip" +trap 'rm -f "$pub" "$sig" "$zip"' EXIT + +# zip up the crx dir +cwd=$(pwd -P) +(cd "$dir" && zip -qr -9 -X "$cwd/$zip" .) + +# signature +openssl sha1 -sha1 -binary -sign "$key" < "$zip" > "$sig" + +# public key +openssl rsa -pubout -outform DER < "$key" > "$pub" 2>/dev/null + +byte_swap () { + # Take "abcdefgh" and return it as "ghefcdab" + echo "${1:6:2}${1:4:2}${1:2:2}${1:0:2}" +} + +crmagic_hex="4372 3234" # Cr24 +version_hex="0200 0000" # 2 +pub_len_hex=$(byte_swap $(printf '%08x\n' $(ls -l "$pub" | awk '{print $5}'))) +sig_len_hex=$(byte_swap $(printf '%08x\n' $(ls -l "$sig" | awk '{print $5}'))) +( + echo "$crmagic_hex $version_hex $pub_len_hex $sig_len_hex" | xxd -r -p + cat "$pub" "$sig" "$zip" +) > "$crx" +echo "Wrote $crx" + +exit 0