仅使用命令行界面在服务器上打包Chrome扩展程序

问题描述 投票:10回答:2

是否可以使用CLI(Ubuntu-server)在服务器上使用密钥(* .pem)打包chrome扩展?

google-chrome-extension continuous-integration
2个回答
13
投票

https://developer.chrome.com/extensions/crx#scripts上列出了官方包装脚本 - 一个在Bash中,一个在Ruby中。谷歌现在希望他们为网上商店打包应用程序。但是,如果您是自托管,这些脚本仍然有用。

由于该网站不再有效,这里是bash脚本:

#!/bin/bash -e
#
# Purpose: Pack a Chromium extension directory into crx format

if test $# -ne 2; then
  echo "Usage: crxmake.sh <extension dir> <pem path>"
  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"

8
投票

您可以使用--pack-extension中描述的应用程序开关--pack-extension-keydocumentation

基本上,在Windows上,您将在终端中运行以下命令:

chrome.exe --pack-extension=c:\myext --pack-extension-key=c:\myext.pem

它适用于Mac以及:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --pack-extension=./myext --pack-extension-key=./myext.pem

在Ubuntu上应该是类似的。

退出--pack-extension-key将自动为您创建一个密钥。

© www.soinside.com 2019 - 2024. All rights reserved.