diff --git a/src/main/scripts/unix/cryo-em/cryoem-download-aterm-script-url-create b/src/main/scripts/unix/facility/facility-download-aterm-script-url-create similarity index 99% rename from src/main/scripts/unix/cryo-em/cryoem-download-aterm-script-url-create rename to src/main/scripts/unix/facility/facility-download-aterm-script-url-create index 55c6c792651a91318f69a2b8eac55e832053a596..ba172e1db9c80f2f4bea3a66ee6a0c60d363158c 100755 --- a/src/main/scripts/unix/cryo-em/cryoem-download-aterm-script-url-create +++ b/src/main/scripts/unix/facility/facility-download-aterm-script-url-create @@ -7,6 +7,7 @@ VERBOSE=true NCSR=4 # root namespace for cryo-em projects +# Set this to the correct parent when deploying NAMESPACE_ROOT=/projects/cryo-em # aterm.jar download url diff --git a/src/main/scripts/unix/cryo-em/cryoem-download-shell-script-url-create b/src/main/scripts/unix/facility/facility-download-shell-script-url-create similarity index 98% rename from src/main/scripts/unix/cryo-em/cryoem-download-shell-script-url-create rename to src/main/scripts/unix/facility/facility-download-shell-script-url-create index 28216d896013f8a1bc4edb8d67b9ee235e2e485a..f15b7686f48c0909328ae7715d16909112997881 100755 --- a/src/main/scripts/unix/cryo-em/cryoem-download-shell-script-url-create +++ b/src/main/scripts/unix/facility/facility-download-shell-script-url-create @@ -5,7 +5,8 @@ EXPIRE_DAYS=14 OVERWRITE=false VERBOSE=true -# root namespace for cryo-em projects +# root namespace for projects +# Set this to the correct parent when deploying NAMESPACE_ROOT=/projects/cryo-em # aterm.jar download url diff --git a/src/main/scripts/windows/cryo-em/cryoem-download-aterm-script-url-create.cmd b/src/main/scripts/windows/facility/facility-download-aterm-script-url-create.cmd similarity index 88% rename from src/main/scripts/windows/cryo-em/cryoem-download-aterm-script-url-create.cmd rename to src/main/scripts/windows/facility/facility-download-aterm-script-url-create.cmd index 2439557727987cb06a841832c6222d496f12db9d..2dc6c34a544eef78ba7a86885f976c332dde4574 100644 --- a/src/main/scripts/windows/cryo-em/cryoem-download-aterm-script-url-create.cmd +++ b/src/main/scripts/windows/facility/facility-download-aterm-script-url-create.cmd @@ -1,6 +1,12 @@ @echo off setlocal EnableExtensions EnableDelayedExpansion +REM This is the root namespace for projects to be located in. +REM The caller specifies only the project ID +REM Needs to be enhanced to allow for projects in /projects (fails if you change the root to that) +REM When this script is deployed, you must set the root namespace correctly. +set NAMESPACE_ROOT=/projects/cryo-em + REM check java where java >nul 2>nul IF %errorlevel% neq 0 ( @@ -49,9 +55,6 @@ set EXPIRE_DAYS=14 set OVERWRITE=false set VERBOSE=true -REM cryo-em project root namespace -set NAMESPACE_ROOT=/projects/cryo-em - REM set PROJECT= set ROLE= @@ -60,7 +63,7 @@ set EMAILS= REM parse arguments :loop -if not [%~1]==[] ( +if "%~1" NEQ "" ( if "%~1"=="--ncsr" ( set NCSR=%~2 shift @@ -84,7 +87,7 @@ if not [%~1]==[] ( goto :loop ) if "%~1"=="--email" ( - set value=%~2 + set "value=%~2" set value=!value:,= ! for %%e in (!value!) do ( if "!EMAILS!"=="" ( set "EMAILS=:to %%e" ) else ( set "EMAILS=!EMAILS! :to %%e" ) @@ -121,17 +124,17 @@ if not [%~1]==[] ( exit /b 1 ) ) - if [!NAMESPACES!]==[] ( - set "NAMESPACES=:namespace !ns!" + if "!NAMESPACES!" EQU "" ( + set "NAMESPACES=:namespace ^"!ns!^"" ) else ( - set "NAMESPACES=!NAMESPACES! :namespace !ns!" + set "NAMESPACES=!NAMESPACES! :namespace ^"!ns!^"" ) shift goto :loop ) REM check if namespace is specified -if "%NAMESPACES%"=="" ( +if "!NAMESPACES!"=="" ( echo Error: no namespace is specified. call :usage exit /b 1 diff --git a/src/main/scripts/windows/cryo-em/cryoem-download-shell-script-url-create.cmd b/src/main/scripts/windows/facility/facility-download-shell-script-url-create.cmd similarity index 91% rename from src/main/scripts/windows/cryo-em/cryoem-download-shell-script-url-create.cmd rename to src/main/scripts/windows/facility/facility-download-shell-script-url-create.cmd index 7f7093adc99f3325c598f054522851afbcdf7180..8d3e515ee2a8c56a4b2814a7ec5c3b7378ca546d 100644 --- a/src/main/scripts/windows/cryo-em/cryoem-download-shell-script-url-create.cmd +++ b/src/main/scripts/windows/facility/facility-download-shell-script-url-create.cmd @@ -1,191 +1,195 @@ -@echo off -setlocal EnableExtensions EnableDelayedExpansion - -REM check java -where java >nul 2>nul -IF %errorlevel% neq 0 ( - echo error: no java is found. Install java and retry. - exit /b 1 -) - -REM script file name -set PROG=%~0 - -REM aterm.jar download url -set ATERM_URL=https://mediaflux.researchsoftware.unimelb.edu.au/mflux/aterm.jar - -REM aterm.jar location -if [%MFLUX_ATERM%]==[] set "MFLUX_ATERM=%~dp0..\..\..\lib\aterm.jar" -if not exist "%MFLUX_ATERM%" ( - set "MFLUX_ATERM=%USERPROFILE%\.Arcitecta\aterm.jar" - if not exist %USERPROFILE%\.Arcitecta\NUL mkdir "%USERPROFILE%\.Arcitecta" - call :download !ATERM_URL! !MFLUX_ATERM! - if !errorlevel! neq 0 exit /b 1 -) - -REM mflux.cfg location -if [%MFLUX_CFG%]==[] set "MFLUX_CFG=%USERPROFILE%\.Arcitecta\mflux.cfg" -if not exist "%MFLUX_CFG%" set "MFLUX_CFG=%~dp0..\..\..\config\mflux.cfg" -if not exist "%MFLUX_CFG%" set "MFLUX_CFG=%~dp0..\..\..\mflux.cfg" -if not exist "%MFLUX_CFG%" set "MFLUX_CFG=%~dp0mflux.cfg" -if not exist "%MFLUX_CFG%" ( - set "MFLUX_CFG=%USERPROFILE%\.Arcitecta\mflux.cfg" - echo error: could not find %MFLUX_CFG% - exit /b 1 -) - -REM aterm command prefix -set "ATERM=java -jar -Dmf.cfg=%MFLUX_CFG% %MFLUX_ATERM% nogui" - -REM service name -set "SERVICE=unimelb.asset.download.shell.script.url.create" - -REM command (prefix) -set "COMMAND=%ATERM% %SERVICE%" - -REM default argument values -set EXPIRE_DAYS=14 -set OVERWRITE=false -set VERBOSE=true - -REM cryo-em project root namespace -set NAMESPACE_ROOT=/projects/cryo-em - -REM -set PROJECT= -set ROLE= -set NAMESPACES= -set EMAILS= - -REM parse arguments -:loop -if not [%~1]==[] ( - if "%~1"=="--expire-days" ( - set EXPIRE_DAYS=%~2 - shift - shift - goto :loop - ) - if "%~1"=="--overwrite" ( - set OVERWRITE=true - shift - goto :loop - ) - if "%~1"=="--quiet" ( - set VERBOSE=false - shift - goto :loop - ) - if "%~1"=="--email" ( - set value=%~2 - set value=!value:,= ! - for %%e in (!value!) do ( - if "!EMAILS!"=="" ( set "EMAILS=:to %%e" ) else ( set "EMAILS=!EMAILS! :to %%e" ) - ) - shift - shift - goto :loop - ) - if "%~1"=="-h" ( - call :usage - exit /b 0 - ) - if "%~1"=="--help" ( - call :usage %PROG% - exit /b 0 - ) - set ns=%~1 - if "!ns:~0,18!"=="!NAMESPACE_ROOT!/" ( - for /f "delims=/" %%c in ("!ns:~18!") do ( - set "prj=%%c" - ) - ) else ( - for /f "delims=/" %%c in ("!ns!") do ( - set "prj=%%c" - ) - set "ns=!NAMESPACE_ROOT!/!ns!" - ) - if [!PROJECT!]==[] ( - set PROJECT=!prj! - set "ROLE=!prj!:participant-a" - ) else ( - if not "!PROJECT!"=="!prj!" ( - echo error: cannot share namespaces from multiple projects. - exit /b 1 - ) - ) - if [!NAMESPACES!]==[] ( - set "NAMESPACES=:namespace !ns!" - ) else ( - set "NAMESPACES=!NAMESPACES! :namespace !ns!" - ) - shift - goto :loop -) - -REM check if namespace is specified -if "%NAMESPACES%"=="" ( - echo error: no namespace is specified. - call :usage - exit /b 1 -) - -REM compose the command -set "COMMAND=%COMMAND% :download ^< %NAMESPACES% :token ^< :role -type role %ROLE% :to now+%EXPIRE_DAYS%day ^> :verbose %VERBOSE% :overwrite %OVERWRITE% ^> :token ^< :perm ^< :resource -type role:namespace %PROJECT%: :access ADMINISTER ^> ^>" - -if not "%EMAILS%"=="" ( - set "COMMAND=%COMMAND% :email ^< %EMAILS% ^>" -) - -REM execute aterm command to generate the script url -%COMMAND% - -if %errorlevel% neq 0 ( - exit /b 2 -) -exit /b 0 - -REM function to print usage -:usage -echo= -echo Usage: -echo %PROG% [-h^|--help] [--expire-days ^<number-of-days^>] [--ncsr ^<ncsr^>] [--overwrite] [--quiet] [--email ^<addresses^>] ^<namespace^> -echo= -echo Options: -echo -h ^| --help prints usage -echo --email ^<addresses^> specify the email recipient of the generated url. Can be comma-separated if there are more than one. NOTE: your need quote the comma separated values like --email "user1@domain1.org,user2@domain2.org" -echo --expire-days ^<number-of-days^> expiry of the auth token. Defaults to ${EXPIRE_DAYS} days. -echo --overwrite overwrite if output file exists. -echo --quiet do not print output message. -echo= -echo Positional arguments: -echo ^<namespace^> Mediaflux asset namespace to be downloaded by the scripts. Can be multiple, but must be from the same project. -echo= -echo Examples: -echo %PROG% --email user1@unimelb.edu.au --expire-days 10 proj-abc-1128.4.999/RAW_DATA proj-abc-1128.4.999/PROCESSED_DATA -echo= -exit /b 0 - -REM function to download from url -:download -setlocal -set url=%~1 -set out=%~2 -if not exist %out% ( - where powershell >nul 2>nul - if %errorlevel% equ 0 ( - echo downloading %out% - powershell -command "(New-Object Net.WebClient).DownloadFile('%url%', '%out%')" >nul 2>nul - if %errorlevel% neq 0 ( - echo error: failed to download %url% - exit /b 1 - ) - if not exist "%out%" ( - echo error: failed to download %url% to %out% - exit /b 1 - ) - ) else ( - echo error: cannot download %out%. No powershell found. - exit /b 1 - ) -) +@echo off +setlocal EnableExtensions EnableDelayedExpansion + +REM This is the root namespace for projects to be located in. +REM The caller specifies only the project ID +REM Needs to be enhanced to allow for projects in /projects (fails if you change the root to that) +REM When this script is deployed, you must set the root namespace correctly. +set NAMESPACE_ROOT=/projects/cryo-em + +REM check java +where java >nul 2>nul +IF %errorlevel% neq 0 ( + echo error: no java is found. Install java and retry. + exit /b 1 +) + +REM script file name +set PROG=%~0 + +REM aterm.jar download url +set ATERM_URL=https://mediaflux.researchsoftware.unimelb.edu.au/mflux/aterm.jar + +REM aterm.jar location +if [%MFLUX_ATERM%]==[] set "MFLUX_ATERM=%~dp0..\..\..\lib\aterm.jar" +if not exist "%MFLUX_ATERM%" ( + set "MFLUX_ATERM=%USERPROFILE%\.Arcitecta\aterm.jar" + if not exist %USERPROFILE%\.Arcitecta\NUL mkdir "%USERPROFILE%\.Arcitecta" + call :download !ATERM_URL! !MFLUX_ATERM! + if !errorlevel! neq 0 exit /b 1 +) + +REM mflux.cfg location +if [%MFLUX_CFG%]==[] set "MFLUX_CFG=%USERPROFILE%\.Arcitecta\mflux.cfg" +if not exist "%MFLUX_CFG%" set "MFLUX_CFG=%~dp0..\..\..\config\mflux.cfg" +if not exist "%MFLUX_CFG%" set "MFLUX_CFG=%~dp0..\..\..\mflux.cfg" +if not exist "%MFLUX_CFG%" set "MFLUX_CFG=%~dp0mflux.cfg" +if not exist "%MFLUX_CFG%" ( + set "MFLUX_CFG=%USERPROFILE%\.Arcitecta\mflux.cfg" + echo error: could not find %MFLUX_CFG% + exit /b 1 +) + +REM aterm command prefix +set "ATERM=java -jar -Dmf.cfg=%MFLUX_CFG% %MFLUX_ATERM% nogui" + +REM service name +set "SERVICE=unimelb.asset.download.shell.script.url.create" + +REM command (prefix) +set "COMMAND=%ATERM% %SERVICE%" + +REM default argument values +set EXPIRE_DAYS=14 +set OVERWRITE=false +set VERBOSE=true + +REM +set PROJECT= +set ROLE= +set NAMESPACES= +set EMAILS= + +REM parse arguments +:loop +if "%~1" NEQ "" ( + if "%~1"=="--expire-days" ( + set EXPIRE_DAYS=%~2 + shift + shift + goto :loop + ) + if "%~1"=="--overwrite" ( + set OVERWRITE=true + shift + goto :loop + ) + if "%~1"=="--quiet" ( + set VERBOSE=false + shift + goto :loop + ) + if "%~1"=="--email" ( + set "value=%~2" + set value=!value:,= ! + for %%e in (!value!) do ( + if "!EMAILS!"=="" ( set "EMAILS=:to %%e" ) else ( set "EMAILS=!EMAILS! :to %%e" ) + ) + shift + shift + goto :loop + ) + if "%~1"=="-h" ( + call :usage + exit /b 0 + ) + if "%~1"=="--help" ( + call :usage %PROG% + exit /b 0 + ) + + + set ns=%~1 + if "!ns:~0,18!"=="!NAMESPACE_ROOT!/" ( + for /f "delims=/" %%c in ("!ns:~18!") do ( + set "prj=%%c" + ) + ) else ( + for /f "delims=/" %%c in ("!ns!") do ( + set "prj=%%c" + ) + set "ns=!NAMESPACE_ROOT!/!ns!" + ) + + if [!PROJECT!]==[] ( + set PROJECT=!prj! + set "ROLE=!prj!:participant-a" + ) else ( + if not "!PROJECT!"=="!prj!" ( + echo error: cannot share namespaces from multiple projects. + exit /b 1 + ) + ) + if "!NAMESPACES!" EQU "" ( + set "NAMESPACES=:namespace ^"!ns!^"" + ) else ( + set "NAMESPACES=!NAMESPACES! :namespace ^"!ns!^"" + ) + shift + goto :loop +) + +REM check if namespace is specified +if "!NAMESPACES!"=="" ( + echo error: no namespace is specified. + call :usage + exit /b 1 +) +REM compose the command +set "COMMAND=%COMMAND% :download ^< %NAMESPACES% :token ^< :role -type role %ROLE% :to now+%EXPIRE_DAYS%day ^> :verbose %VERBOSE% :overwrite %OVERWRITE% ^> :token ^< :perm ^< :resource -type role:namespace %PROJECT%: :access ADMINISTER ^> ^>" +if not "%EMAILS%"=="" ( + set "COMMAND=%COMMAND% :email ^< %EMAILS% ^>" +) + +REM execute aterm command to generate the script url +%COMMAND% + +if %errorlevel% neq 0 ( + exit /b 2 +) +exit /b 0 + +REM function to print usage +:usage +echo= +echo Usage: +echo %PROG% [-h^|--help] [--expire-days ^<number-of-days^>] [--ncsr ^<ncsr^>] [--overwrite] [--quiet] [--email ^<addresses^>] ^<namespace^> +echo= +echo Options: +echo -h ^| --help prints usage +echo --email ^<addresses^> specify the email recipient of the generated url. Can be comma-separated if there are more than one. NOTE: your need quote the comma separated values like --email "user1@domain1.org,user2@domain2.org" +echo --expire-days ^<number-of-days^> expiry of the auth token. Defaults to ${EXPIRE_DAYS} days. +echo --overwrite overwrite if output file exists. +echo --quiet do not print output message. +echo= +echo Positional arguments: +echo ^<namespace^> Mediaflux asset namespace to be downloaded by the scripts. Can be multiple, but must be from the same project. +echo= +echo Examples: +echo %PROG% --email user1@unimelb.edu.au --expire-days 10 proj-abc-1128.4.999/RAW_DATA proj-abc-1128.4.999/PROCESSED_DATA +echo= +exit /b 0 + +REM function to download from url +:download +setlocal +set url=%~1 +set out=%~2 +if not exist %out% ( + where powershell >nul 2>nul + if %errorlevel% equ 0 ( + echo downloading %out% + powershell -command "(New-Object Net.WebClient).DownloadFile('%url%', '%out%')" >nul 2>nul + if %errorlevel% neq 0 ( + echo error: failed to download %url% + exit /b 1 + ) + if not exist "%out%" ( + echo error: failed to download %url% to %out% + exit /b 1 + ) + ) else ( + echo error: cannot download %out%. No powershell found. + exit /b 1 + ) +)