cURL – Latest Chromium Downloader

echo off
::stuff you can modify.
::--------------------------------------------------------------------------------
::                          http|https
set PROTOCOL=http
::                          snapshots|continuous
set BRANCH=snapshots
::                          Android|Arm|Linux|LinuxGit|LinuxGit_x64|Linux_ARM_Cross-Compile|Linux_ChromiumOS|Linux_ChromiumOS_Full|Linux_x64|Mac|MacGit|Win|WinGit|Win_x64|chromium-full-linux-chromeos
set OS=Win_x64
::                          mini_installer.exe|REVISIONS|chrome-win32-syms.zip|chrome-win32.zip|pnacl.zip|content-shell.zip|gcapi.zip|metrics-metadata.zip|remoting-host.msi|remoting-me2me-host-win.zip|devtools_frontend.zip|chrome-linux.zip|changelog.xml|chrome-android.zip
set FILE=mini_installer.exe
::--------------------------------------------------------------------------------


::stuff you should keep as is.
::--------------------------------------------------------------------------------
set URL_LASTCHANGE=%PROTOCOL%://storage.googleapis.com/chromium-browser-%BRANCH%/%OS%/LAST_CHANGE

set COMMAND_CURL_FORVERSION=curl.exe --silent --http2 --ipv4 --anyauth --insecure --location-trusted --ssl-allow-beast --ssl-no-revoke --url "%URL_LASTCHANGE%"

set VERSION=
for /f "tokens=*" %%a in ('call %COMMAND_CURL_FORVERSION% 2^>^&1') do (set VERSION=%%a)
::error handling
if ["%VERSION%"] == [""] ( goto NOVERSION )
set URL_DOWNLOAD=%PROTOCOL%://storage.googleapis.com/chromium-browser-%BRANCH%/%OS%/%VERSION%/%FILE%

echo.
echo Got Latest-Version: ^>%VERSION%^< ^[Branch:%BRANCH%/OS:%OS%^]
::--------------------------------------------------------------------------------


::you should enable one-of-your-prefered downloaders.
::goto DOWNLOAD_CURL
::goto DOWNLOAD_WGET
::goto DOWNLOAD_ORBITDOWNLOADER
goto DOWNLOAD_ARIA2C



::you should not reach here, unless
::you've forgot to enable one of the "downloader lines" (above)...
goto NODOWNLOADER


::--------------------------------------------------------------------------------
:NOVERSION
  echo ERROR: could not get the latest version...
  goto EXIT

:NODOWNLOADER
  echo ERROR: please enable one of the downloader lines..
  goto EXIT


:DOWNLOAD_CURL
  echo Start Download using cURL...
  call curl.exe --verbose --http2 --ipv4 --ignore-content-length ^
                --anyauth --insecure --location-trusted          ^
                --ssl-allow-beast --ssl-no-revoke --tcp-fastopen ^
                --tcp-nodelay --use-ascii --url "%URL_DOWNLOAD%"
  goto EXIT


:DOWNLOAD_WGET
  echo Start Download using wGET...
  call wget.exe --directory-prefix="." --debug --user-agent="Mozilla/5.0 Chrome" --continue ^
                --server-response --no-check-certificate --secure-protocol=auto  "%URL_DOWNLOAD%"
  goto EXIT


:DOWNLOAD_ARIA2C
  echo Start Download using Aria2C...
  call aria2c.exe --allow-overwrite=true         --auto-file-renaming=false         --check-certificate=false        ^
                  --check-integrity=false        --connect-timeout=120              --console-log-level=notice       ^
                  --continue=true                --dir="."                          --disable-ipv6=true              ^
                  --enable-http-keep-alive=true  --enable-http-pipelining=true      --file-allocation=prealloc       ^
                  --http-auth-challenge=false    --human-readable=true              --max-concurrent-downloads=16    ^
                  --max-connection-per-server=16 --max-tries=3                      --min-split-size=1M              ^
                  --retry-wait=1                 --rpc-secure=false                 --split=8                        ^
                  --timeout=120                  --user-agent="Mozilla/5.0 Chrome"  "%URL_DOWNLOAD%"
  goto EXIT


:DOWNLOAD_ORBITDOWNLOADER
  echo Start Download using OrbitDownloader...
  call "C:\Program Files (x86)\Orbitdownloader\orbitdm.exe" "%URL_DOWNLOAD%"
  goto EXIT


:EXIT  
  echo.
  echo Done.
  pause


::--------------------------------------------------------------------------------------------
::--------------------------------------------------------------------------------------------
::
::   - "http"           - http protocol is faster to connect and download with OrbitDownloader and wGet, it also means your PC won't preform certificate exchange with the remote machine.
::   - "snapshots"      - snapshots is newer, "continuous" is more stable (but might be very old).
::   - "OS" and "FILE"  - are what you want to download
::
::
:: snapshots    - newest (unstable) newest code-changes - passed unit-tests + compilation.
:: continuous   - old    (stable)                       - passed unit-tests + compilation + test-suits.
:: ------------------------------------------------------------------------------------------------------
::   branch   |  branch description           |  version-based build
:: ___________|_______________________________|_____________________________________________________________________________________________
::   Win_x64  |  Chromium Installer (64-bit)  |  storage.googleapis.com/chromium-browser-continuous/Win_x64/{version}/mini_installer.exe  
::   Win_x64  |  Chromium Package (64-bit)    |  storage.googleapis.com/chromium-browser-continuous/Win_x64/{version}/chrome-win32.zip    
::   Win      |  Chromium Installer (32-bit)  |  storage.googleapis.com/chromium-browser-continuous/Win/{version}/mini_installer.exe
::   Win      |  Chromium Package (64-bit)    |  storage.googleapis.com/chromium-browser-continuous/Win/{version}/chrome-win32.zip    
::
::
::------------------------------------------------------
::- SCRIPT WAS WRITTEN AND MAINTAINED BY ELAD KARAKO.  -
::- LAST UPDATED: JULY, 2017. FREE TO USE UNDER GNU.   -
::------------------------------------------------------

Download tools..

Unix Snippet – Get File’s “Touch Date-Format” One-Liner

Pipelining the modification date from stat into an inline-date-phrase using the date --date="@... directive (using read to locate the pipeline’s output in the middle of the date-phrase),
And you’ve got yourself a nice little converter, which you can customise, to use *any* date-format,
I’ve using the Universal Time Coordinated standard.

file name:          my_file.txt
unix time-format:   1458036575     (Asia/Jerusalem)
touch time-format:  201603151009   (UTC)
stat --format=%Y "my_file.txt" | { read -r tmp_date; date --utc --date="@$tmp_date" "+%C%y%m%d%H%M"; }

*Ps.
You can easily use the touch-date-format with touch command using the following directive:
touch -t 201603151009 --time=mtime my_file.txt;
but make sure first you set the local-timezone to same timezone it was generated on.
TZ=UTC will help you do that,
TZ=UTC; touch -t 201603151009 --time=mtime my_file.txt; will apply it to the current line.
and you can also make sure of it is done right by using:
export TZ=UTC at the start of the script, and at the end of it just re-run
export TZ=Asia/Jerusalem (or whatever your TimeZone is) to come-back to your TimeZone,

Nice!

Android Synapse – Dynamic Translation Layer Color

if [[ ! -z $2 ]]; then
    let "RC=($((16$2)) & 16711680) >> 16";
    let "GC=($((16$2)) & 65280) >> 8";
    let "BC=$((16$2)) & 255";
fi

case $1 in

scr_red)    ;&
scr_green)  ;&
scr_blue)   ;&
scr_yellow) ;&
scr_cyan)   ;&
scr_magenta)    ;&
scr_white)  ;&
scr_black)
    P=/sys/class/misc/mdnie/hook_control/

    if [[ ! -z $2 ]]; then
        echo $RC > $P/$1_red
        echo $GC > $P/$1_green
        echo $BC > $P/$1_blue
    fi

    echo $(printf "#%02X%02X%02X\n" $(cat $P/$1_red) $(cat $P/$1_green) $(cat $P/$1_blue))
    ;;
esac

Cygwin CTRL+Left To Jump Word Backward

It is time again to fix (or modify) some of the core *nix based characteristics to make you *unix OS a little like Windows (spit to the left in disgust right…. now.)

look for ~/.inputrc and add those binds to the very-end of the file (add new line afterwards).

# mappings for Ctrl-left-arrow and Ctrl-right-arrow for cursor word-wise moving.
"\e[1;5C": forward-word
"\e[1;5D": backward-word
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word

this will work on Cygwin and OSX as well as every Linux/Unix/*nix…

Reverse Engineer And Modify D-Link Binary Firmware File

Some time ago I’ve published an article(post?) about blocking ads using the router,
while it works just fine for non-html files, such as scripts, images and such,
it isn’t so great solution for blocking iframes that shows HTML content,
why?

well..
when the (original firmware) D-Link router software identify a forbidden domain,
it sends out a series of responses, ending with a html page (HTML 1.0 302 redirect -> 200 response page),

while for <script> elements it works perfectly, since it renders an invalid script,
– blocked domain, which shows ads, for example in an iframe in the page (such as eBay),
will still block the original content, but will show an iframe, well… filled with the D-Link’s blocked page msg:

icompile.eladkarako.com_reverse_engineer_dlink_dir655_router_firmware_ads_page_2016-01-20_175855
Continue reading

CMD/Bash Script Ninja – cURL Response Header Number Manipulation

Use cURL response headers using either --head or --include (to include the headers with the response-body),

For the following example we will use GREP, SED (gnu can be compiled either Win32 or Linux, heck! even use cygwin in Windows [as long you put the c:\cygwin\bin\ in PATH, it is super easy])
and Content-Length response-header,

– no “on screen” output (perfect for in-scripts)
– no temporary-file saving (R/O I/O are considered bad practice.. and slow..)
– working out PIPE action (suitable for both Windows and Linux)
– processing and simple arithmetics on value (no just a “stupid” string..)

@echo off

setlocal enableextensions
  for /f "tokens=*" %%a in ('curl --head --ipv4 --sslv3 --silent --location-trusted --url "https://storage.googleapis.com/chromium-browser-continuous/Win_x64/362418/mini_installer.exe" 2^>^&1 ^| grep "Content-Length" 2^>^&1 ^| sed "s/\r\n$//g" 2^>^&1 ^| sed "s/content-length\:\ //gi" 2^>^&1') do ( set /a num=%%a )
  
  set /a num=%num% / 1024 / 1024
  
  echo it is %num%MB
endlocal

will output

it is 41MB

(original header was Content-Length: 43597312)

(naturally a pure bash variable output is simpler.. but interior of pipe processing is still -kind’a- similar, and thus- useful or at least quite interesting..)

Hope it will be useful I’ve saw no StackOverflow nor any Google-related resources providing anything similar to that..