Skip to content

Instantly share code, notes, and snippets.

@luhenry
Created April 5, 2014 00:30
Show Gist options
  • Save luhenry/9985761 to your computer and use it in GitHub Desktop.
Save luhenry/9985761 to your computer and use it in GitHub Desktop.
diff --git a/setup-repo.cs b/setup-repo.cs
index 52a428f..b6f182f 100644
--- a/setup-repo.cs
+++ b/setup-repo.cs
@@ -13,7 +13,7 @@ public class UpdateTool
{
return new UpdateTool ().Run (args);
}
-
+
int Run (string [] args)
{
foreach (var arg in args) {
@@ -39,7 +39,7 @@ public class UpdateTool
}
Initialize ();
-
+
if (update_catalog)
UpdateCatalogs ();
if (update)
@@ -50,11 +50,11 @@ public class UpdateTool
return 0;
}
-
+
void Help ()
{
Console.WriteLine (@"setup-repo: setup Android SDK from archives repository.
-
+
Options:
deploy: apply archives into android-sdk directory.
@@ -62,9 +62,9 @@ Options:
update-catalogs: update reference catalog files.
");
}
-
+
bool update_catalog = false, update = false, deploy = false;
-
+
string archives_dir = Environment.GetEnvironmentVariable ("ANDROID_SDK_SETUP_ARCHIVES") ??
Path.Combine (Environment.GetEnvironmentVariable("HOME"), "android-archives");
string sdk_install_dir = Path.Combine (/*"..",*/ "android-sdk");
@@ -74,7 +74,10 @@ Options:
string componentsBaseUrl, sdkBaseUrl, ndkBaseUrl;
string [] excludes;
string local_os;
-
+ string unzip_cmd = "rm -rf {1} {2} && mkdir -p {1} {2} && unzip {0} -d {1} && mv {1}/*/* {2}";
+ string tar_cmd = "rm -rf {1} {2} && mkdir -p {1} {2} && tar jxvf {0} --directory {1} && mv {1}/*/* {2}";
+
+
void Initialize ()
{
switch (Environment.OSVersion.Platform) {
@@ -88,7 +91,7 @@ Options:
local_os = "windows";
break;
}
-
+
if (!Directory.Exists (archives_dir))
Directory.CreateDirectory (archives_dir);
@@ -108,7 +111,7 @@ Options:
return (int)typeof (Environment).GetMethod ("get_Platform", BindingFlags.Static | BindingFlags.NonPublic).Invoke (null, null) == 6;
}
-
+
void UpdateCatalogs ()
{
foreach (XPathNavigator ccat in components.Select ("Catalog")) {
@@ -116,7 +119,7 @@ Options:
new WebClient ().DownloadFile (componentsBaseUrl + ccat.InnerXml, Path.Combine ("components-catalogs", ccat.InnerXml));
}
}
-
+
void UpdateArchives ()
{
Console.WriteLine ("#!/bin/bash");
@@ -139,7 +142,7 @@ Options:
Console.WriteLine ("# Components Base URL: " + componentsBaseUrl);
foreach (XPathNavigator ccat in components.Select ("Catalog")) {
var cnav = new XPathDocument (Path.Combine ("components-catalogs", ccat.InnerXml)).CreateNavigator ();
-
+
foreach (XPathNavigator s in cnav.Select ("/*/*/*/*"))
if (s.LocalName == "archive") {
int size = 0;
@@ -163,14 +166,14 @@ Options:
}
}
}
-
+
bool DirectoryIsEmpty (string s)
{
if (!Directory.Exists (s))
return true;
return !Directory.GetFiles (s).Any () && Directory.GetDirectories (s).All (d => DirectoryIsEmpty (d));
}
-
+
void Deploy ()
{
if (!Directory.Exists (temp_dir))
@@ -179,7 +182,7 @@ Options:
if (!DirectoryIsEmpty (ndk_install_dir) || !DirectoryIsEmpty (temp_dir)) {
Console.WriteLine ("echo \"I'm not going to process NDK deployment when either of temp or installation directories are not empty. temp = '{0}' install = '{1}'\" && exit 1", temp_dir, ndk_install_dir);
}
-
+
foreach (XPathNavigator arc in ndk.Select ("Archive")) {
string os = arc.GetAttribute ("OS", "");
if (os != local_os)
@@ -187,15 +190,15 @@ Options:
var filename = arc.InnerXml;
var arcfilepath = Path.Combine (archives_dir, filename);
if (Path.GetExtension (arcfilepath) == ".zip")
- Console.WriteLine ("unzip {0} -d {1} && rm -rf {2} && mkdir {2} && mv temp/*/* {2}", arcfilepath, temp_dir, ndk_install_dir);
+ Console.WriteLine (unzip_cmd, arcfilepath, temp_dir, ndk_install_dir);
if (Path.GetExtension (arcfilepath) == ".bz2")
- Console.WriteLine ("tar jxvf {0} --directory {1} && rm -rf {2} && mkdir {2} && mv {1}/*/* {2}", arcfilepath, temp_dir, ndk_install_dir);
+ Console.WriteLine (tar_cmd, arcfilepath, temp_dir, ndk_install_dir);
}
if (!DirectoryIsEmpty (sdk_install_dir) || !DirectoryIsEmpty (temp_dir)) {
Console.WriteLine ("echo \"I'm not going to process SDK deployment when either of temp or installation directories are not empty. temp = '{0}' install = '{1}'\" && exit 1", temp_dir, sdk_install_dir);
}
-
+
foreach (XPathNavigator arc in sdk.Select ("Archive")) {
string os = arc.GetAttribute ("OS", "");
if (os != local_os)
@@ -203,14 +206,14 @@ Options:
var filename = arc.InnerXml;
var arcfilepath = Path.Combine (archives_dir, filename);
if (Path.GetExtension (arcfilepath) == ".zip")
- Console.WriteLine ("unzip {0} -d {1} && rm -rf {2} && mkdir {2} && mv temp/*/* {2}", arcfilepath, temp_dir, sdk_install_dir);
+ Console.WriteLine (unzip_cmd, arcfilepath, temp_dir, sdk_install_dir);
if (Path.GetExtension (arcfilepath) == ".tgz")
- Console.WriteLine ("tar zxvf {0} --directory {1} && rm -rf {2} && mkdir {2} && mv {1}/*/* {2}", arcfilepath, temp_dir, sdk_install_dir);
+ Console.WriteLine (tar_cmd, arcfilepath, temp_dir, sdk_install_dir);
}
foreach (XPathNavigator ccat in components.Select ("Catalog")) {
var cnav = new XPathDocument (Path.Combine ("components-catalogs", ccat.InnerXml)).CreateNavigator ();
-
+
foreach (XPathNavigator s in cnav.Select ("/*/*/*/*")) {
if (s.LocalName == "archive") {
string url = ChildValue (s, "url");
@@ -222,7 +225,7 @@ Options:
if (!string.IsNullOrEmpty (os) && os != "any" && os != local_os)
// skipping archive non-target platform
continue;
-
+
var nav = s.Clone ();
nav.MoveToParent ();
nav.MoveToParent ();
@@ -241,19 +244,19 @@ Options:
var arcfilepath = Path.Combine (archives_dir, filename);
- Console.WriteLine ("unzip {0} -d {1} && mv {1}/*/* {2}", arcfilepath, temp_dir, dstdir);
+ Console.WriteLine (unzip_cmd, arcfilepath, temp_dir, dstdir);
}
}
}
-
+
}
-
+
static IEnumerable<XPathNavigator> AsEnumerable (XPathNodeIterator i)
{
foreach (XPathNavigator n in i)
yield return n;
}
-
+
static string ChildValue (XPathNavigator nav, string child)
{
foreach (XPathNavigator c in nav.Select ("*"))
@@ -261,12 +264,12 @@ Options:
return c.InnerXml;
return null;
}
-
+
static string ConcatPath (params string [] subdirs)
{
return Path.Combine (subdirs.Where (s => !string.IsNullOrEmpty (s)).ToArray ());
}
-
+
static void EnsureDirectory (string path)
{
if (!Directory.Exists (path)) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment