D
D
dxangelo2014-04-24 22:15:03
MongoDB
dxangelo, 2014-04-24 22:15:03

MongoDB, install from bat-file, how to search for new version?

Automated installation of MongoDB in a bat file. Up to downloading, various checks and installation as a service.
Everything works... But I would like to add a search on the site for the current latest version and its installation, and not specifically specified in the file, because download links have to be registered manually.
And, accordingly, the question is, if anyone can help:
How can I access the mongo site from the batch file, check the latest version and download it or provide a choice?
Thanks in advance to those who will not pass by and at least somehow help or advise!

::::::::::::::::::::
::::: СИСТЕМА ::::::
::::::::::::::::::::

::Определяем битность системы и создаем переменную
ECHO OFF
set xOS=x32
set zOS=
if DEFINED ProgramFiles(x86) set xOS=x64
if DEFINED ProgramFiles(x86) set zOS=64

::::::::::::::::::::
::: MONGODB 2.6 ::::
::::::::::::::::::::
set mongodb1=mongodb-win32-i386-2.6.0
set mongodb2=mongodb-win32-x86_64-2008plus-2.6.0
set mongodb3=mongodb-win32-x86_64-2.6.0
::Проверяем есть ли скачанные файлы
IF EXIST %mongodb1%.zip 
  (
  set mongoversion=%mongodb1%
  unzip -l "%mongoversion%.zip"
  ) ELSE 
    (
    IF EXIST %mongodb2%.zip 
      (
      set mongoversion=%mongodb2%
      unzip -l "%mongoversion%.zip"
      ) ELSE 
        (
        IF EXIST %mongodb3%.zip 
          (
          set mongoversion=%mongodb3%
          unzip -l "%mongoversion%.zip"
          ) ELSE 
            ( 
            ::Скачиваем дистрибутив в соответствии с битностью системы
            choice /c 1230 /M "1 - mongodb-i386-2.6.0, 2 - mongodb-x86_64-2008plus-2.6.0., 3 - mongodb-x86_64-2.6.0, 0 - None"
            IF ERRORLEVEL 1 SET urlmongo=mongodb-win32-i386-2.6.0
            IF ERRORLEVEL 2 SET urlmongo=mongodb-win32-x86_64-2008plus-2.6.0
            IF ERRORLEVEL 3 SET urlmongo=mongodb-win32-x86_64-2.6.0
            IF ERRORLEVEL 4 SET urlmongo=None
            curl -f -# -O  -k https://fastdl.mongodb.org/win32/%urlmongo%.zip
            ::Распаковываем дистрибутив
            unzip -l "%urlmongo%.zip"
            )
        )
    )

::Объявляем переменную
set mongodb=d:\server\mongodb
::Создаём каталоги
mkdir %mongodb%\2.6-database >nul 2>nul
mkdir %mongodb%\2.6-server >nul 2>nul
mkdir %mongodb%\2.6-log >nul 2>nul
mkdir %mongodb%\2.6-config >nul 2>nul
::Создаем файл конфигов с указанием папки логов, папки хранения данных и смены порта 27017 по умолчанию на 3333
echo logpath=d:\server\mongodb\2.6-log\mongod.log> "%mongodb%\2.6-config\mongod.cfg"
echo dbpath=d:\server\mongodb\2.6-database>> "%mongodb%\2.6-config\mongod.cfg"
echo port=6666>> "d:\server\mongodb\2.6-config\mongod.cfg"
::Копируем файлы
copy %mongoversion%\bin %mongodb%\2.6-server\
::Инсталлируем
%mongodb%\2.6-server\mongod.exe --config %mongodb%\2.6-config\mongod.cfg --install
::Создаем службу с именем MongoDB
sc.exe create MongoDB-%xOS% binPath= "\"%mongodb%\2.6-server\mongod.exe\" --service --config=\"%mongodb%\2.6-config\mongod.cfg\"" DisplayName= "MongoDB-%xOS% (%mongoversion%)" start= "auto"
::Запускаем службу
net start MongoDB-%xOS%

The code is not final, so do not judge strictly. I'm not good at this (... I will gradually bring it to a good look and condition... For me, the main thing is that it works)))
Used third-party programs: curl.exe and unzip.exe

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question