Minimal Chrome extension (8ko) that output the content of clipboard to a new tab

pack 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/bash -e
  2. #
  3. # Purpose: Pack a Chromium extension directory into crx format
  4. if test $# -ne 2; then
  5. echo "Usage: crxmake.sh <extension dir> <pem path>"
  6. exit 1
  7. fi
  8. min="$1"_tmp
  9. dir=$1
  10. key=$2
  11. name="PasteTab"
  12. crx="$name.crx"
  13. pub="$name.pub"
  14. sig="$name.sig"
  15. zip="$name.zip"
  16. trap 'rm -f "$pub" "$sig" "$zip"' EXIT
  17. # recursively minify js and css
  18. # zip up the crx dir
  19. cwd=$(pwd -P)
  20. (cd "$dir" && zip -qr -9 -X "$cwd/$zip" .)
  21. # signature
  22. openssl sha1 -sha1 -binary -sign "$key" < "$zip" > "$sig"
  23. # public key
  24. openssl rsa -pubout -outform DER < "$key" > "$pub" 2>/dev/null
  25. byte_swap () {
  26. # Take "abcdefgh" and return it as "ghefcdab"
  27. echo "${1:6:2}${1:4:2}${1:2:2}${1:0:2}"
  28. }
  29. crmagic_hex="4372 3234" # Cr24
  30. version_hex="0200 0000" # 2
  31. pub_len_hex=$(byte_swap $(printf '%08x\n' $(ls -l "$pub" | awk '{print $5}')))
  32. sig_len_hex=$(byte_swap $(printf '%08x\n' $(ls -l "$sig" | awk '{print $5}')))
  33. (
  34. echo "$crmagic_hex $version_hex $pub_len_hex $sig_len_hex" | xxd -r -p
  35. cat "$pub" "$sig" "$zip"
  36. ) > "$crx"
  37. echo "Wrote $crx"