diff options
author | John Klug <john.klug@multitech.com> | 2018-07-12 18:25:22 -0500 |
---|---|---|
committer | John Klug <john.klug@multitech.com> | 2018-07-12 18:25:22 -0500 |
commit | ad7db43a91b914ede616e90fc77f997976d8b4a3 (patch) | |
tree | 232ac167d11f9ab72d6796ab7b42fef74c359199 /src | |
parent | 1f7c076c1cc498518d6486cb9b6f4485ba03dcb0 (diff) | |
download | mts-id-eeprom-ad7db43a91b914ede616e90fc77f997976d8b4a3.tar.gz mts-id-eeprom-ad7db43a91b914ede616e90fc77f997976d8b4a3.tar.bz2 mts-id-eeprom-ad7db43a91b914ede616e90fc77f997976d8b4a3.zip |
Prefer MAC, then UUID for generating U-Boot Password0.3.10
Diffstat (limited to 'src')
-rwxr-xr-x | src/ubpasswd.sh | 66 |
1 files changed, 54 insertions, 12 deletions
diff --git a/src/ubpasswd.sh b/src/ubpasswd.sh index 0e5ba2e..34180de 100755 --- a/src/ubpasswd.sh +++ b/src/ubpasswd.sh @@ -24,22 +24,24 @@ if ! [[ -x /sbin/mts-hashpwd ]] ; then exit 1 fi usage() { - echo "ubpasswd [-c] [-m] [-n] [-r] [-u] [-d] [-s salt] [password]" + echo "ubpasswd [-c] [-d] [-n] [-i] [-m] [-u] [-r] [-f] [-s salt] [password]" echo " -c clear the U-Boot password" echo " -d debug" - echo " -f returns true if U-Boot password" - echo " feature is available." - echo " -m means use the mac to generate the password (obsolete)." echo " -n dryrun for setting password" + echo " -i use the uuid to generate the password" + echo " -m means use the mac to generate the password." + echo " -u means u-boot only (not UNIX password)" echo " -r returns true if U-Boot password" echo " is currently required" + echo " -f returns true if U-Boot password" + echo " feature is available." echo " -s salt is user supplied salt" - echo " -u means u-boot only (not UNIX password)" echo " password is a user supplied password" echo "A salt not supplied is generated." echo "If a password is not supplied, it is generated" - echo "If generating a password, and -m is not supplied," - echo "the UUID is used for generating the password" + echo "If generating a password. The MAC address is" + echo "preferred for generating the password, but the" + echo "UUID will be used if the MAC is not present." exit 1 } ((ubonly=0)) @@ -48,7 +50,7 @@ usage() { ((debug=0)) ((upwd=0)) ((dryrun=0)) -while getopts ":cdfmnrs:u" opt; do +while getopts ":cdfimnrs:u" opt; do case $opt in c) u-boot setenv mtsp @@ -64,17 +66,29 @@ while getopts ":cdfmnrs:u" opt; do exit 0 fi ;; + i) + ((useuuid=1)) + if ! [[ -f "${MTS}/uuid" ]] ; then + echo "${MTS}/uuid not found. Maybe mts-io driver is not loaded?" + exit 1 + fi + uuid=$(cat "${MTS}/uuid") + if ((${#uuid} == 0)) ; then + echo "${MTS}/uuid must have a non-zero length value" + usage + fi + ;; m) ((usemac=1)) + if ! [[ -f "${MTS}/mac-eth" ]] ; then + echo "${MTS}/mac-eth not found. Maybe mts-io driver is not loaded?" + exit 1 + fi mac=$(cat "${MTS}/mac-eth") if ((${#mac} == 0)) ; then echo "${MTS}/mac-eth must have a non-zero length value" usage fi - if ! [[ -f "${MTS}/mac-eth" ]] ; then - echo "${MTS}/mac-eth not found. Maybe mts-io driver is not loaded?" - exit 1 - fi ;; n) ((dryrun=1)) @@ -130,11 +144,37 @@ echo "salt: $salt" ((debug)) && echo upwd is $upwd ((debug)) && echo did length is ${#did} + + if ((useuuid == 0)) && ((usemac == 0)) ; then + # Use MAC unless not present. + # This is because old code did this, and because + # UUID is not present in MTR and old Conduits. + ((usemac=1)) + mac=$(cat "${MTS}/mac-eth") + if ((${#mac} == 0)) ; then + ((usemac=0)) + # Check for UUID + ((useuuid=1)) + uuid=$(cat "${MTS}/uuid") + if ((${#uuid} == 0)) ; then + echo "${MTS}/uuid or ${MTS}/mac-eth must have a non-zero length value" + usage + fi + if ! [[ -f "${MTS}/uuid" ]] ; then + echo "${MTS}/uuid not found. Maybe mts-io driver is not loaded?" + exit 1 + fi + fi +fi + + + if ((upwd == 0)) ; then if ! [[ -f "${MTS}/device-id" ]] ; then echo "${MTS}/device-id not found. Maybe mts-io driver is not loaded?" exit 1 fi + did=$(cat "${MTS}/device-id") if ((${#did} == 0)) ; then @@ -156,6 +196,8 @@ if ((upwd == 0)) ; then else pwdsrc="-d ${did} -m ${mac}" fi + + if ((debug)) ; then echo Try this: echo "/sbin/mts-hashpwd ${pwdsrc} ${salt}" |