Skip to content

Instantly share code, notes, and snippets.

@nigjo
Last active April 9, 2018 14:57
Show Gist options
  • Save nigjo/e03b9ac581b416f823bc2eb38fb91820 to your computer and use it in GitHub Desktop.
Save nigjo/e03b9ac581b416f823bc2eb38fb91820 to your computer and use it in GitHub Desktop.
Create a local mirror of the Apache NetBeans Binary repository
@echo off
REM
REM Copyright 2018 Jens Hofschröer <netbeans-tools@nigjo.de>
REM Licensed under the Apache License, Version 2.0 (the "License");
REM you may not use this file except in compliance with the License.
REM You may obtain a copy of the License at
REM http://www.apache.org/licenses/LICENSE-2.0
REM Unless required by applicable law or agreed to in writing, software
REM distributed under the License is distributed on an "AS IS" BASIS,
REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
REM See the License for the specific language governing permissions and
REM limitations under the License.
REM
REM
REM # Read this before using this file
REM
REM USING THIS SCRIPT CREATES A BINARY DATA SINK!
REM
REM This script will create a full copy of the source web folder into the
REM current folder on your disc. All files together will be a couple of
REM gigabyte of data. A lot of it will not be used in recent versions of
REM Apache NetBeans.
REM For normal work with the Apache NetBeans sources this is not necessary.
REM See `${binaries.server}` and `${binaries.cache}` in `default-properties.xml`
REM in the `nbbuild` folder of the sources to determinate how to change all
REM necessary binaries-mirror-settings.
REM
REM If you do have a working local cache you probably don't need this script!
REM
setlocal
set "source=http://hg.netbeans.org/binaries/"
call :init
call :workflow
echo.
echo downloaded %dcounter%
echo skipped %scounter%
title done - %~nx0
pause
goto :eof
:download
set /a counter=%counter% + 1
set /a progress=((%counter% * 1000) / %maxcount%) / 10
set wintitle=update local mirror - %progress% %% - %~nx0
title %wintitle%
set "filename=%~1"
set "destfile=%filename%"
rem df:%destfile%
if "%filename%"=="" set destfile=%remoteindex%
if not "%filename%"=="" (
if not exist "%destfile:~0,2%" md "%destfile:~0,2%"
set "destfile=%destfile:~0,2%\%destfile%"
)
rem df:%destfile%
if exist "%destfile%" (
set /a scounter=%scounter% + 1
goto :eof
)
set /a dcounter=%dcounter% + 1
echo downloading "%filename%"
set pscmd=(New-Object Net.WebClient).DownloadFile('%source%/%filename%', '%destfile%')
set pscmd=$(Get-Host).UI.RawUI.WindowTitle='%wintitle%';%pscmd%
powershell -NonInteractive -NoLogo -NoProfile -C "%pscmd%"
goto :eof
:workflow
if exist "%remoteindex%" del "%remoteindex%"
set counter=0
set maxcount=1
call :download ""
title scanning index - %~nx0
set dcounter=0
set scounter=0
set counter=0
rem token #7 is a guess! TODO: find something more reliable.
for /f "tokens=2 delims=:" %%C in ('find /C /I "href=" "%remoteindex%"') do set maxcount=%%C
set /a maxcount-=2
echo countet %maxcount% files
for /F "skip=2 tokens=7 delims=<>" %%H in ('findstr /I /R "<a href=(.*)>.*</a>" "%remoteindex%"') do (
call :download "%%H"
)
goto :eof
:init
title init - %~nx0
powershell -C {$PSVersionTable.PSVersion} >nul
set remoteindex=remoteindex.html
goto :eof
REM A small download script to handle the subdirectories
REM ---8<--------8<--------8<--------8<--------8<--------8<--------8<-----
<?php
//binaries.server=http://localhost/binaries/dl.php?f=
$filename=filter_input(INPUT_GET, 'f', FILTER_SANITIZE_URL);
$filepath=substr($filename, 2) . '/' . $filename;
if(strpos($filepath, '/', 3) === FALSE && file_exist($filepath))
file($filepath);
else
header('HTTP/1.0 404 Not Found');
REM ---8<--------8<--------8<--------8<--------8<--------8<--------8<-----
@nigjo
Copy link
Author

nigjo commented Apr 6, 2018

Read this before using this file

This file will create a full copy of the source web folder in the current
folder on your disc. For normal work with the Apache NetBeans sources this
is not necessary. See ${binaries.server} and ${binaries.cache} in
default-properties.xml in the nbbuild folder of the sources to determinate
how to change all necessary binaries mirror settings.

If you do have a working local cache you probably don't need this script!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment