HEX
Server: nginx/1.16.1
System: Linux ecs-04358622 4.19.90-2107.6.0.0100.oe1.bclinux.x86_64 #1 SMP Wed Dec 1 19:59:44 CST 2021 x86_64
User: nginx (994)
PHP: 8.0.0
Disabled: NONE
Upload Files
File: //opt/BCLinux/bse/secure_set/s06_umask
#!/bin/sh


#=====================================================================
InsertSection "Set the umask..."

if [ $SET_UMASK -eq 1 ]; then

    cp -np /etc/profile  /etc/profile_bak
    cp -np /etc/bashrc  /etc/bashrc_bak
    cp -np /etc/csh.cshrc  /etc/csh.cshrc_bak
    cp -np /etc/csh.login  /etc/csh.login_bak
    cp -np /root/.bashrc  /root/.bashrc_bak
    cp -np /root/.cshrc /root/.cshrc_bak

    #-----------------------------------
    #echo -e "change the umask value..."

    file=(/etc/profile /etc/bashrc /etc/csh.cshrc /etc/csh.login /root/.bashrc /root/.cshrc)

    for i in ${file[@]}
    do
        if [ -f $i ];then
            IS_EXIST=`egrep -v '^#|^$' $i |grep -v "#" | grep -w 'umask \{1,\}'$UMASK_VALUE'' |wc -l`
            if [ "${IS_EXIST}" = "0" ] ; then
                echo " " >> $i
                echo "umask $UMASK_VALUE" >> $i
            fi
        fi
    done

   num_file=0   #the number of files set umask
   num_umask=0  #the number of umask
   for i in  ${file[@]}
   do
        if [ -f $i ];then
            let num_file+=1;
            UMASK_RESULT=`cat $i |grep umask|grep -v "#" | awk -F " " '{print $2}'|tail -1 `
            if [[ "${UMASK_RESULT}" -eq "$UMASK_VALUE" ]];  #unary operator expected
            then
                let num_umask+=1;
            fi
        fi
    done

    if [[ "$num_file" -eq "$num_umask" ]];then
        logtext "Set the umask finished, checking ok"
        Display --indent 2 --text "- Set the umask... " --result FINISHED --color GREEN
    else
        logtext "Set the umask failed, the result is ${UMASK_RESULT}, and is not ok"
        Display --indent 2 --text "- Set the umask... " --result FAILED --color RED

    fi

else

    Display --indent 2 --text "- Skip set umask due to config file... " --result SKIPPING --color YELLOW

fi