概述
分享一个简单的脚本,可以实现linux服务器一键设置语言为中文,支持以下系统:
Debian 8 / 9
Ubuntu 14 / 16
CentOS 6 / 7
1、脚本内容
注意需要联网才可以。#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH
# Check System Release
if [ -f /etc/redhat-release ]; then
release="centos"
elif cat /etc/issue | grep -Eqi "debian"; then
release="debian"
elif cat /etc/issue | grep -Eqi "ubuntu"; then
release="ubuntu"
elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then
release="centos"
elif cat /proc/version | grep -Eqi "debian"; then
release="debian"
elif cat /proc/version | grep -Eqi "ubuntu"; then
release="ubuntu"
elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then
release="centos"
fi
# Check root
[[ $EUID -ne 0 ]] && echo -e "${RED}Error:${PLAIN} This script must be run as root!" && exit 1
# Install some dependencies
if [ "${release}" == "centos" ]; then
\tyum -y install wget ca-certificates locales localedef
else
\tapt-get update
\tapt-get -y install wget ca-certificates locales
fi
# Get Word dir
dir=$(pwd)
# Change Locale
if [ "${release}" == "centos" ]; then
\tlocaledef -v -c -i zh_CN -f UTF-8 zh_CN.UTF-8 > /dev/null 2>&1
\tcd /etc
\trm -rf locale.conf
\twget https://raw.githubusercontent.com/FunctionClub/LocaleCN/master/locale.conf > /dev/null 2>&1
\tcp locale.conf locale
\tcat locale.conf >> /etc/environment
elif [ "${release}" == "debian" ]; then
\trm -rf /etc/locale.gen
\trm -rf /etc/default/locale
\trm -rf /etc/default/locale.conf
\tcd /etc/
\twget https://raw.githubusercontent.com/FunctionClub/LocaleCN/master/locale.gen > /dev/null 2>&1
\tlocale-gen
\tcd /etc/default/
\twget https://raw.githubusercontent.com/FunctionClub/LocaleCN/master/locale.conf > /dev/null 2>&1
\tcp locale.conf locale
elif [ "${release}" == "ubuntu" ]; then
\t\trm -rf /etc/locale.gen
\trm -rf /etc/default/locale
\trm -rf /etc/default/locale.conf
\tcd /etc/
\twget https://raw.githubusercontent.com/FunctionClub/LocaleCN/master/locale.gen > /dev/null 2>&1
\tlocale-gen
\tcd /etc/default/
\twget https://raw.githubusercontent.com/FunctionClub/LocaleCN/master/locale.conf > /dev/null 2>&1
\tcp locale.conf locale
fi
# Echo Success
clear
echo "Your Machine Language setting is changed to Chinese(Simplified)"
echo "Reconnect to your machine to check it"
echo ""
echo "copyright by hwb"
echo "QQ : 1275758000"
# Delete self
cd ${dir}
rm -rf LocaleCN.sh
3、执行结果:
觉得有用的朋友多帮忙转发哦!后面会分享更多devops和DBA方面的内容,感兴趣的朋友可以关注下~