www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Downloading Latest D Language DMD compiler via Windows 10 batch script

reply BoQsc <vaidas.boqsc gmail.com> writes:
Initialy I though about a way to download DMD compiler on a 
single line of command prompt.
However it turned out that dlang website makes downloading the 
latest version a complex thing.

Here, I'm sharing a batch script that might be interesting if you 
are wondering how to download and launch latest d language 
compiler setup in a single click.

Usage: Copy and paste the script below into a text file
and rename the text file to a file name that ends in .cmd or .bat 
extension

Examples:
download-dmd.cmd
download-dmd.bat

.cmd and .bat extensions are the same thing, no worries about 
that.


 ECHO OFF

:Download-version-number-file-from-dlang
:: Downloads LATEST file from dlang, via bitsadmin - official 
command line download utility included since Windows 7
:: LATEST file is a plain text file that contains a single line 
of text: a number of latest version of DMD. bitsadmin /Transfer 
"%random%" "http://downloads.dlang.org/releases/LATEST" 
"%cd%/LATEST"
IF NOT ERRORLEVEL 0 (
	TITLE BITSADMIN have an error, retrying to download LATEST file
	TIMEOUT "2"
	CLS
	GOTO :Download-version-number-file-from-dlang )
:: A hacky Batch language way to store File content inside a 
variable.
SET /P "version=" < "LATEST"

:: Simply delete LATEST file, we don't need it anymore LATEST 
file is stored inside variable named "version"
DEL "LATEST"
CLS


:: Get YEARS from from Windows 10 Date Environment Variable
:: Windows 7 might require adjustments to gather the correct 
years, as the format might be different
SET "yearsRightNow=%date:~0,4%"

:: Download Latest version of dmd compiler for Windows, via 
bitsadmin
bitsadmin /Transfer "%random%" 
"http://downloads.dlang.org/releases/%yearsRightNow%/dmd-%version%.exe"
"%cd%/dmd-%version%.exe"

:: Launch the downloaded compiler's setup
start "" "dmd-%version%.exe"
Dec 17 2019
next sibling parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Tue, Dec 17, 2019 at 04:55:56PM +0000, BoQsc via Digitalmars-d wrote:
 Initialy I though about a way to download DMD compiler on a single
 line of command prompt.
 However it turned out that dlang website makes downloading the latest
 version a complex thing.
Why is that? IMO, we should have a fixed URL, something like http://dlang.org/download/dmd-latest-$OS.zip, that always points to the latest release. That way people can just download from there without having to figure out what the latest version number is. On the server side, we could use a HTTP 307 (temporary redirect) from that URL to whatever the latest release is, so that the browser / downloader will get the correct filename, and won't cache old releases incorrectly. T -- Questions are the beginning of intelligence, but the fear of God is the beginning of wisdom.
Dec 17 2019
prev sibling next sibling parent reply Eugene Wissner <belka caraus.de> writes:
On Tuesday, 17 December 2019 at 16:55:56 UTC, BoQsc wrote:
 Initialy I though about a way to download DMD compiler on a 
 single line of command prompt.
 However it turned out that dlang website makes downloading the 
 latest version a complex thing.

 Here, I'm sharing a batch script that might be interesting if 
 you are wondering how to download and launch latest d language 
 compiler setup in a single click.

 Usage: Copy and paste the script below into a text file
 and rename the text file to a file name that ends in .cmd or 
 .bat extension

 Examples:
 download-dmd.cmd
 download-dmd.bat

 .cmd and .bat extensions are the same thing, no worries about 
 that.


 ECHO OFF

:Download-version-number-file-from-dlang
:: Downloads LATEST file from dlang, via bitsadmin - official 
command line download utility included since Windows 7
:: LATEST file is a plain text file that contains a single line 
of text: a number of latest version of DMD. bitsadmin /Transfer 
"%random%" "http://downloads.dlang.org/releases/LATEST" 
"%cd%/LATEST"
IF NOT ERRORLEVEL 0 (
	TITLE BITSADMIN have an error, retrying to download LATEST file
	TIMEOUT "2"
	CLS
	GOTO :Download-version-number-file-from-dlang )
:: A hacky Batch language way to store File content inside a 
variable.
SET /P "version=" < "LATEST"

:: Simply delete LATEST file, we don't need it anymore LATEST 
file is stored inside variable named "version"
DEL "LATEST"
CLS


:: Get YEARS from from Windows 10 Date Environment Variable
:: Windows 7 might require adjustments to gather the correct 
years, as the format might be different
SET "yearsRightNow=%date:~0,4%"

:: Download Latest version of dmd compiler for Windows, via 
bitsadmin
bitsadmin /Transfer "%random%" 
"http://downloads.dlang.org/releases/%yearsRightNow%/dmd-%version%.exe"
"%cd%/dmd-%version%.exe"

:: Launch the downloaded compiler's setup
start "" "dmd-%version%.exe"
This is the same thing GNOME does. And it allows to automate compiler updates and allows to figure out what is the latest version (useful for tools). "dmd-latest.deb" or similar is more useful for human beings but is less "generic" approach since a tool wouldn't know what version it is. And imho there is the homepage for humans which always displays the latest version.
Dec 17 2019
parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Tue, Dec 17, 2019 at 06:08:05PM +0000, Eugene Wissner via Digitalmars-d
wrote:
[...]
 This is the same thing GNOME does. And it allows to automate compiler
 updates and allows to figure out what is the latest version (useful
 for tools). "dmd-latest.deb" or similar is more useful for human
 beings but is less "generic" approach since a tool wouldn't know what
 version it is.
[...] Not really. The idea is this: 1) Have a fixed URL that never changes, that always points to the latest release. So your script doesn't have to figure out anything, just download from the fixed URL. 2) Use HTTP 307 to redirect the fixed URL to the actual URL, so that the downloaded filename will have the correct version embedded. 3) The script can parse the filename to figure out what the version is. T -- Without geometry, life would be pointless. -- VS
Dec 17 2019
next sibling parent Eugene Wissner <belka caraus.de> writes:
On Tuesday, 17 December 2019 at 18:32:30 UTC, H. S. Teoh wrote:
 On Tue, Dec 17, 2019 at 06:08:05PM +0000, Eugene Wissner via 
 Digitalmars-d wrote: [...]
 [...]
[...] Not really. The idea is this: 1) Have a fixed URL that never changes, that always points to the latest release. So your script doesn't have to figure out anything, just download from the fixed URL. 2) Use HTTP 307 to redirect the fixed URL to the actual URL, so that the downloaded filename will have the correct version embedded. 3) The script can parse the filename to figure out what the version is. T
ah yes, would work too. +1
Dec 17 2019
prev sibling parent reply JN <666total wp.pl> writes:
On Tuesday, 17 December 2019 at 18:32:30 UTC, H. S. Teoh wrote:
 1) Have a fixed URL that never changes, that always points to 
 the latest
    release. So your script doesn't have to figure out anything, 
 just
    download from the fixed URL.

 2) Use HTTP 307 to redirect the fixed URL to the actual URL, so 
 that the
    downloaded filename will have the correct version embedded.

 3) The script can parse the filename to figure out what the 
 version is.


 T
The most common way nowadays for installing compilers seems to be curl | sh solution. Languages such as Crystal, Rust and Nim are using it. For Windows equivalent PowerShell solution could be used.
Dec 19 2019
parent Gregor =?UTF-8?B?TcO8Y2ts?= <gregormueckl gmx.de> writes:
On Thursday, 19 December 2019 at 09:43:17 UTC, JN wrote:
 The most common way nowadays for installing compilers seems to 
 be curl | sh solution. Languages such as Crystal, Rust and Nim 
 are using it. For Windows equivalent PowerShell solution could 
 be used.
Urgh. Piping a random shell script from the dregs of the interwebs into a local shell (possibly even a root shell) is about the worst security malpractice that is perpetuated these days with "installers" like this. I mean, we tell the more illiterate users to not click on random email attachments, not to trust VBA macros in Word files addressed to them, etc.. and then we're telling ourselves that it's OK to run random scripts sight unseen? Somebody probably needs to hack or MITM a couple of these web servers to drive the point home, I guess... :-( At least give instructions that have users download the script to a temporary file. That will encourage at least some of them to review the script before running it.
Dec 19 2019
prev sibling next sibling parent reply singingbush <singingbush hotmail.com> writes:
On Tuesday, 17 December 2019 at 16:55:56 UTC, BoQsc wrote:
 Initialy I though about a way to download DMD compiler on a 
 single line of command prompt.
 However it turned out that dlang website makes downloading the 
 latest version a complex thing.

 Here, I'm sharing a batch script that might be interesting if 
 you are wondering how to download and launch latest d language 
 compiler setup in a single click.

 Usage: Copy and paste the script below into a text file
 and rename the text file to a file name that ends in .cmd or 
 .bat extension

 Examples:
 download-dmd.cmd
 download-dmd.bat

 .cmd and .bat extensions are the same thing, no worries about 
 that.


[...]
There's no need because both DMD and LDC are in available via chocolatey. https://chocolatey.org/search?q=Dmd So simply: choco install dmd
Dec 17 2019
parent reply Laurent =?UTF-8?B?VHLDqWd1aWVy?= <laurent.treguier.sink gmail.com> writes:
On Wednesday, 18 December 2019 at 07:16:30 UTC, singingbush wrote:
 There's no need because both DMD and LDC are in available via 
 chocolatey.

 https://chocolatey.org/search?q=Dmd

 So simply: choco install dmd
It doesn't look up to date, version 2.087.0 was 2 releases ago. Looking at the package release history, it's updated like once every year, so it's definitely not a good solution to have the latest version. Besides, it also means depending on chocolatey to download it.
Dec 18 2019
parent singingbush <singingbush hotmail.com> writes:
On Wednesday, 18 December 2019 at 09:03:25 UTC, Laurent Tréguier 
wrote:
 On Wednesday, 18 December 2019 at 07:16:30 UTC, singingbush 
 wrote:
 There's no need because both DMD and LDC are in available via 
 chocolatey.

 https://chocolatey.org/search?q=Dmd

 So simply: choco install dmd
It doesn't look up to date, version 2.087.0 was 2 releases ago. Looking at the package release history, it's updated like once every year, so it's definitely not a good solution to have the latest version. Besides, it also means depending on chocolatey to download it.
That needs sorting out then. To fair to PxlBuzzard that was only a few months ago. DMD release very frequently. I'd actually rather have less frequent but more reliable releases. That's a separate issue though. Chocolatey is probably the best option for keeping dev tools up to date on Windows in the same way that Mac users use homebrew and Linux users update from their chosen repositories. It's a lot easier to 'choco upgrade all -y' and have all my tools updated than to individually run scripts for each thing individually.
Dec 18 2019
prev sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2019-12-17 17:55, BoQsc wrote:

 :: Get YEARS from from Windows 10 Date Environment Variable
 :: Windows 7 might require adjustments to gather the correct years, as 
 the format might be different
 SET "yearsRightNow=%date:~0,4%"
Instead of using the current year, you can use this base URL: http://downloads.dlang.org/releases/2.x/ -- /Jacob Carlborg
Dec 18 2019
parent BoQsc <vaidas.boqsc gmail.com> writes:
On Wednesday, 18 December 2019 at 18:39:11 UTC, Jacob Carlborg 
wrote:
 On 2019-12-17 17:55, BoQsc wrote:

 :: Get YEARS from from Windows 10 Date Environment Variable
 :: Windows 7 might require adjustments to gather the correct 
 years, as the format might be different
 SET "yearsRightNow=%date:~0,4%"
Instead of using the current year, you can use this base URL: http://downloads.dlang.org/releases/2.x/
Well, then the script won't download the latest version, it simply downloads latest version of 2.x version. You'll never know when 3.x version comes along and will be released. The script still need additional lines of code to figure out if it is 3.x, 4.x, 5.x release yet. It is only personal preference. For me, checking for date is more readable, than checking for major version changes. Although in a perfect world there should be no checks at all, simply a direct link to latest version. Then we would be left with only a single line of code of bitsadmin, and that would be great.
Dec 19 2019