Permalink
Browse files

get_image: corrections from verx

  • Loading branch information...
1 parent f451e32 commit 786ddcfe74ee18aef526f5ab4a8b996c713d79cc @msantos committed Sep 15, 2012
Showing with 13 additions and 4 deletions.
  1. +13 −4 bin/get_image.escript
View
@@ -14,12 +14,22 @@ main(_) ->
ssl:start(),
URI = "http://downloads.openwrt.org/backfire/10.03.1/x86_generic/openwrt-x86-generic-combined-ext2.img.gz",
- File = "priv/" ++ filename:rootname(filename:basename(URI)),
+ File = "priv/" ++ filename:basename(URI),
+ Image = filename:rootname(File),
Cfg = "priv/example.xml",
download(URI, File),
- config(Cfg, File).
+
+ case file:read_file_info(Image) of
+ {ok, _} ->
+ ok;
+ {error, enoent} ->
+ io:format("Uncompressing image: ~p~n", [File]),
+ os:cmd("gunzip -dc " ++ File ++ " > " ++ Image)
+ end,
+
+ config(Cfg, Image).
download(URI, File) ->
io:format("Checking download test image ...~n"),
@@ -28,8 +38,7 @@ download(URI, File) ->
ok;
{error, enoent} ->
io:format("Downloading image: ~p -> ~p~n", [URI, File]),
- {ok, _} = httpc:request(get, {URI, []}, [], [{stream, File}]),
- os:cmd("gunzip " ++ File ++ ".gz")
+ {ok, _} = httpc:request(get, {URI, []}, [], [{stream, File}])
end.
config(Cfg, File) ->

0 comments on commit 786ddcf

Please sign in to comment.