#!/bin/bash

_install() {
	# create user core
	if [[ $(grep -c core /etc/passwd) -gt 0 ]];then
		userdel -rf core
	fi
	useradd -d /home/core -s /sbin/nologin core
	chmod 0777 /home/core

    if [[ $ENVFLAG = 'offline' ]];then
        return 0
    fi

	# create user ureadonly for UNOC
    if [[ $VMFLAG -eq 0 ]];then
    	if [[ $(grep -c ureadonly /etc/passwd) -gt 0 ]];then
    		userdel -rf ureadonly
    		rm -rf /etc/sudoers.d/ureadonly
    	fi
    	useradd -d /home/ureadonly ureadonly
    	cat $BASEDIR/configs/account/ureadonly/pass | passwd --stdin ureadonly  > /dev/null
    	mkdir -p /home/ureadonly/.ssh/
    	chmod 0700 /home/ureadonly/.ssh
    	cat $BASEDIR/configs/account/ureadonly/pubkey > /home/ureadonly/.ssh/authorized_keys
    	chmod 600 /home/ureadonly/.ssh/authorized_keys
    	chown -R ureadonly:ureadonly /home/ureadonly/.ssh
    	\cp -f $BASEDIR/configs/account/ureadonly/sudo /etc/sudoers.d/ureadonly
    	chmod 0440 /etc/sudoers.d/ureadonly
    fi

}


_check() {
	_check="PASS"
    if [[ $ENVFLAG = 'offline' ]];then
        return 0
    fi

	if [[ $(id core 2>/dev/null|wc -l) -eq 0 ]];then
		_check="FAIL"
		PRINT_ERR "[ERROR] User:core Not Exist."
	elif [ $VMFLAG -eq 0 -a $(id ureadonly 2>/dev/null|wc -l) -eq 0 ];then
		_check="FAIL"
		PRINT_ERR "[ERROR] User:ureadonly Not Exist."
	fi
}
