Skip to content

Commit 700d546

Browse files
committed
changed the sources.json structure, streamlined the whole process and added the option to specify custom image
1 parent 3978fa0 commit 700d546

File tree

14 files changed

+197
-205
lines changed

14 files changed

+197
-205
lines changed

.vs/VSWorkspaceState.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"ExpandedNodes": [
3+
""
4+
],
5+
"PreviewInSolutionExplorer": false
6+
}

.vs/easyWSL/v16/.suo

14.5 KB
Binary file not shown.

.vs/slnx.sqlite

0 Bytes
Binary file not shown.

easyWSL/DistroInstaller.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class autorizationResponse
2626
}
2727

2828

29-
public static void InstallDistro(string distroID, string distroName, string distroPath, string easyWSLDataDirectory, string easyWSLDirectory)
29+
public static void InstallDistro(string distroImage, string distroName, string distroPath, string easyWSLDataDirectory, string easyWSLDirectory)
3030
{
3131

3232
void StartProcessSilently(string processName, string processArguments)
@@ -90,20 +90,20 @@ void GetRequestWithHeaderToFile(string url, string token, string type, string fi
9090
}
9191

9292

93-
SortedDictionary<string, Sources> sources = JsonSerializer.Deserialize<SortedDictionary<string, Sources>>(File.ReadAllText("sources.json"), new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
93+
dynamic sources = JsonSerializer.Deserialize<Sources>(File.ReadAllText("sources.json"));
9494
string repository = "", tag = "", registry = "registry-1.docker.io", authorizationUrl = "https://auth.docker.io/token", registryUrl = "registry.docker.io";
9595

9696

97-
if (sources[distroID].Image.Contains('/'))
97+
if (distroImage.Contains('/'))
9898
{
99-
string[] imageArray = sources[distroID].Image.Split('/');
99+
string[] imageArray = distroImage.Split('/');
100100
tag = "latest";
101-
repository = sources[distroID].Image;
101+
repository = distroImage;
102102
}
103103

104104
else
105105
{
106-
string[] imageArray = sources[distroID].Image.Split(':');
106+
string[] imageArray = distroImage.Split(':');
107107
string imgage = imageArray[0];
108108
tag = imageArray[1];
109109
repository = $"library/{imgage}";
@@ -126,7 +126,6 @@ void GetRequestWithHeaderToFile(string url, string token, string type, string fi
126126
}
127127

128128

129-
130129
string layersDirectory = $"{easyWSLDataDirectory}\\layers";
131130
Directory.CreateDirectory(layersDirectory);
132131

@@ -149,7 +148,7 @@ void GetRequestWithHeaderToFile(string url, string token, string type, string fi
149148

150149

151150
Console.WriteLine("Creating install.tar file ...");
152-
if (sources[distroID].Layers.Count == 1)
151+
if (layersList.Count == 1)
153152
{
154153
File.Move($"{layersDirectory}\\layer1.tar.bz", $"{layersDirectory}\\install.tar.bz");
155154

easyWSL/Program.cs

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ namespace easyWSL
1515
{
1616
class Program
1717
{
18+
19+
1820
static void Main(string[] args)
1921
{
2022
if(args.Length == 0)
@@ -30,10 +32,10 @@ static void Main(string[] args)
3032
Console.ResetColor();
3133
}
3234

33-
SortedDictionary<string, Sources> sources = JsonSerializer.Deserialize<SortedDictionary<string, Sources>>(File.ReadAllText("sources.json"), new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
34-
35-
string distroID = "", distroName = "", distroPath = "";
36-
int distroNumber;
35+
dynamic sources = JsonSerializer.Deserialize<Sources>(File.ReadAllText("sources.json"));
36+
37+
string distroImage = "", distroName = "", distroPath = "";
38+
int distroNumber = 0;
3739

3840
bool isConversionSuccessful;
3941

@@ -47,9 +49,9 @@ static void Main(string[] args)
4749
{
4850
foreach (int argument in Enumerable.Range(0, args.Length))
4951
{
50-
if ((args[argument] == "-d") ^ (args[argument] == "--distro"))
52+
if ((args[argument] == "-i") ^ (args[argument] == "--image"))
5153
{
52-
distroID = args[argument + 1];
54+
distroImage = args[argument + 1];
5355
}
5456

5557
else if ((args[argument] == "-n") ^ (args[argument] == "--name"))
@@ -59,47 +61,52 @@ static void Main(string[] args)
5961

6062
else if ((args[argument] == "-p") ^ (args[argument] == "--path"))
6163
{
62-
distroID = args[argument + 1];
64+
distroPath = args[argument + 1];
6365
}
6466
}
6567
}
6668

67-
if (distroID == "")
69+
if (distroImage == "")
6870
{
6971
int count = 1;
70-
foreach (KeyValuePair<string, Sources> kvp in sources)
72+
foreach (var source in sources.sources)
7173
{
72-
Console.WriteLine($"{count}. {sources[kvp.Key].Name}");
74+
Console.WriteLine($"{count}. {source.name}");
7375
count++;
7476
}
7577

78+
// additional entry for a custom image option
79+
Console.WriteLine($"{count}. Specify a docker image");
80+
7681
do
7782
{
7883
Console.Write("A number of a distro you want to install: ");
7984

8085
isConversionSuccessful = Int32.TryParse(Console.ReadLine(), out distroNumber);
81-
} while ((distroNumber > sources.Count) ^ (isConversionSuccessful == false));
82-
83-
86+
} while ((distroNumber > count) ^ (isConversionSuccessful == false));
8487

85-
count = 1;
86-
foreach (KeyValuePair<string, Sources> kvp in sources)
88+
if(distroNumber == count)
8789
{
88-
distroID = kvp.Key;
89-
count++;
90-
if (count > distroNumber)
91-
break;
90+
Console.Write("Specify a docker container: ");
91+
distroImage = Console.ReadLine();
92+
}
93+
else
94+
{
95+
distroImage = sources.sources[distroNumber - 1].image;
9296
}
97+
98+
99+
Console.WriteLine(distroImage);
93100
}
94-
101+
95102
if(distroName == "")
96103
{
97-
Console.Write("A name for your distro (default " + sources[distroID].Name + "): ");
104+
Console.Write("A name for your distro (default " + sources.sources[distroNumber-1].name + "): ");
98105
distroName = Console.ReadLine();
99106

100107
if (distroName == "")
101108
{
102-
distroName = sources[distroID].Name;
109+
distroName = sources.sources[distroNumber-1].name;
103110
}
104111

105112
distroName = Regex.Replace(distroName, @"\s+", "");
@@ -124,7 +131,7 @@ static void Main(string[] args)
124131

125132
Directory.CreateDirectory(distroPath);
126133

127-
DistroInstaller.InstallDistro(distroID, distroName, distroPath, easyWSLDataDirectory, easyWSLDirectory);
134+
DistroInstaller.InstallDistro(distroImage, distroName, distroPath, easyWSLDataDirectory, easyWSLDirectory);
128135
}
129136
}
130137
}

easyWSL/Sources.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ namespace easyWSL
88
{
99
class Sources
1010
{
11-
public string Name { get; set; }
12-
public string Image { get; set; }
13-
public List<string> Layers { get; set; }
11+
public List<SourceProperties> sources { get; set; }
12+
}
13+
14+
public class SourceProperties
15+
{
16+
public string image { get; set; }
17+
public string name { get; set; }
1418
}
1519
}

easyWSL/bin/x64/Debug/easyWSL.exe

2 KB
Binary file not shown.

easyWSL/bin/x64/Debug/easyWSL.pdb

2 KB
Binary file not shown.

easyWSL/bin/x64/Debug/sources.json

Lines changed: 73 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,80 @@
11
{
2-
"archlinux": {
3-
"name": "ArchLinux",
4-
"image": "archlinux:latest",
5-
"layers": [ "sha256:cc7ff1c0e7225a03b06669026f98576552c6c608efd4474485532e681f67c58c", "sha256:503b62125c985d32e9a8faef48d50c978b9415c11cc0763b740f0d468f64ff97" ]
6-
},
7-
8-
"ubuntu20.04": {
9-
"name": "Ubuntu 20.04",
10-
"image": "ubuntu:20.04",
11-
"layers": [ "sha256:da7391352a9bb76b292a568c066aa4c3cbae8d494e6a3c68e3c596d34f7c75f8", "sha256:14428a6d4bcdba49a64127900a0691fb00a3f329aced25eb77e3b65646638f8d", "sha256:2c2d948710f21ad82dce71743b1654b45acb5c059cf5c19da491582cef6f2601" ]
12-
},
13-
14-
"ubuntu20.10": {
15-
"name": "Ubuntu 20.10",
16-
"image": "ubuntu:20.10",
17-
"layers": [ "sha256:d8b994c442864dd519627740d3a4d134f385a2caa54b7f59bf9d372adcf7def0", "sha256:b0773f3f14174f9bc8047861c64c2aa0cc581e73b16b48194a2884ad3918d01b", "sha256:5b20aefff2dc282ec6e2f496acce5b228bd1dfc30057a8ed41eae0513191b312" ]
18-
},
19-
20-
"alpine": {
21-
"name": "Alpine",
22-
"image": "alpine:latest",
23-
"layers": [ "sha256:801bfaa63ef2094d770c809815b9e2b9c1194728e5e754ef7bc764030e140cea" ]
24-
},
25-
26-
"debianstable": {
27-
"name": "DebianStable",
28-
"image": "debian:stable",
29-
"layers": [ "sha256:5e0d4a82136cf43df758ea4260c3aba2203db5ed27b727940a7e2b7cfd6af580" ]
30-
},
2+
"sources": [
3+
{
4+
"image": "archlinux:latest",
5+
"name": "ArchLinux"
6+
},
7+
{
8+
"image": "ubuntu:20.04",
9+
"name": "Ubuntu 20.04"
10+
},
11+
{
12+
"image": "ubuntu:20.10",
13+
"name": "Ubuntu 20.10"
14+
},
3115

32-
"debianunstable": {
33-
"name": "DebianUnstable",
34-
"image": "debian:unstable",
35-
"layers": [ "sha256:38f54f0c57a31d9522970c134a72491612f81faaf99832d75020d1ad121d3b9c" ]
36-
},
16+
{
17+
"image": "alpine:latest",
18+
"name": "Alpine"
19+
},
3720

38-
"debiantesting": {
39-
"name": "DebianTesting",
40-
"image": "debian:testing",
41-
"layers": [ "sha256:ecd924c7226f314c16de965258f37da4aa990c07e494be1116af512706138401" ]
42-
},
21+
{
22+
"image": "debian:stable",
23+
"name": "DebianStable"
24+
},
4325

44-
"centos": {
45-
"name": "CentOS",
46-
"image": "centos:latest",
47-
"layers": [ "sha256:7a0437f04f83f084b7ed68ad9c4a4947e12fc4e1b006b38129bac89114ec3621" ]
48-
},
26+
{
27+
"image": "debian:unstable",
28+
"name": "DebianUnstable"
29+
},
4930

50-
"clearlinux": {
51-
"name": "Clear Linux",
52-
"image": "clearlinux:latest",
53-
"layers": [ "sha256:d3ff7f519c930e7e7f52e7a9b42e4235f38349a56d0d604ed64660fae08f30c4" ]
54-
},
55-
56-
"fedora": {
57-
"name": "Fedora",
58-
"image": "fedora:latest",
59-
"layers": [ "sha256:ae7b613df528a37664448affa6e52ff405701cda015a2a67301423bc20226b61" ]
60-
},
61-
"manjaro": {
62-
"name": "Manjaro",
63-
"image": "manjarolinux/base",
64-
"layers": [ "sha256:216c2b07dc6cdef63748d768bbfcd394fcde275397835cb973d6aa857e9983a8" ]
65-
},
66-
"scientificlinux": {
67-
"name": "Scientific Linux",
68-
"image": "sl:latest",
69-
"layers": [ "sha256:59d57c9268c8301abd28f5554dc4d14497c7cc8a281c85e06aafa8db92a1d079"]
70-
},
71-
"crux": {
72-
"name": "Crux Linux",
73-
"image": "crux:latest",
74-
"layers": [ "sha256:180a5b3bafc3c941332c0ca2c40e004ae0aabfa7173a28d5ca5f8562f596442a"]
75-
},
76-
"void": {
77-
"name": "Void Linux",
78-
"image": "voidlinux/voidlinux",
79-
"layers": [ "sha256:7a0058e958fe08e7b0265db555bcbd656ceced2f248ca41ac8547c8bc201738e", "sha256:67ec93f428d8f63dcc651f81271fa998d227078854eedbe258d054f0d9423915"]
80-
},
81-
"kali": {
82-
"name": "Kali Linux",
83-
"image": "kalilinux/kali-rolling",
84-
"layers": [ "sha256:62a6cf2f6f69d34ddb39bf1a18c7ddfb3875687d4ecdae469d99acf63ccba839"]
85-
},
86-
"opensuseleap": {
87-
"name": "OpenSuse Leap",
88-
"image": "opensuse/leap",
89-
"layers": [ "sha256:0883b61588de8d468e590174a7dde9545b48770afade002e3925feba38310294" ]
90-
},
91-
"parrot": {
92-
"name": "Parrot Security OS",
93-
"image": "parrotsec/security",
94-
"layers": [ "sha256:250c4d9991f518f0e874345e1cb4c8da8d07bd6381b8dbd451c6c22dd607051d", "sha256:a5f5dddb8ddc210730ee23e3bbc35e9bb6173c3aeca3774e6f0fa43c10799dcc", "sha256:29060bcec7f56ba927952eca467626c723447777a6fb447f327e42c0e7f5ed58"]
95-
},
96-
"gentoo": {
97-
"name": "Gentoo",
98-
"image": "gentoo/stage3",
99-
"layers": [ "sha256:915cbdf289072d1bdb8aaac4ce0808af9c9f7984738d19e3320985271c3e126d"]
31+
{
32+
"image": "debian:testing",
33+
"name": "DebianTesting"
34+
},
35+
{
36+
"image": "centos:latest",
37+
"name": "CentOS"
38+
},
39+
{
40+
"name": "Clear Linux",
41+
"image": "clearlinux:latest"
42+
},
43+
{
44+
"image": "fedora:latest",
45+
"name": "Fedora"
46+
},
47+
{
48+
"image": "manjarolinux/base",
49+
"name": "Manjaro"
50+
},
51+
{
52+
"name": "Scientific Linux",
53+
"image": "sl:latest"
54+
},
55+
{
56+
"image": "crux:latest",
57+
"name": "Crux Linux"
58+
},
59+
{
60+
"image": "voidlinux/voidlinux",
61+
"name": "Void Linux"
62+
},
63+
{
64+
"image": "kalilinux/kali-rolling",
65+
"name": "Kali Linux"
66+
},
67+
{
68+
"image": "opensuse/leap",
69+
"name": "OpenSuse Leap"
70+
},
71+
{
72+
"image": "parrotsec/security",
73+
"name": "Parrot Security OS"
74+
},
75+
{
76+
"image": "gentoo/stage3",
77+
"name": "Gentoo"
10078
}
79+
]
10180
}
28.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)