1 Star 0 Fork 65

j717273419/MLSBS

forked from MickeyBeeHome/MLSBS
暂停
 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
myscript.sh 3.84 KB
一键复制 编辑 原始数据 按行查看 历史
蓝宝石的傻话 提交于 2014-12-15 18:00 . 增加配置文件生成功能
#!/usr/bin/env bash
#! Encoding UTF-8
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
clear;
cn="false"
case $LANG in
zh_CN*) cn="true";;
esac
#获取脚本路劲
ScriptPath=$(cd $(dirname "$0") && pwd)
CONFIG_CREATE(){
declare -a VarLists
declare -a ValueLists
declare -a ExplainLists
ValueLists=("/var/log" "/usr/local" "/tmp")
VarLists=("LogPath" "InstallPath" "DownloadTmp")
$cn && ExplainLists=("日志路径" "安装路径" "缓存路径") || ExplainLists=("Logs" "Install" "Download")
count=0
for var in ${VarLists[@]} ;do
$cn && TmpMsg="请输入需要生成的${ExplainLists[$count]}." || TmpMsg="Please input the path with ${ExplainLists[$count]}."
read -p "$TmpMsg" -t 30 tmpvar
eval ${VarLists[$count]}=${tmpvar:-${ValueLists[$count]}}
echo "========================================================================="
echo "# ${VarLists[$count]}=${tmpvar:-${ValueLists[$count]}} #"
count=$(expr $count + 1)
done
cat > $ScriptPath/config <<eof
#! Encoding UTF-8
#配置参数
#基础路径
InstallPath="/usr/local"
DownloadTmp="/tmp"
LogPath="/var/log"
#程序路径
LibPath="\$ScriptPath/mylib"
FunctionPath="\$ScriptPath/function"
TemplatePath="\$ScriptPath/Template"
MyCronBashPath="\$InstallPath/mybash"
MyBashLogPath="\$LogPath/mybash"
Python2Path="\$ScriptPath/py2script"
#日志路径
InfoLog=\$LogPath/mlsbs_err\$(date +%Y%m%d).log
ErrLog=\$LogPath/mlsbs_info\$(date +%Y%m%d).log
#check system parameter about cpu's core ,ram ,other
#
#收集系统的一些基础参数给其他函数使用
#
SysName=""
SysCount=""
egrep -i "centos" /etc/issue && SysName='centos';
egrep -i "debian" /etc/issue && SysName='debian';
egrep -i "ubuntu" /etc/issue && SysName='ubuntu';
SysBit='32' && [ \$(getconf WORD_BIT) == '32' ] && [ \$(getconf LONG_BIT) == '64' ] && SysBit='64';
CpuNum=\$(cat /proc/cpuinfo |grep 'processor'|wc -l);
RamTotal=$(free -m | grep 'Mem' | awk '{print $2}');
RamSwap=$(free -m | grep 'Swap' | awk '{print $2}');
RamSum=\$[\$RamTotal+\$RamSwap];
FileMax=\$(cat /proc/sys/fs/file-max)
OSlimit=\$(ulimit -n)
SysVer=$(uname -r|cut -d. -f1-2)
eof
}
#加载配置内容
[[ ! -f $ScriptPath/config ]] && CONFIG_CREATE
source $ScriptPath/config
#################错误提示##############################
EXIT_MSG(){
$cn && ExitMsg="$1" || ExitMsg="$2"
echo "$(date +%Y-%m-%d-%H:%M) -ERR $ExitMsg " && exit 1
}
#########普通日志##########
INFO_MSG(){
$cn && InfoMsg="$1" || InfoMsg="$2"
echo "$(date +%Y-%m-%d-%H:%M) -INFO $InfoMsg "
}
#检测脚本文件是否存在并加载
SOURCE_SCRIPT(){
for arg do
if [ ! -f "$arg" ]; then
EXIT_MSG "缺少文件:$arg ,程序无法运行,请重新下载原程序!" "not exist $arg,so $0 can not be supported!"
else
INFO_MSG "正在加载库: $arg ......" "loading $arg now, continue ......"
source $arg
fi
done
}
[[ "$SysName" == '' ]] && EXIT_MSG "程序不支持在此系统上运行。" "Your system is not supported this script"
SOURCE_SCRIPT $LibPath/common
#main
SELECT_RUN_SCRIPT(){
echo "----------------------------------------------------------------"
declare -a VarLists
if $cn ;then
echo "[Notice] 请选择要运行的指令:"
VarLists=("退出" "软件安装" "系统设置" "生成任务")
else
echo "[Notice] Which function you want to run:"
VarLists=("Exit" "Sofeware_Install" "System_Setup" "Create_Cron")
fi
select var in ${VarLists[@]} ;do
case $var in
${VarLists[1]})
SOURCE_SCRIPT $FunctionPath/sofeinstall.sh
SELECT_SOFE_INSTALL;;
${VarLists[2]})
SOURCE_SCRIPT $FunctionPath/system_setup.sh
SELECT_SYSTEM_SETUP_FUNCTION;;
${VarLists[3]})
SOURCE_SCRIPT $LibPath/decryption_encryption $FunctionPath/create_cron.sh
SELECT_ENCRY_FUNCTION
SELECT_CRON_FUNCTION;;
${VarLists[0]})
exit 0;;
*)
SELECT_RUN_SCRIPT;;
esac
break
done
SELECT_RUN_SCRIPT
}
SELECT_RUN_SCRIPT
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wangdongjie/MLSBS.git
git@gitee.com:wangdongjie/MLSBS.git
wangdongjie
MLSBS
MLSBS
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385