Skip to content

[massStorageCopy] Handle short node name #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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