1 Star 0 Fork 4

Jesse.wang/坐公交也用券的脚本分享仓库

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
demo.sh 7.72 KB
一键复制 编辑 原始数据 按行查看 历史
Y 提交于 2020-12-03 22:30 . add mysql cmd
#!/bin/bash
##定义了常用的字体效果及基础功能
##定义字体效果
#红色背景
red_bg='\e[41;33;1m'
#红色字体
red_zt='\e[1;31m'
#绿色背景
green_bg='\033[0;32;1m'
#绿色字体
green_zt='\e[1;32m'
#关闭效果
end='\033[0m'
#字体闪烁
ss='\033[05m'
#消隐
sy='\33[08m'
##常用语句定义区
Entering(){
echo -e "${green_bg}正在进入...${end}\n${red_zt}${1}...${end}"
}
red_z_green_z_info(){
echo -e "${red_zt}${1}:${end}${green_zt}${2}${end}"
}
check(){
echo -e "${red_zt}正在检测${1}...${end}"
}
green_zt(){
echo -e "${green_zt}${1}${end}"
}
red_z_green_z(){
echo -e "${red_zt}${1}${end}${green_zt}${2}${end}${green_zt}${3}${end}"
}
red_z(){
echo -e "${red_zt}${1}${end}"
}
red_bg(){
echo -e "${red_bg}${1}${end}"
}
red_zt_bg(){
echo -e "${red_zt}${1}${end}${red_bg}${2}${end}"
}
input(){
echo -e "${red_zt}${1}${end}"
read $2
}
install_check(){
red_z_green_z_info "安装配置信息确认"
input "当前主机名预配置为: $HOST_NAME\n按回车继续安装" "dd"
}
chek_status(){
if [[ "$1" -eq '0' ]];then
if [[ "$3" -eq 'q' ]];then
return 0
else
red_z_green_z_info "$2" "成功"
fi
return 0
else
status='true'
while $status;do
red_zt_bg "$2" "失败"
err='n'
input "是否停止脚本运行[当前脚本PID: $$]\n输入f忽略该提示" "err"
if [[ "$err" == 'f' ]];then
status='false'
if [[ "$status" == 'false' ]];then
red_z "已跳过该错误:[${2}失败]"
else
status='true'
fi
else
status=true
fi
done
fi
}
disable_firealld(){
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
if [[ -f "/etc/selinux/config" ]];then
sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
fi
if [[ -f "/etc/sysconfig/selinux" ]];then
sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/sysconfig/selinux
fi
}
#服务循环安装
service_install(){
for i in $*;do
red_z_green_z_info "正在安装---->>>>" "${i}\t安装速度根据包的大小及网络而定,请耐心等待"
red_z_green_z_info "当前脚本进程PID---->>>" "$$"
if [[ "$display" -eq 'n' ]];then
$install $i > /dev/null 2>&1
else
$install $i
fi
chek_status "$?" "${i}安装"
done
}
#服务卸载
service_unstall(){
input "即将卸载以下服务:\n$* \n是否全部卸载[y/n]" "re"
for i in $*;do
green_zt "$i"
done
if [[ "$re" == "y" || "$re" == "Y" ]];then
for i in $*;do
red_z_green_z_info "正在卸载---->>>>" "$i"
$unstall $i
chek_status "$?" "${i}卸载"
done
else
input "是否自定义输入卸载[y/n]" "zre"
if [[ "$zre" == "y" || "$zre" == "Y" ]];then
input "请输入需要卸载的包,并以空格分开" "sre"
for i in $sre;do
$unstall $i
done
else
red_z "跳过卸载"
fi
fi
}
#服务启动
service_start(){
systemctl daemon-reload
for i in $*;do
systemctl restart $i
chek_status "$?" "${i}服务启动"
systemctl enable $i > /dev/null
chek_status "$?" "${i}设置服务开机启动"
done
}
service_stop(){
for i in $*;do
systemctl stop $i
chek_status "$?" "${i}服务关闭"
systemctl disable $i > /dev/null
chek_status "$?" "${i}关闭开机启动"
done
}
service_chek(){
red_z_green_z_info "正在检查" "$1"
ser=`$local_search | grep $1`
if [[ -n "$ser" ]];then
input "检测到本机已安装[$1]相关服务,请选择一个操作\n[1]跳过此服务[默认选项]\n[2]卸载该服务" db_remove
if [[ "$db_remove" == '2' ]];then
service_unstall "$ser"
else
red_z_green_z_info "跳过卸载" "$1"
db_init='y'
fi
fi
}
cmd(){
for i in $*;do
red_z_green_z_info "正在执行" "$i"
$i
chek_status "$1" "执行"
done
}
Version_Check(){
if [[ -n "$1" ]];then
red_z_green_z "系统版本检测:" "[SCUUESS]"
else
red_zt_bg "系统版本:" "[FAILD]"
exit 1
fi
}
Check_Network(){
check "网络连接"
ping baidu.com -c 5 > /dev/null
chek_status "$?" "DNS配置"
}
Check_IP(){
iP_s=`hostname -I | head -n1 | awk -F ' ' '{print NF}'`
if [[ "$iP_s" -eq '1' ]];then
local_ip=`hostname -I`
else
ip_list=`hostname -I`
local_ip=`hostname -I | awk '{print $2}'`
red_z_green_z_info "请选择一个业务IP,回车启用默认" "[ $local_ip ]"
for i in $ip_list;do
red_z "$i"
done
read select_ip
if [[ -n "$select_ip" ]];then
for i in $local_ip;do
if [[ "select" -eq "$i" ]];then
local_ip=$select_ip
else
red_z_green_z_info "输入的IP地址与本机IP地址不符,已启用默认IP"
fi
done
else
red_z_green_z_info "输入的IP地址与本机IP地址不符,已启用默认IP[ $local_ip ]"
fi
fi
}
Loading_function(){
for i in $*;do
if [[ -f "$i" ]];then
source $i
chek_status "$?" "加载功能文件[ $i ]" 'q'
else
red_bg "找不到功能文件[ $i ]"
fi
done
green_zt "全部功能加载完成"
}
item='yes'
##获取Debian系统的版本信息
get_os_info_os-Debian-OS-Version(){
unset System_version
System_version=`grep VERSION_ID /etc/os-release | sed -e 's/VERSION_ID=//' -e 's/\"//g'`
# for i in $*;do
# if [[ "$s" -eq "$i" ]];then
# Version_Number=$i
# fi
# done
}
##获取CentOS系统的版本信息
get_os_info_os-Centos-OS-Version(){
unset System_version
# s=`cat /etc/os-release | grep ^ID= | sed -e 's/ID=//' -e 's/\"//g'`
# for i in $*;do
# if [[ "$s" -eq "$i" ]];then
# Version_Number=$i
# fi
# done
System_version=`cat /etc/os-release | grep VERSION_ID | sed -e 's/VERSION_ID=//' -e 's/\"//g'`
}
get_os_info_os-Type(){
# for type in $*;do
System_Type=`cat /etc/os-release | grep ^ID= | sed -e 's/ID=//' -e 's/\"//g'`
if [[ "${System_Type}" == "$type" ]];then
os_check='y'
fi
if [[ ${System_Type} -eq 'centos' ]];then
get_os_info_os-Centos-OS-Version
elif [[ ${System_Type} -eq 'debian' ]];then
get_os_info_os-Debian-OS-Version
fi
# done
if [[ "$os_check" -eq 'y' ]];then
red_z_green_z "当前系统类型" "支持"
else
red_zt_bg "当前系统类型" "不支持"
exit 11
fi
}
get_os_info_os-Package-management(){
if [[ -f '/usr/bin/apt' ]];then
local_install='dpkg'
Package_management='apt'
Package_managements='apt'
local_search="apt list --installed "
elif [[ -f '/usr/bin/yum' ]];then
yum --version > /dev/null
if [[ "$?" -eq '0' ]];then
Package_management='yum'
Package_managements='yum'
if [[ -f '/usr/bin/dnf' ]];then
dnf --version > /dev/null
if [[ "$?" -eq '0' ]];then
Package_management='dnf'
fi
fi
local_search='rpm -qa '
else
red_zt_bg "包管理器[ yum ]" "出现意外"
exit 11
fi
local_install='rpm'
else
red_zt_bg "无法判断当前系统使用的包管理器"
exit 11
fi
export install="${Package_management} install -y"
export unstall="${Package_management} remove -y"
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Shell
1
https://gitee.com/Jesse_wang01/zgj_toutiao.git
git@gitee.com:Jesse_wang01/zgj_toutiao.git
Jesse_wang01
zgj_toutiao
坐公交也用券的脚本分享仓库
master

搜索帮助