-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 移除了 子模块 - 将 子模块脚本 转到到了 Common 目录中 - 优化了 子模块脚本
- Loading branch information
Showing
12 changed files
with
198 additions
and
13 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/bash | ||
|
||
############### | ||
# Name: 批量路径复制脚本 | ||
# Author: ZhangTianJie | ||
# Email: [email protected] | ||
# Params: <BatchCopyPaths>[ArrayString](SrcPath=>DistPath) | ||
# Return=0: success | ||
# Return=!0: failure, failed index | ||
############### | ||
|
||
### 定义帮助文本 | ||
if [ "${1}" == "help" ]; then | ||
echo ">>> Params: <BatchCopyPaths>[ArrayString](SrcPath=>DistPath)" | ||
echo ">>> Return=0: success" | ||
echo ">>> Return=!0: failure, failed index" | ||
exit 0 | ||
fi | ||
|
||
### 设置变量 | ||
[ -z "${BatchCopyPaths}" ] && BatchCopyPaths=(${*}) | ||
|
||
### 判断是否定义了路径 | ||
if [ "${BatchCopyPaths[*]}" == "" ]; then | ||
echo ">>>>> Error: the var <BatchCopyPaths> does not exist" | ||
exit 1 | ||
fi | ||
|
||
### 循环数组 | ||
for i in ${!BatchCopyPaths[@]} | ||
do | ||
Path=${BatchCopyPaths[$i]} | ||
SrcPath=${Path%=>*} | ||
DistPath=${Path#*=>} | ||
### 跳过不存在路径 | ||
if [ "${SkipNotExist}" == "yes" ]; then | ||
if [ ! -e ${SrcPath%\*} ]; then | ||
continue | ||
fi | ||
if [ ! -e ${DistPath} ]; then | ||
continue | ||
fi | ||
fi | ||
### 复制文件 | ||
sudo \cp -fR ${Path%=>*} ${Path#*=>} | ||
if [ $? -ne 0 ]; then | ||
echo ">>>>> Error: copy <${Path}> error" | ||
exit $(($i+1)) | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash | ||
|
||
############### | ||
# Name: 获取第一个存在的路径 | ||
# Params: <Path Path...> 路径 | ||
# author: ZhangTianJie | ||
# email: [email protected] | ||
############### | ||
function getFirstExistPath () { | ||
for Path in ${*} | ||
do | ||
[ -e "${Path}" ] && echo "${Path}" && return 0 | ||
done | ||
return 1 | ||
} | ||
|
||
############### | ||
# Name: 获取字符串数组元素 | ||
# Params 1: <String> 字符串 | ||
# Params 2: <Delimiter> 定界符 | ||
# Params 3: <Index> 索引 | ||
# author: ZhangTianJie | ||
# email: [email protected] | ||
############### | ||
function getStringArrayItem () { | ||
Str=${1} | ||
Delimiter=${2} | ||
Index=${3} | ||
Arr=(${Str//$Delimiter/ }) | ||
echo ${Arr[$Index]} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/bash | ||
|
||
############### | ||
# Name: 路径备份 | ||
# Author: ZhangTianJie | ||
# Email: [email protected] | ||
# Params: <OriginalPath>(FilePath|DirPath|Required) | ||
# Params: <TargetPath|Optional>(DirPath) | ||
# Params: <PathAlias|Optional>(FileName|DirName) | ||
# Return=0: success | ||
# Return=1: failure | ||
# Output: error message | ||
############### | ||
|
||
### 定义帮助文本 | ||
if [ "${1}" == "help" ]; then | ||
echo ">>> Params: <OriginalPath>(FilePath|DirPath|Required)" | ||
echo ">>> Params: <TargetPath|Optional>(DirPath)" | ||
echo ">>> Params: <PathAlias|Optional>(FileName|DirName)" | ||
echo ">>> Return=0: success" | ||
echo ">>> Return=1: failure" | ||
echo ">>> Output: error message" | ||
exit | ||
fi | ||
|
||
### 设置变量 | ||
[ -z "${OriginalPath}" ] && OriginalPath="${1}" | ||
[ -z "${TargetPath}" ] && TargetPath="${2}" | ||
[ -z "${PathAlias}" ] && PathAlias="${3}" | ||
|
||
### 处理变量 | ||
[ -z "${TargetPath}" ] && TargetPath=$(dirname "${OriginalPath}") | ||
[ -z "${PathAlias}" ] && PathAlias=$(basename "${OriginalPath}") | ||
|
||
### 判断变量 | ||
if [ ! -f "${OriginalPath}" ] && [ ! -d "${OriginalPath}" ]; then | ||
echo ">>>>> Error: the var <OriginalPath> does not exist" | ||
exit 1 | ||
fi | ||
|
||
### 备份原始文件 | ||
if [ ! -f "${TargetPath}/${PathAlias}.bak" ] && [ ! -d "${TargetPath}/${PathAlias}.bak" ]; then | ||
sudo cp -fR "${OriginalPath}" "${TargetPath}/${PathAlias}.bak" | ||
fi | ||
|
||
### 按日期备份 | ||
DateTime=`date +%Y-%m-%d-%H-%M-%S` | ||
sudo cp -fR "${OriginalPath}" "${TargetPath}/${PathAlias}.bak.${DateTime}" | ||
[ $? -ne 0 ] && echo ">>>>> Error: backup <${OriginalPath}> error" && exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/bin/bash | ||
|
||
############### | ||
# Name: 简单模板引擎 | ||
# Author: ZhangTianJie | ||
# Email: [email protected] | ||
# Params: <TplContent>[TplString|FilePath|Required] | ||
# Params: <OutFile>[FilePath] | ||
# Return=0: success | ||
# Return=1: failure | ||
# Output: result content OR error message | ||
############### | ||
|
||
### 定义帮助文本 | ||
if [ "${1}" == "help" ]; then | ||
echo ">>> Params: <TplContent>[TplString|FilePath|Required]" | ||
echo ">>> Params: <OutFile>[FilePath]" | ||
echo ">>> Return=0: success" | ||
echo ">>> Return=1: failure" | ||
echo ">>> Output: result content OR error message" | ||
exit 0 | ||
fi | ||
|
||
### 设置变量 | ||
[ -z "${TplContent}" ] && TplContent="${1}" | ||
[ -z "${TplOutFile}" ] && TplOutFile="${2}" | ||
[ -z "${TplVars}" ] && TplVars=("${@:3}") | ||
|
||
### 设置模板变量 | ||
if [ "${TplVars[*]}" != "" ]; then | ||
for VarString in ${TplVars[@]} | ||
do | ||
eval ${VarString} | ||
done | ||
fi | ||
|
||
### 判断是否设置了模板内容变量 | ||
[ -f "${TplContent}" ] && TplContent=$(cat ${TplContent}) | ||
[ "${TplContent}" == "" ] && echo ">>>>> Error: the var <TplContent> does not exist" && exit 1 | ||
|
||
### 替换所有的 $ 为 \$ | ||
TplContent=${TplContent//\$/\\\$} | ||
|
||
### 将所有的变量和语句中的 \$ 替换 $ | ||
TplContent=$(echo "${TplContent}" | sed -E '/<[%|{]=.+?=[%|}]>/ s/\\\$/$/g') | ||
|
||
### 替换所有的非语句中的 " 为 \" | ||
TplContent=$(echo "${TplContent}" | sed -e '/^<{=/! s/\"/\\\"/g') | ||
|
||
### 将所有的非语句 echo 一下 | ||
TplContent=$(echo "${TplContent}" | sed -e '/^<{=/! s/^.*$/echo "&"/') | ||
|
||
### 替换掉所有的模板标签 | ||
TplContent=$(echo "${TplContent}" | sed -e 's/<{=\|=}>\|<%=\|=%>//g') | ||
|
||
### 执行字符串 | ||
TplContent=$(eval "${TplContent}") | ||
|
||
[ "${TplOutFile}" != "" ] && echo "${TplContent}" | sudo tee ${TplOutFile} |
Submodule CommonShell
deleted from
aac148
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters