diff --git a/README.md b/README.md index 94d4e80..0e1fe8a 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,15 @@ ### Prerequisites -Operating System: Linux amd64 +Operating System: Linux amd64/aarch64, MacOS x86_64/arm64 + +**Notes**: The script uses `yum` to install `unzip` which is only avialable on RPM-based Linux systems(such as `Red Hat Enterprise Linux`, `CentOS`, `Fedora`, and `Oracle Linux`), and is now replaced by `dnf` in latest version. To use the script on other distributions, please install `unzip` command in advance. + +**注意:**本脚本使用`yum`安装`unzip`命令,这只适用于基于RPM的Linux系统(如`Red Hat Enterprise Linux`, `CentOS`, `Fedora`, and `Oracle Linux`)。并且在较新的分发版中,它已被`dnf`所替代。 +因此,当使用其他Linux分发版或者无法使用`yum`时,请事先安装`unzip`命令。 + +Python version: Should be as the same as the version in `dify-plugin-daemon` which is currently 3.12.x -Requires Python version is 3.11 or higher #### Clone ```shell @@ -60,7 +66,13 @@ git clone https://github.com/junjiem/dify-plugin-repackaging.git ![db_query](images/db_query.png) +#### Platform Crossing Repacking +For repacking the plugins in different platforms between operating and running environment, +please using `-p` option with a pip platform string. + +Typically, uses `manylinux2014_x86_64` for plugins running on an `x86_64/amd64` OS, +and `manylinux2014_aarch64` for `aarch64/arm64`. ### Update Dify platform env Dify平台放开限制 @@ -89,9 +101,3 @@ Visit the Dify platform's plugin management page, choose Local Package File to c ![install_plugin_via_local](./images/install_plugin_via_local.png) - - -### Star history - -[![Star History Chart](https://api.star-history.com/svg?repos=junjiem/dify-plugin-repackaging&type=Date)](https://star-history.com/#junjiem/dify-plugin-repackaging&Date) - diff --git a/dify-plugin-darwin-amd64-5g b/dify-plugin-darwin-amd64-5g new file mode 100755 index 0000000..14aee34 Binary files /dev/null and b/dify-plugin-darwin-amd64-5g differ diff --git a/dify-plugin-darwin-arm64-5g b/dify-plugin-darwin-arm64-5g new file mode 100755 index 0000000..7c99ed2 Binary files /dev/null and b/dify-plugin-darwin-arm64-5g differ diff --git a/plugin_repackaging.sh b/plugin_repackaging.sh index 70c3d43..a5d94c7 100644 --- a/plugin_repackaging.sh +++ b/plugin_repackaging.sh @@ -14,12 +14,16 @@ cd $CURR_DIR CURR_DIR=`pwd` USER=`whoami` ARCH_NAME=`uname -m` +OS_TYPE=$(uname) +OS_TYPE=$(echo "$OS_TYPE" | tr '[:upper:]' '[:lower:]') -CMD_NAME="dify-plugin-linux-amd64-5g" +CMD_NAME="dify-plugin-${OS_TYPE}-amd64-5g" if [[ "arm64" == "$ARCH_NAME" || "aarch64" == "$ARCH_NAME" ]]; then - CMD_NAME="dify-plugin-linux-arm64-5g" + CMD_NAME="dify-plugin-${OS_TYPE}-arm64-5g" fi +PIP_PLATFORM="" + market(){ if [[ -z "$2" || -z "$3" || -z "$4" ]]; then echo "" @@ -105,14 +109,27 @@ repackage(){ echo "Unzip success." echo "Repackaging ..." cd ${CURR_DIR}/${PACKAGE_NAME} - pip download -r requirements.txt -d ./wheels --index-url ${PIP_MIRROR_URL} + pip download ${PIP_PLATFORM} -r requirements.txt -d ./wheels --index-url ${PIP_MIRROR_URL} --trusted-host mirrors.aliyun.com if [[ $? -ne 0 ]]; then echo "Pip download failed." exit 1 fi - sed -i '1i\--no-index --find-links=./wheels/' requirements.txt + if [[ "linux" == "$OS_TYPE"]]; then + sed -i '1i\--no-index --find-links=./wheels/' requirements.txt + elif [[ "darwin" == "$OS_TYPE"]]; then + sed -i ".bak" '1i\ +--no-index --find-links=./wheels/ + ' requirements.txt + rm -f requirements.txt.bak + fi + if [ -f .difyignore ]; then - sed -i '/^wheels\//d' .difyignore + if [[ "linux" == "$OS_TYPE"]]; then + sed -i '/^wheels\//d' .difyignore + elif [[ "darwin" == "$OS_TYPE"]]; then + sed -i ".bak" '/^wheels\//d' .difyignore + rm -f .difyignore.bak + fi fi cd ${CURR_DIR} chmod 755 ${CURR_DIR}/${CMD_NAME} @@ -131,6 +148,20 @@ install_unzip(){ fi } +print_usage() { + echo "usage: $0 [-p platform] {market|github|local}" + echo "-p platform: python packages' platform. Using for crossing repacking." + exit 1 +} + +while getopts "p:" opt; do + case "$opt" in + p) PIP_PLATFORM="--platform ${OPTARG} --only-binary=:all:"; shift $((OPTIND - 1)) ;; + *) print_usage; exit 1 ;; + esac +done + +echo "$1" case "$1" in 'market') market $@ @@ -143,7 +174,7 @@ case "$1" in ;; *) -echo "usage: $0 {market|github|local}" +print_usage exit 1 esac exit 0