jim.jin 发表于 2013-1-15 01:57:44

ubuntu server 启动时用zhcon自动开启中文界面

1.安装zhcon
sudo apt-get install zhcon

2.添加用户 welcome (可以不用设置密码,因为将设置开机自动登录)

sudo useradd welcome -m -s /bin/bash


设置开机自动以welcome登录
sudo vi /usr/bin/auto_login_welcome
加入内容并保存
#!/bin/bash/bin/login -f welcome

加执行权限
sudo chmod +x /usr/bin/auto_login_welcome


把/etc/init/tty1.conf中下面这一行(注意目录和文件名):

代码:
exec /sbin/getty 38400 tty1   

修改为
代码:
exec /sbin/getty -n -l /usr/bin/auto_login_welcome 38400 tty1


这样开机就可以自动登录了(开机状态按 Ctrl + D,可以看效果)

3.登录后自动启动字符界面
添加welcome中文字符界面,字符界面如果要更漂亮可以通过 http://www.text-image.com/convert/ascii.html 来生成字符图片
中文可以通过putty来输入

sudo vi /usr/bin/welcome
内容:
#!/bin/bashecho 欢迎使用echo 服务器已经启动成功echo 服务器已经启动, 请在浏览器登录系统echo 地址: http://`getip`while truedoread lineecho 欢迎使用echo 服务器已经启动, 请在浏览器登录系统echo 地址: http://`getip`sleep 1done


加执行权限
sudo chmod +x /usr/bin/welcome

添加得到ip地址命令,因为下面要用到ip
sudo vi /usr/bin/getip
内容:
#!/bin/sh# Shell script scripts to read ip address# -------------------------------------------------------------------------# Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/># This script is licensed under GNU GPL version 2.0 or above# -------------------------------------------------------------------------# This script is part of nixCraft shell script collection (NSSC)# Visit http://bash.cyberciti.biz/ for more information.# -------------------------------------------------------------------------# Get OS nameOS=`uname`IO="" # store IPcase $OS-$LC_ALL in   Linux) IP=`ifconfig| grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`;;   Linux-zh_CN.UTF-8) IP=`ifconfig| grep 'inet 地址:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`;;   FreeBSD|OpenBSD) IP=`ifconfig| grep -E 'inet.' | grep -v '127.0.0.1' | awk '{ print $2}'` ;;   SunOS) IP=`ifconfig -a | grep inet | grep -v '127.0.0.1' | awk '{ print $2} '` ;;   *) IP="Unknown";;esacecho "$IP"

sudo vi /home/welcome/.bash_profile
加入内容:
/usr/bin/zhcon --utf8 #注意路径

如果.bash_profile是新建的文件,需要修改own
sudo chown welcome /home/welcome/.bash_profile

sudo vi /home/welcome/.bashrc
加入内容:
/usr/bin/welcome

如果不要显示zhcon欢迎信息
要把/etc/zhcon.conf 中startupmsg 改为off
#whether to display startup messagestartupmsg = off



大功告成,重启试试看。

如果 有 setlocale: LC_ALL cannot change locale (zh_CN.UTF-8) 类错误
是没有中文包造成,用locale -a 可以查看
可以安装下列包来解决,参考http://56553655.iteye.com/blog/722708
sudo apt-get install language-pack-gnome-zh language-pack-gnome-zh-base language-pack-zh language-pack-zh-base language-support-zh
页: [1]
查看完整版本: ubuntu server 启动时用zhcon自动开启中文界面