Skip to content

Commit

Permalink
Merge pull request #15 from STJEREM/feature/powershell-dist
Browse files Browse the repository at this point in the history
Powershell One-Line Installer
  • Loading branch information
bash committed Apr 30, 2016
2 parents 2d19d51 + 4b30b73 commit cee2d1f
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 48 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ brew tap bash/homebrew-coop
brew install --HEAD coop
```

### Installation on Windows
coop is avaible as a powershell module:

```powershell
Invoke-WebRequest -OutFile CoopInstaller.ps1 -Uri https://raw.githubusercontent.com/STJEREM/coop/development/client/powershell/Installer.ps1; .\CoopInstaller.ps1 "0.0.3"
```

## API

The api is hosted at [themachine.jeremystucki.com](https://themachine.jeremystucki.com).
Expand Down
47 changes: 0 additions & 47 deletions client/coop.ps1

This file was deleted.

Binary file added client/powershell/Coop/Coop.psd1
Binary file not shown.
49 changes: 49 additions & 0 deletions client/powershell/Coop/STJEREM.Coop.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
function Coop {
[CmdletBinding()]
param (
[switch] $Version,
[string] $location = "",
[string] $menuFilter = ""
)

function Get-Unix-Midnight() {
return [int][double]::Parse($(Get-Date -date (Get-Date -Hour 0 -Minute 00 -Second 00 -Millisecond 0000).ToUniversalTime()-uformat %s))
}

if ($Version -eq $true) {
$module = Get-Module Coop
Write-Host "STJEREM/coop $($module.Version)"
Return
}

if ($location -eq "") {
$location = $(Read-Host "Location")
}

$timestamp = Get-Unix-Midnight

$client = New-Object System.Net.WebClient
$url = "https://themachine.jeremystucki.com/api/v1/coop/menus/$($location)/$($timestamp)"

$response = $client.DownloadString($url)
$json = ConvertFrom-Json $response

Write-Host ""

foreach ($menu in $json.results) {
if ($menuFilter -ne "" -and $menu.title -ne $menuFilter) {
continue;
}

Write-Host -NoNewline $menu.title
Write-Host -Foreground Magenta " $($menu.price)"

foreach($item in $menu.menu) {
Write-Host "- $($item)"
}

Write-Host ""
}
}

Export-ModuleMember -Cmdlet Coop
41 changes: 41 additions & 0 deletions client/powershell/Installer.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
param (
[string] $version = (Read-Host "Commit - SHA or Tag")
)

$url = "https://github.com/STJEREM/coop/archive/$($version).zip"
$out = "$env:TEMP\coop-$($version).zip"
$tmp = "$env:TEMP"
$installDir = "$Home\Documents\WindowsPowerShell\Modules"

function Expand-ZipFile($file, $destination) {
$shell = New-Object -com shell.application
$zip = $shell.NameSpace($file)

foreach($item in $zip.items()) {
$shell.Namespace($destination).copyhere($item)
}
}

Write-Host "Downloading package..."

Invoke-WebRequest -Uri $url -OutFile $out
Expand-ZipFile $out $tmp

if ((Test-Path $installDir) -eq $false) {
New-Item -ItemType Directory -Force -Path $installDir | Out-Null
}

if ((Test-Path "$($installDir)\Coop") -eq $true) {
Write-Host "Removing previous installed version..."
Remove-Item -Force -Recurse "$($installDir)\Coop"
}

Write-Host "Installing files..."
Copy-Item -Recurse "$($tmp)\coop-$($version)\client\powershell\Coop" $installDir

Write-Host "Cleaning up..."
Remove-Item -Force $out
Remove-Item -Force -Recurse "$($tmp)\coop-$($version)"

Write-Host ""
Write-Host -Foreground Green "Installation Successful! Type 'Coop' to see available menus."
2 changes: 1 addition & 1 deletion client/coop → client/python/coop
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def print_menu(menu):


def print_version():
print('STJEREM/coop 0.0.2')
print('STJEREM/coop 0.0.3')


if len(sys.argv) == 2 and sys.argv[1] == '--version':
Expand Down
File renamed without changes.

0 comments on commit cee2d1f

Please sign in to comment.