Skip to content

Commit

Permalink
Merge pull request #61 from fpistm/nod_xxx
Browse files Browse the repository at this point in the history
[massStorageCopy] Handle short node name
  • Loading branch information
fpistm authored May 5, 2020
2 parents 33735fb + 0d8f0ce commit 7664bfa
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 17 deletions.
10 changes: 9 additions & 1 deletion linux/massStorageCopy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,16 @@ if [ ! -f "$bin_filepath" ]; then
exit 2
fi

# Add short node name
IFS=' ,\t' read -ra mnt_list <<< "$mountpoint_name"
for mnt in "${mnt_list[@]}"; do
if [[ "$mnt" == "NODE_"* ]]; then
mountpoint_name="${mountpoint_name},${mnt//E_/_}"
fi
done

# Search the mountpoint
IFS=',' read -ra mnt_list <<< "$mountpoint_name"
IFS=' ,\t' read -ra mnt_list <<< "$mountpoint_name"
for mnt in "${mnt_list[@]}"; do
# mnt_path_list=(`cat /proc/mounts | cut -d' ' -f2 | sort -u | grep $mnt`)
mnt_path_list=($(df -Hl | grep -v "Mounted on" | rev | cut -d' ' -f1 | rev | sort -u | grep "$mnt"))
Expand Down
10 changes: 9 additions & 1 deletion macosx/massStorageCopy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,16 @@ if [ ! -f "$bin_filepath" ]; then
exit 2
fi

# Add short node name
IFS=' ,\t' read -ra mnt_list <<< "$mountpoint_name"
for mnt in "${mnt_list[@]}"; do
if [[ "$mnt" == "NODE_"* ]]; then
mountpoint_name="${mountpoint_name},${mnt//E_/_}"
fi
done

# Search the mountpoint
IFS=',' read -ra mnt_list <<< "$mountpoint_name"
IFS=' ,\t' read -ra mnt_list <<< "$mountpoint_name"
for mnt in "${mnt_list[@]}"; do
mnt_path_list=($(df -Hl | grep -v "Mounted on" | rev | cut -d' ' -f1 | rev | sort -u | grep "$mnt"))
if [ ${#mnt_path_list[@]} -ne 0 ]; then
Expand Down
40 changes: 25 additions & 15 deletions win/massStorageCopy.bat
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
@ECHO off
@echo off

REM Exit codes for xcopy
REM code | Description
REM 0 | Files were copied without error.
REM 1 | No files were found to copy.
REM 2 | The user pressed CTRL+C to terminate xcopy.
REM 4 | Initialization error occurred. There is not enough memory or disk space, or you entered an invalid drive name or invalid syntax on the command line.
REM 5 | Disk write error occurred.
rem Exit codes for xcopy
rem code | Description
rem 0 | Files were copied without error.
rem 1 | No files were found to copy.
rem 2 | The user pressed CTRL+C to terminate xcopy.
rem 4 | Initialization error occurred. There is not enough memory or disk space, or you entered an invalid drive name or invalid syntax on the command line.
rem 5 | Disk write error occurred.

SET SOURCE=%2
SET SRC_PARSE=%SOURCE:/=\%
SET TARGET=%4
SET TARGET=%TARGET:\=%
set SOURCE=%2
set SRC_PARSE=%SOURCE:/=\%
set TARGET=%4
set TARGET=%TARGET:\=%

call :parse %TARGET%
echo %TARGET% not found. Please ensure the device is correctly connected.
Expand All @@ -21,19 +21,29 @@ exit 7
set list=%1
set list=%list:"=%

for /f "tokens=1* delims=," %%a in ("%list%") DO (
for /f "tokens=1* delims=," %%a in ("%list%") do (
if not "%%a" == "" call :sub %%a
if not "%%a" == "" call :nod %%a
if not "%%b" == "" call :parse "%%b"
)
goto :eof

rem Try with the short name NOD_XXX
:nod
setlocal enabledelayedexpansion
echo.%~1|findstr /C:"NODE_" >nul 2>&1
if not errorlevel 1 (
set name=%~1
call :sub !name:E_=_!
)
goto :eof

:sub
setlocal enabledelayedexpansion
for /F "skip=1 tokens=*" %%a in ('WMIC LOGICALDISK where "volumename like '%~1'" get deviceid 2^>NUL') do if not defined id set id=%%a
call Set "deviceid=%%id: =%%"
call set "deviceid=%%id: =%%"
if not "%deviceid%" == "" (
XCOPY %SRC_PARSE% %deviceid% /Y /Q
if !errorlevel! == 0 (echo Upload complete on %1 ^(%deviceid%^))
if !errorlevel! == 0 (echo Upload complete on %1 ^(%deviceid%^))
exit !errorlevel!)
goto :eof

0 comments on commit 7664bfa

Please sign in to comment.