perf: 优化脚本

This commit is contained in:
kuaifan 2025-03-07 16:18:06 +08:00
parent 3e2a40aaa0
commit c866500120
4 changed files with 87 additions and 14 deletions

View File

@ -299,7 +299,7 @@ jobs:
env:
PUBLISH_KEY: ${{ secrets.PUBLISH_KEY }}
run: |
pushd electron
pushd electron || exit
npm install
popd
popd || exit
node ./electron/build.js published

11
cmd
View File

@ -156,9 +156,9 @@ run_electron() {
npm install
fi
if [ ! -d "./electron/node_modules" ]; then
pushd electron
pushd electron || exit
npm install
popd
popd || exit
fi
#
if [ -d "./electron/dist" ]; then
@ -178,8 +178,9 @@ run_electron() {
run_exec() {
local container=$1
local cmd=$2
local name=`docker_name $container`
shift 1
local cmd=$@
local name=$(docker_name "$container")
if [ -z "$name" ]; then
error "没有找到 $container 容器!"
exit 1
@ -561,7 +562,7 @@ if [ $# -gt 0 ]; then
success "修改成功"
elif [[ "$1" == "repassword" ]]; then
shift 1
run_exec mariadb "sh /etc/mysql/repassword.sh \"$@\""
run_exec mariadb "sh /etc/mysql/repassword.sh $@"
elif [[ "$1" == "serve" ]] || [[ "$1" == "dev" ]] || [[ "$1" == "development" ]]; then
shift 1
run_compile dev

0
docker/es/data/.gitignore vendored Normal file → Executable file
View File

View File

@ -1,27 +1,99 @@
#!/bin/sh
#
# 重置用户密码脚本
#
# 使用方法:
# ./repassword.sh [账号标识符] [自定义密码]
#
# 参数说明:
# [账号标识符]: 可选可以是用户ID(纯数字)或邮箱地址。不提供时默认为第一个管理员用户
# [自定义密码]: 可选,指定要设置的新密码。不提供时会自动生成随机密码
#
# 使用示例:
# ./repassword.sh # 重置第一个管理员用户密码(随机生成)
# ./repassword.sh 123 # 重置ID=123的用户密码(随机生成)
# ./repassword.sh user@example.com # 重置邮箱为user@example.com的用户密码(随机生成)
# ./repassword.sh 123 newpass # 重置ID=123的用户密码为"newpass"
# ./repassword.sh user@example.com newpass # 重置邮箱为user@example.com的用户密码为"newpass"
#
new_password=$1
account_identifier=$1
custom_password=$2
GreenBG="\033[42;37m"
RedBG="\033[41;37m"
Font="\033[0m"
# 生成随机密码
new_encrypt=$(date +%s%N | md5sum | awk '{print $1}' | cut -c 1-6)
if [ -z "$new_password" ]; then
if [ -z "$custom_password" ]; then
new_password=$(date +%s%N | md5sum | awk '{print $1}' | cut -c 1-16)
else
new_password=$custom_password
fi
md5_password=$(echo -n `echo -n $new_password | md5sum | awk '{print $1}'`$new_encrypt | md5sum | awk '{print $1}')
content=$(echo "select \`email\` from ${MYSQL_PREFIX}users where \`userid\`=1;" | mysql -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE)
account=$(echo "$content" | sed -n '2p')
# 构建查询条件
if [ -z "$account_identifier" ]; then
# 默认查询第一个管理员
admin_query=$(echo "SELECT userid FROM ${MYSQL_PREFIX}users WHERE identity LIKE '%,admin,%' ORDER BY userid LIMIT 1;" | mysql -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE)
identifier_value=$(echo "$admin_query" | sed -n '2p')
if [ -z "$identifier_value" ]; then
echo "${RedBG}错误:未找到管理员用户!${Font}"
exit 1
fi
where_field="userid"
identifier_type="管理员ID"
else
# 检查是否为纯数字ID
# 使用更兼容的 shell 语法检查是否为纯数字
case "$account_identifier" in
''|*[!0-9]*)
# 非纯数字,视为邮箱
where_field="email"
identifier_type="邮箱"
identifier_value="$account_identifier"
;;
*)
# 纯数字视为ID
where_field="userid"
identifier_type="ID"
identifier_value="$account_identifier"
;;
esac
fi
# 构建 WHERE 条件(为邮箱添加引号)
if [ "$where_field" = "email" ]; then
where_condition="where $where_field='$identifier_value'"
else
where_condition="where $where_field=$identifier_value"
fi
# 查询用户信息
content=$(echo "select userid,email from ${MYSQL_PREFIX}users $where_condition;" | mysql -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE)
# 提取用户ID和邮箱
user_id=$(echo "$content" | sed -n '2p' | awk '{print $1}')
account=$(echo "$content" | sed -n '2p' | awk '{print $2}')
if [ -z "$account" ]; then
echo "错误:账号不存在!"
echo "${RedBG}错误:${identifier_type} '${identifier_value}' 的账号不存在!${Font}"
exit 1
fi
# 更新密码
mysql -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE <<EOF
update ${MYSQL_PREFIX}users set \`encrypt\`='${new_encrypt}',\`password\`='${md5_password}' where \`userid\`=1;
update ${MYSQL_PREFIX}users set encrypt='${new_encrypt}',password='${md5_password}' $where_condition;
EOF
echo "账号: ${GreenBG}${account}${Font}"
# 只在 identifier_type="ID" 时才输出ID
if [ "$identifier_type" = "ID" ]; then
echo "ID: ${GreenBG}${user_id}${Font}"
fi
# 输出邮箱和密码
echo "邮箱: ${GreenBG}${account}${Font}"
echo "密码: ${GreenBG}${new_password}${Font}"