vault backup: 2024-09-11 17:31:33

This commit is contained in:
BlueRose 2024-09-11 17:31:33 +08:00
parent 302bd76712
commit c45f0b36f9

View File

@ -725,6 +725,153 @@ Triggers:
PS.***脚本内部的换行符需要跟换成unix的***
### Trigger Example
[P4服务器部署、配置、备份流程详解](https://zhuanlan.zhihu.com/p/676332084)
on_create_workspace.sh创建工作区自动填写设置。
```bash
workspacename=$1
workspacefile=$2
p4="p4 -u perforce_trigger"
$p4 trust -fy >/dev/null 2>&1
if [ -z "$($p4 clients -e $workspacename)" ]; then
sed -i '/Options:/{s/noallwrite/allwrite/g}' $workspacefile
sed -i '/Options:/{s/noclobber /clobber /g}' $workspacefile
if grep -q "^SubmitOptions:" $workspacefile; then
sed -i 's/^SubmitOptions:.*/SubmitOptions: leaveunchanged/' $workspacefile
else
echo "SubmitOptions: leaveunchanged" >> $workspacefile
fi
if grep -q "^LineEnd:" $workspacefile; then
sed -i 's/^LineEnd:.*/LineEnd: unix/' $workspacefile
else
echo "LineEnd: unix" >> $workspacefile
fi
fi
```
check_case_conflict.sh大小写检查
```bash
#!/bin/bash
changelist=$1
p4="p4 -p 127.0.0.1:1666 -u perforce_trigger"
pending_files=($($p4 opened -s -c $changelist | awk '{print $1}'))
canSubmit=0
function p4_user_login()
{
$p4 login -s ${@:2} "$1" 2>/dev/null | grep -q ^//
}
if p4_user_login; then
echo nswl123456|$p4 -u perforce_trigger login
fi
function p4_file_exist()
{
$p4 files -e ${@:2} "$1" 2>/dev/null | grep -q ^//
}
function p4_path_exist()
{
$p4 dirs ${@:2} "$1" 2>/dev/null | grep -q ^//
}
function check_changelist_file_conflict()
{
local file=$1
local pending_list=(${@:2})
local message=
for other_file in ${pending_list[@]}; do
if [ $file != $other_file ] && [ ${file,,} == ${other_file,,} ]; then
message="$message\n$other_file"
fi
done
if [ "$message" ]; then
message="Changelist File Case Conflict(提交队列大小写冲突:文件):$message"
printf "$message"
fi
}
function check_changelist_path_conflict()
{
local path=$(dirname $1)
local pending_list=(${@:2})
local message=
while [ $path != '/' ]; do
for i in ${!pending_list[@]}; do
local other_file=${pending_list[$i]}
if [[ "$other_file" != "$path"* ]] && [[ "${other_file,,}" == "${path,,}"* ]]; then
message="$message\n$other_file"
unset "pending_list[$i]"
fi
done
path=$(dirname $path)
done
if [ "$message" ]; then
message="Changelist Path Case Conflict(提交队列大小写冲突:路径):$message"
printf "$message"
fi
}
for file in ${pending_files[@]}; do
# Check File Case Conflicted Or Not
canSubmit=0
message=
if ! p4_file_exist $file && p4_file_exist $file -i; then
#===== Output Error Message =====#
message="$message\nDepot File Case Conflicted (仓库大小写冲突:文件):\n$($p4 files -i "$file")"
#================================#
fi
# Check Path Case Conflicted Or Not
path=$(dirname $file)
while [ $path != '/' ]
do
if ! p4_path_exist $path && p4_path_exist $path -i; then
#===== Output Error Message =====#
message="$message\nDepot Path Case Conflicted (仓库大小写冲突:路径):\n$($p4 dirs -i "$path")"
#================================#
break
fi
path=$(dirname $path)
done
temp_message=$(check_changelist_file_conflict "$file" "${pending_files[@]}")
if [ "$temp_message" ]; then
message="$message\n$temp_message"
fi
temp_message=$(check_changelist_path_conflict "$file" "${pending_files[@]}")
if [ "$temp_message" ]; then
message="$message\n$temp_message"
fi
if [ "$message" ]; then
canSubmit=1
message="File(文件):\n$file\n$message"
printf "\n==============================\n$message\n==============================\n"
fi
done
exit $canSubmit
```
```text
on_create_workspace form-out client "/p4/triggers/on_create_workspace.sh %formname% %formfile%"
check_case_conflict change-submit //... "/p4/triggers/check_case_conflict.sh %changelist%"
```
### 自动登录命令
```
echo password|p4 -u user login