duplicati_setup/duplicati_install_script/setup_duplicati.bat

196 lines
5.9 KiB
Batchfile

@echo off
title %~nx0
set local
cls
:START
echo.
echo Copyright -- Matthew Shillam -- 2018
echo.
echo ---------------------------------------------------------------------------
echo %date% %time% - Duplicati Install started
echo ---------------------------------------------------------------------------
echo.
set RESTART=0
:GETOSVERSION
SET OSVersion=Unknown
VER | FINDSTR /L "5.0" > NUL
IF %ERRORLEVEL% EQU 0 SET OSversion="2000"& SET OSDescription="Windows 2000"
VER | FINDSTR /L "5.1" > NUL
IF %ERRORLEVEL% EQU 0 SET OSversion="XP"& SET OSDescription="Windows XP"
VER | FINDSTR /L "5.2" > NUL
IF %ERRORLEVEL% EQU 0 SET OSversion="2003"& SET OSDescription="Windows XP Pro x64 | Windows Server 2003"
VER | FINDSTR /L "6.0" > NUL
IF %ERRORLEVEL% EQU 0 SET OSversion="Vista"& SET OSDescription="Windows Vista | Windows Server 2008"
VER | FINDSTR /L "6.1" > NUL
IF %ERRORLEVEL% EQU 0 SET OSversion="7"& SET OSDescription="Windows 7 | Windows Server 2008 R2"
VER | FINDSTR /L "6.2" > NUL
IF %ERRORLEVEL% EQU 0 SET OSversion="8"& SET OSDescription="Windows 8 | Windows Server 2012"
VER | FINDSTR /L "6.3" > NUL
IF %ERRORLEVEL% EQU 0 SET OSversion="8.1"& SET OSDescription="Windows 8.1 | Windows Server 2012 R2"
VER | FINDSTR /L "10.0" > NUL
IF %ERRORLEVEL% EQU 0 SET OSversion="10"& SET OSDescription="Windows 10 | Windows Server 2016"
IF %OSVersion%==Unknown (
echo.
echo Unable to Determine your operating system, it must be old!
) ELSE (
echo.
echo You appear to be using %OSDescription%
)
reg Query "HKLM\Hardware\Description\System\CentralProcessor\0" | find /i "x86" > NUL && set OSTYPE=32Bit || set OSTYPE=64Bit
if %OSTYPE%==64Bit (
reg query HKEY_CLASSES_ROOT\Installer\Dependencies\,,amd64,14.0,bundle 1>NUL || "%~dp0bin\vc_redist.x64.exe" /norestart
)
if %OSTYPE%==32Bit (
reg query HKEY_CLASSES_ROOT\Installer\Dependencies\,,x86,14.0,bundle 1>NUL || "%~dp0bin\vc_redist.x32.exe" /norestart
)
:DUPLICATIINSTALL
echo .
echo Installing duplicati binary...
echo Ensure that you deselect run at startup to ensure service works proper!
echo Also! Ensure you do not run duplicati after install has completed!!
start /wait msiexec /i "%~dp0bin\duplicati-2.0.3.11_canary_2018-09-05-x64.msi"
goto GETPROGRAMPATH
:GETPROGRAMPATH
SET NUL=NUL
IF "%OS%"=="Windows_NT" SET NUL=
echo.
echo ---------------------------------------------------------------------------
SET "PROGRAMFOLDER=C:\Program Files\Duplicati 2\"
IF EXIST "C:\Program Files (x86)\Duplicati 2\%NUL%" ( SET "PROGRAMFOLDER=C:\Program Files (x86)\Duplicati 2\" )& echo Program path is: "C:\Program Files (x86)\Duplicati 2\"
IF EXIST "C:\Program Files\Duplicati 2\%NUL%" ( SET "PROGRAMFOLDER=C:\Program Files\Duplicati 2\")& echo Program path is: "C:\Program Files\Duplicati 2\"
:SERVICECHECK
Set ServiceName=Duplicati
SC QUERY %ServiceName% > NUL
IF ERRORLEVEL 1060 GOTO SETUPSERVICE
echo %ServiceName% service already installed, skipping service install...
echo.
GOTO STARTSERVICE
:SETUPSERVICE
set "execpath=%PROGRAMFOLDER%\Duplicati.WindowsService.exe"
"%execpath%" install --webservice-interface=127.0.0.1 --webservice-port=8200 --portable-mode
echo .
GOTO STARTSERVICE
:STARTSERVICE
SC queryex "%ServiceName%"|Find "STATE"|Find /v "RUNNING">Nul&&(
echo %ServiceName% not running...
echo Starting %ServiceName%...
NET start "%ServiceName%">nul||(
Echo "%ServiceName%" wont start
)
echo "%ServiceName%" started
)||(
echo "%ServiceName%" working
)
:GETCLIENTNAME
echo Enter client name ( In email eg: client-mat-is-ace )? :
set /p CLIENTNAME=
echo.
echo ---------------------------------------------------------------------------
echo Ok -- %CLIENTNAME% it is...
echo ---------------------------------------------------------------------------
echo.
goto GETSCHEDULES
:GETSCHEDULES
set FILEXRAYS="schedule-xrays-%CLIENTNAME%.json"
set FILEDATABASE="schedule-database-%CLIENTNAME%.json"
set FILEDOCUMENTS="schedule-documents-%CLIENTNAME%.json"
"%~dp0bin\winscp.com" /ini=nul /command ^
"open sftp://mrdownloader@mydentalbackup.co.uk:5349/ -hostkey=""ssh-ed25519 256 PTL6imOWXdhJQEuBThd8yfozcuOtOxpKEZs0hOGZh3c="" -privatekey=""%~dp0bin\id_deployer2.ppk""" ^
"cd /home/mydentalbackup.co.uk/files" ^
"lcd %~dp0bin" ^
"get %FILEDATABASE%" "get %FILEDOCUMENTS%" "get %FILEXRAYS%" ^
"close" ^
"exit"
goto ADDSCHEDULES
:ADDSCHEDULES
"%~dp0bin\duplicati_client.exe" login http://127.0.0.1:8200
"%~dp0bin\duplicati_client.exe" create backup "%~dp0bin\schedule-database-%CLIENTNAME%.json"
"%~dp0bin\duplicati_client.exe" create backup "%~dp0bin\schedule-documents-%CLIENTNAME%.json"
"%~dp0bin\duplicati_client.exe" create backup "%~dp0bin\schedule-xrays-%CLIENTNAME%.json"
goto SORTCHORTCUTS
:SORTCHORTCUTS
echo Removing shortcut from desktop...
echo.
del "%USERPROFILE%\Desktop\Duplicati 2.lnk"
echo.
echo Adding new shortcut to desktop
xcopy "%~dp0bin\Duplicati 2 start.lnk" "%USERPROFILE%\Desktop"
:EXITNOW
echo.
echo.
echo ---------------------------------------------------------------------------
echo.
echo Ok -- if all went well you should see no errors above... Scroll up
echo and check!!! ( yes you John! )
echo.
echo ---------------------------------------------------------------------------
echo. & echo %date% %time% - %~nx0 ended & echo.
Cmd /k
:EXITCLOSE