Skip to content
This repository has been archived by the owner on Oct 9, 2019. It is now read-only.

Commit

Permalink
Add support for specific platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
kiedtl committed Mar 20, 2019
1 parent 78ae8aa commit 650e6dd
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 109 deletions.
33 changes: 0 additions & 33 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,6 @@ function getversion() {
"0.4.0"
}

function is_installed($pkg) {
$isin = $false
$packages = @()
$manifestobj = get-content './kombucha.json' | convertfrom-json
$manifest = @{}
$manifestobj.psobject.properties | Foreach { $manifest[$_.Name] = $_.Value }
foreach ($package in $manifest.packages.package) {
$packages += $package
}
foreach ($package in $packages) {
if ($pkg -eq $package) {
$isin = $true
}
}
return $isin
}

function update_manifest($pkg, $ver) {
$i = 0
$pos = 0
$manifest = get-content './kombucha.json' | convertfrom-json
foreach ($package in $manifest.packages.package) {
if ($package -eq $pkg) {
$pos = $i
break
}
$i++
}
($manifest.packages[$pos]).version = $ver
set-content './kombucha.json' ($manifest | convertto-json)
}


function printf($txt) {
write-host "[kombucha] $txt" -nonewline
}
Expand Down
125 changes: 109 additions & 16 deletions libexec/kombucha-install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,29 @@
#
# Options:
# -g, --global Install the package globally.
# -f, --force Force installation of package.

. "$psscriptroot/../lib/core.ps1"
. "$psscriptroot/../lib/unix.ps1"
. "$psscriptroot/../lib/shim.ps1"
. "$psscriptroot/../lib/path.ps1"
. "$psscriptroot/../lib/args.ps1"
. "$psscriptroot/../lib/filesys.ps1"

$E = [char]27
$error_msg = "$E[1m$E[38;2;255;10;010merr!$E[0m"
$done_msg = "$E[1m$E[38;2;100;255;80mdone$E[0m"
$ok_msg = "$E[1m$E[38;2;100;255;80mok$E[0m"
$unknown_msg = "$E[1m$E[38;2;250;250;0m???$E[0m"
$warn_msg = "$E[1m$E[38;2;250;250;0mwarn$E[0m"
$info_msg = "$E[1m$E[38;2;120;120;255minfo$E[0m"

$opt, $packages, $errors = getopt $args 'g' 'global'
$opt, $packages, $errors = getopt $args 'gf' 'global','force'
$global = $opt.global -or $opt.g
$force = $opt.force -or $opt.f

if ($errors) {
printf "$error_msg argument error: $err`n"
printf "$error_msg argument error: $errors`n"
exit 1
}

Expand All @@ -41,26 +46,114 @@ foreach ($_pkg in $packages) {
$manifest = $manifest_json | convertfrom-json
$package = $manifest.name
$vendor = $manifest.vendor
$g_url = $manifest.git_url
$f_url = $manifest.file_url
$platform = $manifest.platform
$done_msg


printf "$info_msg checking repository '$package' from '$vendor'... "
git ls-remote "[email protected]:$vendor/$package" -q 2> $null
if (!$?) {
$error_msg
printf "$error_msg repository does not appear to exist. aborting.`n"
continue
if ($platform) {
printf "$info_msg checking platform compatibility... "
if ($platform -eq "win32") {
if ($IsWindows) {
$ok_msg
}
else {
if ($force) {
""
printf "$warn_msg platform 'win32' does not match current platform, forcing install anyway.`n"
}
else {
$error_msg
printf "$error_msg platform 'win32' does not match current platform, skipping.`n"
continue
}
}
}
elseif ($platform -eq "linux") {
if ($IsLinux) {
$ok_msg
}
else {
if ($force) {
""
printf "$warn_msg platform 'linux' does not match current platform, forcing install anyway."
}
else {
$error_msg
printf "$error_msg platform 'linux' does not match current platform, skipping."
continue
}
}
}
elseif ($platform -eq "darwin") {
if ($IsMacOS) {
$ok_msg
}
else {
if ($force) {
""
printf "$warn_msg platform 'darwin' does not match current platform, forcing install anyway."
}
else {
$error_msg
printf "$error_msg platform 'darwin' does not match current platform, skipping."
continue
}
}
}
else {
$unknown_msg
}
}
else {

if ($g_url) {
printf "$info_msg checking repository $g_url... "
git ls-remote "$g_url" -q 2> $null
if (!$?) {
$error_msg
printf "$error_msg repository does not appear to exist. skipping.`n"
continue
}
else {
$done_msg
}

printf "$info_msg cloning package '${package}'... "
if (test-path "$(get_tmp)/${vendor}-${package}") {
remove-item -r -fo "$(get_tmp)/${vendor}-${package}"
}
git clone -q "$g_url" "$(get_tmp)/${vendor}-${package}" > $null
$done_msg
}
} elseif ($f_url) {
if (test-path "$(get_tmp)/${vendor}-${package}") {
remove-item -r -fo "$(get_tmp)/${vendor}-${package}"
}
mkdir -p "$(get_tmp)/${vendor}-${package}" > $null

printf "$info_msg cloning package '${package}'... "
if (test-path "$(get_tmp)/${vendor}-${package}") {
remove-item -r -fo "$(get_tmp)/${vendor}-${package}"
foreach ($url in $f_url) {
printf "$info_msg downloading file from $f_url... "
curl -sSL "$url" > "$(get_tmp)/${vendor}-${package}/$(url_fname $url)"
$done_msg
}
} else {
printf "$info_msg checking repository '$package' from '$vendor'... "
git ls-remote "[email protected]:$vendor/$package" -q 2> $null
if (!$?) {
$error_msg
printf "$error_msg repository does not appear to exist. skipping.`n"
continue
}
else {
$done_msg
}

printf "$info_msg cloning package '${package}'... "
if (test-path "$(get_tmp)/${vendor}-${package}") {
remove-item -r -fo "$(get_tmp)/${vendor}-${package}"
}
git clone -q "https://github.com/$vendor/$package" "$(get_tmp)/${vendor}-${package}" > $null
$done_msg
}
git clone -q "https://github.com/$vendor/$package" "$(get_tmp)/${vendor}-${package}" > $null
$done_msg

if ($manifest.global -eq "true" -and $global -eq $false) {
$install_global = $true
Expand Down
60 changes: 0 additions & 60 deletions libexec/kombucha-status.ps1

This file was deleted.

0 comments on commit 650e6dd

Please sign in to comment.