Skip to content

Commit

Permalink
Separate wsl id from user id for distributions (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Feb 7, 2022
1 parent 61096f8 commit 6728b86
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 44 deletions.
143 changes: 108 additions & 35 deletions src/main/kotlin/net/kautler/github/action/setup_wsl/Distribution.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ val distributions = listOf(
Ubuntu1604,
Ubuntu1804,
Ubuntu2004
).associateBy { it.id }
).associateBy { it.userId }

sealed class Distribution(
val id: String,
val wslId: String,
val distributionName: String,
val version: SemVer,
private val _downloadUrl: URL?,
private val productId: String?,
val installerFile: String
val installerFile: String,
val userId: String = wslId
) {
val downloadUrl = GlobalScope.async(start = LAZY) {
if (_downloadUrl != null) {
Expand Down Expand Up @@ -71,20 +72,38 @@ sealed class Distribution(
}

constructor(
id: String,
wslId: String,
distributionName: String,
version: SemVer,
downloadUrl: URL,
installerFile: String
) : this(id, distributionName, version, downloadUrl, null, installerFile)
) : this(wslId, distributionName, version, downloadUrl, null, installerFile)

constructor(
id: String,
wslId: String,
userId: String,
distributionName: String,
version: SemVer,
downloadUrl: URL,
installerFile: String,
) : this(wslId, distributionName, version, downloadUrl, null, installerFile, userId)

constructor(
wslId: String,
distributionName: String,
version: SemVer,
productId: String,
installerFile: String
) : this(wslId, distributionName, version, null, productId, installerFile)

constructor(
wslId: String,
userId: String,
distributionName: String,
version: SemVer,
productId: String,
installerFile: String
) : this(id, distributionName, version, null, productId, installerFile)
) : this(wslId, distributionName, version, null, productId, installerFile, userId)

abstract suspend fun update()

Expand All @@ -93,27 +112,45 @@ sealed class Distribution(

abstract class AptGetBasedDistribution : Distribution {
constructor(
id: String,
wslId: String,
distributionName: String,
version: SemVer,
downloadUrl: URL,
installerFile: String
) : super(wslId, distributionName, version, downloadUrl, installerFile)

constructor(
wslId: String,
userId: String,
distributionName: String,
version: SemVer,
downloadUrl: URL,
installerFile: String
) : super(id, distributionName, version, downloadUrl, installerFile)
) : super(wslId, userId, distributionName, version, downloadUrl, installerFile)

constructor(
wslId: String,
distributionName: String,
version: SemVer,
productId: String,
installerFile: String
) : super(wslId, distributionName, version, productId, installerFile)

constructor(
id: String,
wslId: String,
userId: String,
distributionName: String,
version: SemVer,
productId: String,
installerFile: String
) : super(id, distributionName, version, productId, installerFile)
) : super(wslId, userId, distributionName, version, productId, installerFile)

private suspend fun refresh() {
exec(
"wsl",
arrayOf(
"--distribution",
id,
wslId,
"apt-get",
"update"
),
Expand All @@ -132,7 +169,7 @@ abstract class AptGetBasedDistribution : Distribution {
"wsl",
arrayOf(
"--distribution",
id,
wslId,
"apt-get",
"upgrade",
"--yes"
Expand All @@ -152,7 +189,7 @@ abstract class AptGetBasedDistribution : Distribution {
"wsl",
arrayOf(
"--distribution",
id,
wslId,
"apt-get",
"install",
"--yes",
Expand All @@ -170,39 +207,39 @@ abstract class AptGetBasedDistribution : Distribution {
}

object Ubuntu2004 : AptGetBasedDistribution(
id = "Ubuntu-20.04",
wslId = "Ubuntu-20.04",
distributionName = "Ubuntu",
version = SemVer("20.4.0", jsObject<Options>()),
downloadUrl = URL("https://aka.ms/wslubuntu2004"),
installerFile = "ubuntu2004.exe"
)

object Ubuntu1804 : AptGetBasedDistribution(
id = "Ubuntu-18.04",
wslId = "Ubuntu-18.04",
distributionName = "Ubuntu",
version = SemVer("18.4.0", jsObject<Options>()),
downloadUrl = URL("https://aka.ms/wsl-ubuntu-1804"),
installerFile = "ubuntu1804.exe"
)

object Ubuntu1604 : AptGetBasedDistribution(
id = "Ubuntu-16.04",
wslId = "Ubuntu-16.04",
distributionName = "Ubuntu",
version = SemVer("16.4.0", jsObject<Options>()),
downloadUrl = URL("https://aka.ms/wsl-ubuntu-1604"),
installerFile = "ubuntu1604.exe"
)

object Debian : AptGetBasedDistribution(
id = "Debian",
wslId = "Debian",
distributionName = "Debian",
version = SemVer("1.0.0", jsObject<Options>()),
downloadUrl = URL("https://aka.ms/wsl-debian-gnulinux"),
installerFile = "debian.exe"
)

object Kali : AptGetBasedDistribution(
id = "kali-linux",
wslId = "kali-linux",
distributionName = "Kali",
version = SemVer("1.0.0", jsObject<Options>()),
productId = "9pkr34tncv07",
Expand All @@ -211,27 +248,45 @@ object Kali : AptGetBasedDistribution(

abstract class ZypperBasedDistribution : Distribution {
constructor(
id: String,
wslId: String,
distributionName: String,
version: SemVer,
downloadUrl: URL,
installerFile: String
) : super(id, distributionName, version, downloadUrl, installerFile)
) : super(wslId, distributionName, version, downloadUrl, installerFile)

constructor(
id: String,
wslId: String,
userId: String,
distributionName: String,
version: SemVer,
downloadUrl: URL,
installerFile: String
) : super(wslId, userId, distributionName, version, downloadUrl, installerFile)

constructor(
wslId: String,
distributionName: String,
version: SemVer,
productId: String,
installerFile: String
) : super(wslId, distributionName, version, productId, installerFile)

constructor(
wslId: String,
userId: String,
distributionName: String,
version: SemVer,
productId: String,
installerFile: String
) : super(id, distributionName, version, productId, installerFile)
) : super(wslId, userId, distributionName, version, productId, installerFile)

private suspend fun refresh() {
exec(
"wsl",
arrayOf(
"--distribution",
id,
wslId,
"zypper",
"--non-interactive",
"refresh"
Expand All @@ -245,7 +300,7 @@ abstract class ZypperBasedDistribution : Distribution {
"wsl",
arrayOf(
"--distribution",
id,
wslId,
"zypper",
"--non-interactive",
"update"
Expand All @@ -259,7 +314,7 @@ abstract class ZypperBasedDistribution : Distribution {
"wsl",
arrayOf(
"--distribution",
id,
wslId,
"zypper",
"--non-interactive",
"install",
Expand All @@ -270,7 +325,7 @@ abstract class ZypperBasedDistribution : Distribution {
}

object OpenSuseLeap15_2 : ZypperBasedDistribution(
id = "openSUSE-Leap-15.2",
wslId = "openSUSE-Leap-15.2",
distributionName = "openSUSE Leap",
version = SemVer("15.2.0", jsObject<Options>()),
productId = "9mzd0n9z4m4h",
Expand All @@ -279,27 +334,45 @@ object OpenSuseLeap15_2 : ZypperBasedDistribution(

abstract class ApkBasedDistribution : Distribution {
constructor(
id: String,
wslId: String,
distributionName: String,
version: SemVer,
downloadUrl: URL,
installerFile: String
) : super(id, distributionName, version, downloadUrl, installerFile)
) : super(wslId, distributionName, version, downloadUrl, installerFile)

constructor(
wslId: String,
userId: String,
distributionName: String,
version: SemVer,
downloadUrl: URL,
installerFile: String
) : super(wslId, userId, distributionName, version, downloadUrl, installerFile)

constructor(
wslId: String,
distributionName: String,
version: SemVer,
productId: String,
installerFile: String
) : super(wslId, distributionName, version, productId, installerFile)

constructor(
id: String,
wslId: String,
userId: String,
distributionName: String,
version: SemVer,
productId: String,
installerFile: String
) : super(id, distributionName, version, productId, installerFile)
) : super(wslId, userId, distributionName, version, productId, installerFile)

private suspend fun refresh() {
exec(
"wsl",
arrayOf(
"--distribution",
id,
wslId,
"apk",
"update"
)
Expand All @@ -312,7 +385,7 @@ abstract class ApkBasedDistribution : Distribution {
"wsl",
arrayOf(
"--distribution",
id,
wslId,
"apk",
"upgrade"
)
Expand All @@ -325,7 +398,7 @@ abstract class ApkBasedDistribution : Distribution {
"wsl",
arrayOf(
"--distribution",
id,
wslId,
"apk",
"add",
*packages
Expand All @@ -335,7 +408,7 @@ abstract class ApkBasedDistribution : Distribution {
}

object Alpine : ApkBasedDistribution(
id = "Alpine",
wslId = "Alpine",
distributionName = "Alpine",
version = SemVer("1.0.3", jsObject<Options>()),
productId = "9p804crf0395",
Expand Down
Loading

0 comments on commit 6728b86

Please sign in to comment.