wechat-web-devtools-linux/tools/setup-wechat-devtools-bash
2022-03-06 22:53:54 +08:00

88 lines
2.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
set -e # 命令出错就退出
trap 'catchError $LINENO $BASH_COMMAND' SIGHUP SIGINT SIGQUIT EXIT # 捕获错误情况
catchError() {
exit_code=$?
if [ $exit_code -ne 0 ]; then
fail "\033[31mcommand: $2\n at $0:$1\n at $STEP\033[0m"
fi
exit $exit_code
}
success() {
echo -e "\033[42;37m 成功 \033[0m $1"
}
fail() {
echo -e "\033[41;37m 失败 \033[0m $1"
}
root_dir=$(cd `dirname $0`/.. && pwd -P)
echo "==========Initializing node=========="
if [ -f "$root_dir/node/bin/node" ]; then
success "node安装完毕"
else
node "$root_dir/tools/update-node-node"
success "node ok"
fi
if [ ! -f "$root_dir/node/bin/node" ]; then
fail "Node安装失败"
exit
fi
# 将node加入环境
export PATH="$root_dir/node/bin":$PATH
echo "=====安装node-gyp nw-gyp===="
npm uninstall node-gyp -g
npm install node-gyp nw-gyp npm -g --registry=https://registry.npm.taobao.org
node-gyp install
node-gyp list
echo "==========Initializing nwjs=========="
if [ -f "$root_dir/nwjs/nw" ]; then
success "nwjs安装完毕"
else
node "$root_dir/tools/update-nwjs-node"
fi
# 7z旧版本解压不正常
# rm -rf "$root_dir/tmp/7z"
# mkdir -p "$root_dir/tmp/7z"
# cd "$root_dir/tmp/7z"
# wget https://www.7-zip.org/a/7z2107-linux-x64.tar.xz
# tar -xJf 7z2107-linux-x64.tar.xz
# ln -s 7zz 7z
# export PATH="$root_dir/tmp/7z:$PATH"
echo "==========Initializing wechat-devtools package=========="
if [[ $@ == *version* ]];then
# 参数有版本号优先级高清空TARGET_VERSION
echo "参数有版本号"
TARGET_VERSION=""
else
# 参数没有版本号,获取
echo "参数没有版本号"
TARGET_VERSION="version="$( cat "$root_dir/conf/devtools_v")
fi
echo "TARGET_VERSION: $TARGET_VERSION"
if [ ! -f "$root_dir/package.nw/package.json" ];then
# 没装,直接装
node "$root_dir/tools/update-wechat-devtools-node" $TARGET_VERSION $@
exit 0
fi
# 装了,获取已安装版本
DEVTOOLS_VERSION=$( cat "$root_dir/package.nw/package.json" | grep -m 1 -Eo "\"[0-9]{1}\.[0-9]{2}\.[0-9]+" )
DEVTOOLS_VERSION="${DEVTOOLS_VERSION//\"/}"
# 已安装, 比较目标版本
if [ "$TARGET_VERSION" == "$DEVTOOLS_VERSION" ];then
success "微信开发者工具安装完毕"
exit 0
fi
node "$root_dir/tools/update-wechat-devtools-node" $TARGET_VERSION $@