FOXBI

DSM 5.x/6.x CPU name & cores infomation Change tool

Recommended Posts

Thank you, FOXBI!

Can you publish last version shell script?

  • Thanks 1

Share this post


Link to post
Share on other sites
1 hour ago, kacy said:

Thank you, FOXBI!

Can you publish last version shell script?

 

 

I am not a professional developer

 

I am a bit embarrassed every time I release the source ,, :36_flushed:

 

Please see below.

 

 

Spoiler

#!/bin/bash
# ver 4.0 2018.09.13 Made by FOXBI
# ver 3.0 2018.08.24 Made by FOXBI
# Ver 1.5 2018.08.23 Made by FOXBI
# Ver 1.1 2018.08.22 Made by FOXBI
# Ver 1.0 2018.08.17 Made by FOXBI
ver="4.0"
# ==============================================================================
# Y or N Function
# ==============================================================================
READ_YN () { # $1:question $2:default
   read -n1 -p "$1" Y_N
    case "$Y_N" in
    y) Y_N="y"
         echo -e "\n" ;;
    n) Y_N="n"
         echo -e "\n" ;;        
    q) echo -e "\n"
       exit 0 ;;
    *) echo -e "\n" ;;
    esac
}

# ==============================================================================
# Process Function
# ==============================================================================
PREPARE_FN () {
    if [ -f "$WORK_DIR/admin_center.js" ] && [ -f "$MWORK_DIR/mobile.js" ]
    then
        if [ "$direct_job" == "y" ]
        then
            echo "warning!! Work directly on the original file without backup.\n"
        else
            cd $WORK_DIR
            tar -cf $BKUP_DIR/$TIME/admin_center.tar admin_center.js*
            cd $MWORK_DIR
            tar -cf $BKUP_DIR/$TIME/mobile.tar mobile.js*
        fi
        if [ "$MA_VER" -eq "6" ] && [ "$MI_VER" -ge "2" ]
        then
            mv $WORK_DIR/admin_center.js.gz $BKUP_DIR/
            mv $MWORK_DIR/mobile.js.gz $BKUP_DIR/
	        cd $BKUP_DIR/
            gzip -df $BKUP_DIR/admin_center.js.gz 
            gzip -df $BKUP_DIR/mobile.js.gz        
        else
            cp -Rf $WORK_DIR/admin_center.js $BKUP_DIR/
            cp -Rf $MWORK_DIR/mobile.js $BKUP_DIR/
        fi
    else
        COMMENT08_FN
    fi
}

GATHER_FN () {
    DMI_CHK=`dmidecode | grep 'SMBIOS' | egrep 'NO|sorry' | wc -l`
    if [ "$DMI_CHK" -gt "0" ]
    then
        cpu_vendor=`cat /proc/cpuinfo | grep model | grep name | sort -u | sed "s/(.)//g" | sed "s/(..)//g" | sed "s/CPU//g" | awk '{print $4}'`
        if [ "$cpu_vendor" == "AMD" ]
        then
            cpu_family=`cat /proc/cpuinfo | grep model | grep name | sort -u | sed "s/(.)//g" | sed "s/(..)//g" | sed "s/CPU//g" | awk -F "$cpu_vendor " '{ print $2 }' | awk -F "Processor" '{ print $1 }'`
            cpu_series=""
        else
            cpu_family=`cat /proc/cpuinfo | grep model | grep name | sort -u | sed "s/(.)//g" | sed "s/(..)//g" | sed "s/CPU//g" | awk '{print $5}'`        
            cpu_series=`cat /proc/cpuinfo | grep model | grep name | sort -u | sed "s/(.)//g" | sed "s/(..)//g" | sed "s/CPU//g" | awk '{ if (index($7,"@")!=0) { print $6 } else { print $6" "$7 } }'`
        fi        
    else
        cpu_vendor=`dmidecode -t processor | grep Version | grep -v Unknown | grep -v Not | sort -u | sed "s/(.)//g" | sed "s/(..)//g" | sed "s/CPU//g" | awk '{print $2}'`
        if [ "$cpu_vendor" == "AMD" ]
        then
            cpu_family=`dmidecode -t processor | grep Version | grep -v Unknown | grep -v Not | sort -u | sed "s/(.)//g" | sed "s/(..)//g" | sed "s/CPU//g" | awk -F "$cpu_vendor " '{ print $2 }' | awk -F "Processor" '{ print $1 }'`
            cpu_series=""
        else
            cpu_family=`dmidecode -t processor | grep Version | grep -v Unknown | grep -v Not | sort -u | sed "s/(.)//g" | sed "s/(..)//g" | sed "s/CPU//g" | awk '{print $3}'`        
            cpu_series=`dmidecode -t processor | grep Version | grep -v Unknown | grep -v Not | sort -u | sed "s/(.)//g" | sed "s/(..)//g" | sed "s/CPU//g" | awk '{ if (index($5,"@")!=0) { print $4 } else { print $4" "$5 } }'`
        fi
    fi
    cpu_cores=`cat /proc/cpuinfo | grep processor| wc -l`
}

PERFORM_FN () {
    if [ -f "$BKUP_DIR/admin_center.js" ] && [ -f "$BKUP_DIR/mobile.js" ]
    then    
        if [ "$MA_VER" -ge "6" ]
        then
            cpu_info=`echo "f.cpu_vendor=\"${cpu_vendor}\";f.cpu_family=\"${cpu_family}\";f.cpu_series=\"${cpu_series}\";f.cpu_cores=\"${cpu_cores}\";"`
            sed -i "s/f.model]);/f.model]);${cpu_info}/g" $BKUP_DIR/admin_center.js

            cpu_info_m=`echo "{name: \"cpu_series\",renderer: function(value){var cpu_vendor=\"${cpu_vendor}\";var cpu_family=\"${cpu_family}\";var cpu_series=\"${cpu_series}\";var cpu_cores=\"${cpu_cores}\";return Ext.String.format('{0} {1} {2} ({3}Core)', cpu_vendor, cpu_family, cpu_series, cpu_cores);},label: _T(\"status\", \"cpu_model_name\")},"`
            sed -i "s/\"ds_model\")},/\"ds_model\")},${cpu_info_m}/g" $BKUP_DIR/mobile.js
        else
            if [ "$MI_VER" -gt "0" ]
            then
                cpu_info=`echo "b.cpu_vendor=\"${cpu_vendor}\";b.cpu_family=\"${cpu_family}\";b.cpu_series=\"${cpu_series}\";b.cpu_cores=\"${cpu_cores}\";"`
            else
                cpu_info=`echo "b.cpu_vendor=\"${cpu_vendor}\";b.cpu_family=\"${cpu_family} ${cpu_series}\";b.cpu_cores=\"${cpu_cores}\";"`
            fi
            sed -i "s/b.model]);/b.model]);${cpu_info}/g" $BKUP_DIR/admin_center.js
        fi
    else
        COMMENT08_FN
    fi
}

APPLY_FN () {
    if [ -f "$BKUP_DIR/admin_center.js" ] && [ -f "$BKUP_DIR/mobile.js" ]
    then    
        cp -Rf $BKUP_DIR/admin_center.js $WORK_DIR/
        cp -Rf $BKUP_DIR/mobile.js $MWORK_DIR/
        if [ "$MA_VER" -eq "6" ] && [ "$MI_VER" -ge "2" ]
        then    
            gzip -f $BKUP_DIR/admin_center.js
            gzip -f $BKUP_DIR/mobile.js
            mv $BKUP_DIR/admin_center.js.gz $WORK_DIR/
            mv $BKUP_DIR/mobile.js.gz $MWORK_DIR/
        else
            rm -rf $BKUP_DIR/admin_center.js
            rm -rf $BKUP_DIR/mobile.js
        fi
    else
        COMMENT08_FN
    fi        
}

RECOVER_FN () {
    if [ -d "$BKUP_DIR/$TIME" ]
    then
        cd $WORK_DIR
        tar -xf $BKUP_DIR/$TIME/admin_center.tar
        if [ -f "$BKUP_DIR/$TIME/mobile.tar" ]
        then
            cd $MWORK_DIR
            tar -xf $BKUP_DIR/$TIME/mobile.tar
        fi
        if [ "$re_check" == "y" ]
        then
            echo -e "Restore to source and continue.\n"
        else
            COMMENT09_FN
        fi
    else
        COMMENT08_FN
    fi
}

RERUN_FN () {
    if [ "$1" == "redo" ]
    then
        ls -l $BKUP_DIR/ | grep ^d | grep -v "$BL_CHK" | awk '{print "rm -rf '$BKUP_DIR'/"$9}' | sh
        GATHER_FN
        if [ -f "$WORK_DIR/admin_center.js" ] && [ -f "$MWORK_DIR/mobile.js" ]
        then
            info_cnt=`cat $WORK_DIR/admin_center.js | grep ".model]);if(Ext.isDefined" | wc -l`
            info_cnt_m=`cat $MWORK_DIR/mobile.js | grep "ds_model\")},{name:\"ram_size" | wc -l`
            if [ "$info_cnt" -eq "0" ] && [ "$info_cnt_m" -eq "0" ]
            then
                if [ "$MA_VER" -ge "6" ]
                then
                    cpu_info="f.cpu_vendor=\\\"${cpu_vendor}\\\";f.cpu_family=\\\"${cpu_family}\\\";f.cpu_series=\\\"${cpu_series}\\\";f.cpu_cores=\\\"${cpu_cores}\\\";"
                    sed -i "s/${cpu_info}//g" $WORK_DIR/admin_center.js

                    cpu_info_m="{name: \\\"cpu_series\\\",renderer: function(value){var cpu_vendor=\\\"${cpu_vendor}\\\";var cpu_family=\\\"${cpu_family}\\\";var cpu_series=\\\"${cpu_series}\\\";var cpu_cores=\\\"${cpu_cores}\\\";return Ext.String.format('{0} {1} {2} ({3}Core)', cpu_vendor, cpu_family, cpu_series, cpu_cores);},label: _T(\\\"status\\\", \\\"cpu_model_name\\\")},"
                    sed -i "s/${cpu_info_m}//g" $MWORK_DIR/mobile.js                    
                    if [ "$MI_VER" -ge "2" ]
                    then
                        cp -Rf $WORK_DIR/admin_center.js $WORK_DIR/admin_center.js.1
                        cp -Rf $MWORK_DIR/mobile.js $MWORK_DIR/mobile.js.1
                        gzip -f $WORK_DIR/admin_center.js
                        gzip -f $MWORK_DIR/mobile.js
                        mv $WORK_DIR/admin_center.js.1 $WORK_DIR/admin_center.js
                        mv $MWORK_DIR/mobile.js.1 $MWORK_DIR/mobile.js
                    fi
                else
                    if [ "$MI_VER" -gt "0" ]
                    then
                        cpu_info="b.cpu_vendor=\\\"${cpu_vendor}\\\";b.cpu_family=\\\"${cpu_family}\\\";b.cpu_series=\\\"${cpu_series}\\\";b.cpu_cores=\\\"${cpu_cores}\\\";"
                    else
                        cpu_info="b.cpu_vendor=\\\"${cpu_vendor}\\\";b.cpu_family=\\\"${cpu_family} ${cpu_series}\\\";b.cpu_cores=\\\"${cpu_cores}\\\";"
                    fi
                    sed -i "s/${cpu_info}//g" $WORK_DIR/admin_center.js
                fi
            fi
        else
            COMMENT08_FN
        fi    
    fi
}

BLCHECK_FN () {
    bl_check=n
    if [ -d "$BKUP_DIR" ]
    then
        BK_CNT=`ls -l $BKUP_DIR/ | grep ^d | wc -l`
        if [ "$BK_CNT" -gt "0" ]
        then
            BK_CNT=`ls -l $BKUP_DIR/ | grep ^d | grep "$BL_CHK" | wc -l`
            if [ "$BK_CNT" -gt "0" ]
            then
                TIME=`ls -l $BKUP_DIR/ | grep ^d | grep "$BL_CHK" | awk '{print $9}' | head -1`
                BK_CNT=`ls -l $BKUP_DIR/ | grep ^d | grep -v "$BL_CHK" | wc -l`
                if [ "$BK_CNT" -gt "0" ]
                then
                    BLSUB_FN "$1"
                else
                    if [ "$re_check" == "n" ]
                    then
                        if [ "$1" == "run" ]
                        then
                            COMMENT03_FN
                        fi
                        COMMENT05_FN
                    else
                        STIME=`ls -l $BKUP_DIR/ | grep ^d | awk '{print $9}' | head -1`
                        BLSUB_FN "redo"
                    fi
                fi
            else
                if [ "$1" == "restore" ]
                then
                    COMMENT07_FN
                fi
                BK_CNT=`ls -l $BKUP_DIR/ | grep ^d | grep -v "$BL_CHK" | wc -l`
                if [ "$BK_CNT" -gt "0" ]
                then
                    BL_COM=`ls -l $BKUP_DIR/ | grep ^d | awk '{print $9}' | head -1 | awk -F_ '{print $2}'`
                    BL_CNT=`ls -l $BKUP_DIR/ | grep ^d | awk '{print $9}' | head -1 | awk -F_ '{print $2}' | wc -l`
                    if [ "$BL_COM" == "" ]
                    then
                        if [ "$BL_CNT" -gt "0" ]
                        then
                            BLSUB_FN "$1"
                            bl_check=y
                        else
                            COMMENT06_FN
                        fi
                    else
                        TIME=`ls -l $BKUP_DIR/ | grep ^d | awk '{print $9}' | head -1`
                        if [ "$BL_CHK" == "$BL_COM" ]
                        then
                            if [ "$1" == "run" ]
                            then
                                COMMENT03_FN
                            else
                                COMMENT05_FN
                                bl_check=n
                            fi
                        else
                            if [ "$BL_CHK" -gt "$BL_COM" ]
                            then
                                BLSUB_FN "$1"
                                bl_check=y
                            else
                                COMMENT06_FN
                            fi
                        fi
                    fi
                else
                    COMMENT06_FN
                fi
            fi
        else
            CASE_FN "$1"
        fi
    else
        CASE_FN "$1"
    fi
}

BLSUB_FN () {
    TIME=`echo "$STIME"`
    if [ "$1" == "run" ]
    then
        RERUN_FN "redo"
    else
        RERUN_FN "$1"
    fi
    COMMENT05_FN
}

CASE_FN () {
    case "$1" in
        run) COMMENT05_FN ;;
        redo) COMMENT07_FN ;;        
        restore) COMMENT07_FN ;;
        *) COMMENT06_FN ;;
    esac    
}

EXEC_FN () {
if [ -d $WORK_DIR ]
then    
    READ_YN "Auto Excute, If you select n, proceed interactively  (Cancel : q) [y/n] : "
    if [ "$Y_N" == "y" ]
    then
        mkdir -p $BKUP_DIR/$TIME

        if [ "$re_check" == "y" ]
        then
            if [ "$bl_check" == "y" ]
            then
 		        COMMENT04_FN
            else
                RECOVER_FN
            fi
        fi

        PREPARE_FN

        GATHER_FN

        PERFORM_FN

        APPLY_FN

        COMMENT09_FN

    elif [ "$Y_N" == "n" ]
    then
        READ_YN "Proceed with original file backup and preparation.. If you select n, Work directly on the original file. (Cancel : q) [y/n] : "
        if [ "$Y_N" == "y" ]    
        then
            mkdir -p $BKUP_DIR/$TIME

            if [ "$re_check" == "y" ]
            then
                if [ "$bl_check" == "y" ]
                then
 		            COMMENT04_FN
                else
                    RECOVER_FN
                fi
            fi

            PREPARE_FN

        elif [ "$Y_N" == "n" ]
        then
            direct_job=y
            mkdir -p $BKUP_DIR
            PREPARE_FN            
        else
            COMMENT10_FN
        fi

        READ_YN "CPU name, Core count and reflects it. If you select n, Resote original file (Cancel : q) [y/n] : "
        if [ "$Y_N" == "y" ]    
        then    
            GATHER_FN

            PERFORM_FN

            APPLY_FN

		    COMMENT09_FN
        elif [ "$Y_N" == "n" ]
        then
	        if [ -d "$BKUP_DIR" ]
    	    then
                gzip $BKUP_DIR/admin_center.js
                gzip $BKUP_DIR/mobile.js
                mv $BKUP_DIR/admin_center.js.gz $WORK_DIR/
                mv $BKUP_DIR/mobile.js.gz $MWORK_DIR/
                COMMENT09_FN
		    else
			    COMMENT07_FN
		    fi
        else
            COMMENT10_FN
        fi
    else
        COMMENT10_FN
    fi
else
    COMMENT08_FN
fi
}

COMMENT03_FN () {
    echo -e "There is a history of running the same version. Please run again select 2) redo .\n"
    exit 0
}

COMMENT04_FN () {
    echo -e "Do not restore to source when installing a higher version. Contiue...\n"
}

COMMENT05_FN () {
    echo -e "You have verified and installed the previous version. Contiue...\n"
}

COMMENT06_FN () {
    echo -e "Problem and exit. Please run again after checking."
    exit 0    
}

COMMENT07_FN () {
    echo -e "No execution history. Please go back to the first run."
    exit 0
}

COMMENT08_FN () {
    echo -e "The target file(location) does not exist. Please run again after checking."
    exit 0
}

COMMENT09_FN () {
    echo -e "The operation is complete!! It takes about 1-2 minutes to reflect, \n(Please refresh the DSM page with F5 or after logout/login and check the information.)"
    exit 0
}

COMMENT10_FN () {
    echo -e "Only y / n / q can be input. Please proceed again."
    exit 0
}

# ==============================================================================
# Main Progress
# ==============================================================================
clear
WORK_DIR="/usr/syno/synoman/webman/modules/AdminCenter"
MWORK_DIR="/usr/syno/synoman/mobile/ui"
BKUP_DIR="/root/Xpenology_backup"
VER_DIR="/etc.default"

echo "DSM CPU Information Change Tool ver. \033[0;31m"$ver"\033[00m - made by FOXBI\n"

if [ -d "$VER_DIR" ]
then
    VER_FIL="$VER_DIR/VERSION"
else
    VER_FIL="/etc/VERSION"
fi

if [ -f "$VER_FIL" ]
then
    MA_VER=`cat $VER_FIL | grep majorversion | awk -F \= '{print $2}' | sed 's/\"//g'`
    MI_VER=`cat $VER_FIL | grep minorversion | awk -F \= '{print $2}' | sed 's/\"//g'`
    BL_NUM=`cat $VER_FIL | grep buildnumber | awk -F \= '{print $2}' | sed 's/\"//g'`    
    BL_FIX=`cat $VER_FIL | grep smallfixnumber | awk -F \= '{print $2}' | sed 's/\"//g'`
else
    COMMENT08_FN
fi

BL_CHK=$BL_NUM$BL_FIX
TIME=`date +%Y%m%d%H%M%S`"_"$BL_CHK
STIME=`echo "$TIME"`

if [ "$MA_VER" -gt "4" ]
then
    if [ "$MA_VER" -eq "5" ]
    then
        MWORK_DIR="/usr/syno/synoman/webman/mapp"
    fi
    echo "Your version of DSM is \033[0;36mDSM \033[0;31m"$MA_VER"."$MI_VER"\033[0;32m continue...\n"
else
    echo "DSM version less than 5 is not supported. End the process."
    exit 0
fi

read -n1 -p "1) First run  2) Redo  3) Restore - Select Number : " inst_z 
   case "$inst_z" in
   1) inst_check=run 
      echo -e "\n " ;;
   2) inst_check=redo 
      echo -e "\n " ;;
   3) inst_check=restore 
      echo -e "\n " ;;
   *) echo -e "\n" ;;
   esac

if [ "$inst_check" == "redo" ]
then
	READ_YN "Do you want to proceed again? Restore to original file backup and proceed.(Cancel : q) [y/n] : "
    if [ "$Y_N" == "y" ]    
    then
        re_check=y        
        BLCHECK_FN "$inst_check"
        inst_check=run
        EXEC_FN
    elif [ "$Y_N" == "n" ]
    then
        echo "Do not proceed with the redo."    
    else
        COMMENT10_FN
    fi
elif [ "$inst_check" == "restore" ]
then
	READ_YN "Do you want to restore using the original backup file? (Cancel : q) [y/n] : "
    if [ "$Y_N" == "y" ]    
    then
        re_check=n
        BLCHECK_FN "$inst_check"
        RECOVER_FN
    elif [ "$Y_N" == "n" ]
    then
        echo "No restore was performed."   
    else
        COMMENT10_FN
    fi
elif [ "$inst_check" == "run" ]
then
    re_check=n
    BLCHECK_FN "$inst_check"
    EXEC_FN
else
    echo "Please select the correct number."
fi

 

 

  • Like 1

Share this post


Link to post
Share on other sites

Many thanks, FOXBI!
The shell script works great!
PS  I recently had a trip to Korea. Korea is a beautiful country populated by wonderful people.

  • Thanks 1

Share this post


Link to post
Share on other sites

As the binary cannot be downloaded, I've made a cpu_info file by pasting your code into it.

Copied to a temp folder on my XPEnology NAS. Then set executable attribute, but could only execute via sh command, then I get an error message.

 

root@FORESTER:/volume1/tibor/Temp# sh cpu_info
cpu_info: line 13: syntax error near unexpected token `$'in\r''
'pu_info: line 13: `    case "$Y_N" in
 

What did I wrong? I have DSM 6.2-23739 if that matters (don't think so).

 

  • Thanks 1

Share this post


Link to post
Share on other sites
19 hours ago, Tibor said:

As the binary cannot be downloaded, I've made a cpu_info file by pasting your code into it.

Copied to a temp folder on my XPEnology NAS. Then set executable attribute, but could only execute via sh command, then I get an error message.

 

root@FORESTER:/volume1/tibor/Temp# sh cpu_info
cpu_info: line 13: syntax error near unexpected token `$'in\r''
'pu_info: line 13: `    case "$Y_N" in
 

What did I wrong? I have DSM 6.2-23739 if that matters (don't think so).

 

 

Hello,

 

Why are not attachments being downloaded? 

Please contact the forum administrator.

 

 

It may not be a problem in your shell environment or in the pasting process.

Please try debugging with

#sh -x cpu_info 

You can see at a glance where the error occurs.

If you show me the results, I will look for problems together.

Share this post


Link to post
Share on other sites
16 hours ago, FOXBI said:

 

Hello,

 

Why are not attachments being downloaded? 

Please contact the forum administrator.

 

 

It may not be a problem in your shell environment or in the pasting process.

Please try debugging with


#sh -x cpu_info 

You can see at a glance where the error occurs.

If you show me the results, I will look for problems together.

 

As of the debug info

root@FORESTER:/volume1/tibor/Temp# sh -x cpu_info
+ ver=$'4.0\r'
cpu_info: line 13: syntax error near unexpected token `$'in\r''
'pu_info: line 13: `    case "$Y_N" in
 

I tried to download the binary again, this I could. Don't know why couldn't last time. I don't have luck with you script :)

Executed like this and got that message:

root@FORESTER:/volume1/tibor/Temp# ./ch_cpuinfo
-ash: ./ch_cpuinfo: Text file busy

 

What text filie might be busy?  I'm in the middle of expanding my volume (running for a day now, but it's still at 36%), otherwise it's a new system, it's quite empty, no big packages running, etc.

 

I have not expectations, you're kind already that took the time, made the script and publish it for so many people's delight :)

  • Thanks 1

Share this post


Link to post
Share on other sites
19 hours ago, Tibor said:

+ ver=$'4.0\r'
cpu_info: line 13: syntax error near unexpected token `$'in\r''

 

I think so happen problem, when you pasted shell source.

 

original source not include \r 

 

Perhaps it seems that \r has been inserted in the line change during the pasting process.

 

 

It is possible that some terminal programs may occur. Please compress the source created by notepad, upload & unzip it, and try to execute it

 

gook luck :)

 

Share this post


Link to post
Share on other sites

Cool, it was probalby my mistake. I've downloaded again, set the permissions properly, executed and voila, it did work as it should :)DSM.thumb.PNG.3ebfdb3bac2045242fa54fd4e2e2961f.PNG

  • Thanks 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now