#!/bin/bash
Msg-Warning() {
	dialog --title "Warning" --msgbox "$1" 0 0
}
Msg-OK() {
	dialog --title "OK" --msgbox "$1" 0 0
}
function CuserName() {
	UserName=$(dialog --title "First-CreateUserName" --inputbox "输入用户名" 0 0 cs 3>&1 1>&2 2>&3)
	exitstatus=$?
	if [ $exitstatus = 0 ]; then
		VuserN
	else
		Msg-Warning "已退出"
		clear
		exit
	fi
}
function CuserPasswd() {
	UserPasswd=$(dialog --title "First-CreateUserPasswd" --inputbox "输入密码" 0 0 cs 3>&1 1>&2 2>&3)
	exitstatus=$?
	if [ $exitstatus = 0 ]; then
		VuserP
	else
		Msg-Warning "已退出"
		clear
		exit
	fi
}
function VuserN() {
	if [ ! -n "$UserName" ]
	then
		Msg-Warning "用户名不能为空"
		CuserName
		VuserN
	else
		Msg-OK "用户名已确认"
		CuserPasswd
	fi
}
function VuserP() {
	if [ ! -n "$UserPasswd" ]
	then
		Msg-Warning "密码不能为空"
		CuserPasswd
		VuserP
	else
		VuserPT
	fi

}
function VuserPT() {
	UserPasswdT=$(dialog --title "First-CreateUserPasswd" --inputbox "再次输入密码" 0 0 cs 3>&1 1>&2 2>&3)
	exitstatus=$?
	if [ $exitstatus = 0 ]; then
		if [ "$UserPasswd" = "$UserPasswdT" ]
		then
			Msg-OK "密码已确认"
		else
			Msg-Warning "两次密码不同"
			CuserPasswd
		fi
	else
		Msg-Warning "密码验证取消，已退出"
		clear
		exit
	fi
}
CuserName