Skip to content

Commit

Permalink
trying to get more difficult packages to work
Browse files Browse the repository at this point in the history
  • Loading branch information
lukesampson committed Jun 17, 2013
1 parent e87c212 commit 2a59f70
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 89 deletions.
3 changes: 3 additions & 0 deletions bin/scoop.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ param($cmd)

$commands = commands

echo $cmd
exit

if (@($null, '-h', '--help') -contains $cmd) { exec 'help' $args }
elseif ($commands -contains $cmd) { exec $cmd $args }
else { "scoop: '$cmd' isn't a scoop command. See 'scoop help'"; exit 1 }
14 changes: 7 additions & 7 deletions bin/uninstall.ps1
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
. "$(split-path $myinvocation.mycommand.path)\..\lib\core.ps1"

if(test-path $scoopdir) {
try {
rm -r $scoopdir -ea stop
} catch {
abort "couldn't remove $(friendly_path $scoopdir): it may be in use"
}
try {
rm -r $scoopdir -ea stop
} catch {
abort "couldn't remove $(friendly_path $scoopdir): it may be in use"
}
}

$bindir_regex = "$([regex]::escape((full_path $bindir)));?"
if((env 'path') -match $bindir_regex) { # future sessions only
echo "removing $(friendly_path $bindir) from your path"
env 'path' ((env 'path') -replace $bindir_regex, '')
echo "removing $(friendly_path $bindir) from your path"
env 'path' ((env 'path') -replace $bindir_regex, '')
}

success "scoop has been uninstalled"
4 changes: 4 additions & 0 deletions bucket/7zip.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"url": "http://downloads.sourceforge.net/sevenzip/7za920.zip",
"bin": "7za.exe"
}
6 changes: 6 additions & 0 deletions bucket/git.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"url": "https://msysgit.googlecode.com/files/Git-1.8.3-preview20130601.exe",
"installer": { "args": ["/verysilent", "/dir=\"$appdir\""] },
"bin": [ "cmd\\git.exe", "cmd\\gitk.cmd" ],
"uninstall": "unins000.exe"
}
45 changes: 23 additions & 22 deletions lib/cmd/help.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,53 @@ param($cmd)
. (resolve '..\commands.ps1')

function usage($text) {
$text | sls '(?m)^# Usage: ([^\n]*)$' | % { $_.matches[0].groups[1] }
$text | sls '(?m)^# Usage: ([^\n]*)$' | % { $_.matches[0].groups[1] }
}

function summary($text) {
$text | sls '(?m)^# Summary: ([^\n]*)$' | % { $_.matches[0].groups[1] }
$text | sls '(?m)^# Summary: ([^\n]*)$' | % { $_.matches[0].groups[1] }
}

function help($text) {
$help_lines = $text | sls '(?ms)^# Help:(.(?!^[^#]))*' | % { $_.matches[0].value; }
$help_lines -replace '(?ms)^# (Help: )?', ''
$help_lines = $text | sls '(?ms)^# Help:(.(?!^[^#]))*' | % { $_.matches[0].value; }
$help_lines -replace '(?ms)^# (Help: )?', ''
}

function print_help($cmd) {
$file = gc (resolve ".\$cmd.ps1") -raw
$file = gc (resolve ".\$cmd.ps1") -raw

$usage = usage $file
$summary = summary $file
$help = help $file
$usage = usage $file
$summary = summary $file
$help = help $file

if($usage) { echo "usage: $usage`n" }
if($help) { echo $help }
if($usage) { echo "usage: $usage`n" }
if($help) { echo $help }
}

function print_summaries {
$commands = @{}
$commands = @{}

command_files | % {
$command = command_name $_
$summary = summary (gc (resolve $_) -raw )
if(!($summary)) { $summary = '' }
$commands.add("$command ", $summary) # add padding
}
command_files | % {
$command = command_name $_
$summary = summary (gc (resolve $_) -raw )
if(!($summary)) { $summary = '' }
$commands.add("$command ", $summary) # add padding
}

$commands | ft -hidetablehead -autosize -wrap
$commands | ft -hidetablehead -autosize -wrap
}

$commands = commands

if(!($cmd)) {
echo "usage: scoop <command> [<args]
echo "usage: scoop <command> [<args]
Some useful commands are:"
print_summaries
print_summaries
echo "type scoop help <command> to get help for a command"
} elseif($commands -contains $cmd) {
print_help $cmd
print_help $cmd
} else {
echo "scoop help: no such command '$cmd'"
echo "scoop help: no such command '$cmd'"
}

43 changes: 32 additions & 11 deletions lib/cmd/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,46 @@ if(installed $app) { abort "'$app' is already installed"}
$appdir = appdir $app
mkdir $appdir > $null
$appdir = resolve-path $appdir
$delete_dl_file = $false;

echo "downloading $($manifest.url)..."
$fname = split-path $manifest.url -leaf
dl $manifest.url "$appdir\$fname"

# todo: unzip?
# unzip
if($fname -match '\.zip') {
unzip "$appdir\$fname" $appdir
$delete_dl_file = $true
}

# installer
if($manifest.installer) {
$arguments = $manifest.installer.args
$a = @()

if($arguments) { $arguments | % { $a += (format $_ @{'appdir'=$appdir}) } }
echo "executing: $fname $a"
& "$appdir\$fname" /verysilent
$delete_dl_file = $true
}

# delete downloaded file
if($delete_dl_file) {
rm "$appdir\$fname"
}

# create bin stubs
$manifest.bin | % {
echo "creating stub for $_ in ~\appdata\local\bin"
# check valid bin
$binpath = full_path "$appdir\$_"
if($binpath -notmatch "^$([regex]::escape("$appdir\"))") {
abort "error in manifest: bin '$_' is outside the app directory"
}
if(!(test-path $binpath)) { abort "can't stub $_`: file doesn't exist"}

stub "$appdir\$_"
echo "creating stub for $_ in ~\appdata\local\bin"

# check valid bin
$binpath = full_path "$appdir\$_"
if($binpath -notmatch "^$([regex]::escape("$appdir\"))") {
abort "error in manifest: bin '$_' is outside the app directory"
}
if(!(test-path $binpath)) { abort "can't stub $_`: file doesn't exist"}

stub "$appdir\$_"
}

success "$app was succesfully installed"
4 changes: 2 additions & 2 deletions lib/cmd/list.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
echo "Available apps:
"
gci (resolve '..\..\bucket') |
where { $_.name.endswith('.json') } |
% { $_ -replace '.json$', '' }
where { $_.name.endswith('.json') } |
% { $_ -replace '.json$', '' }
7 changes: 4 additions & 3 deletions lib/cmd/uninstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ param($app)

if(!(installed $app)) { abort "'$app' isn't installed" }

# todo: run other uninstall steps from manifest?
# todo: run uninstaller from manifest
# todo: remove bin stubs from manifest

$appdir = appdir $app
try {
rm -r $appdir -ea stop
rm -r $appdir -ea stop
} catch {
abort "couldn't remove $(friendly_path $appdir): it may be in use"
abort "couldn't remove $(friendly_path $appdir): it may be in use"
}

success "$app was uninstalled"
6 changes: 3 additions & 3 deletions lib/commands.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
function command_files {
gci (resolve 'cmd') | where { $_.name.endswith('.ps1') }
gci (resolve 'cmd') | where { $_.name.endswith('.ps1') }
}

function commands {
command_files | % { command_name $_ }
command_files | % { command_name $_ }
}

function command_name($filename) { $filename.name -replace '\.ps1$', '' }

function exec($cmd, $arguments) {
& (resolve "cmd\$cmd.ps1") @arguments
& (resolve "cmd\$cmd.ps1") @arguments
}
66 changes: 28 additions & 38 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,53 @@ $bindir = "$scoopdir\bin"
# helper functions
function dl($url,$to) { (new-object system.net.webClient).downloadFile($url,$to) }
function env($name,$val) {
if($val) { [environment]::setEnvironmentVariable($name,$val,'User') } # set
else { [environment]::getEnvironmentVariable($name, 'User') } # get
if($val) { [environment]::setEnvironmentVariable($name,$val,'User') } # set
else { [environment]::getEnvironmentVariable($name, 'User') } # get
}
function abort($msg) { write-host $msg -b darkred -f white; exit 1 }
function success($msg) { write-host $msg -b green -f black; }
function appdir($name) { "$scoopdir\apps\$name" }

function fname($path) { split-path $path -leaf }
function strip_ext($fname) { $fname -replace '\.[^\.]*$', '' }

function ensure($dir) { if(!(test-path $dir)) { mkdir $dir > $null }; resolve-path $dir }
function full_path($path) { # should be ~ rooted
$executionContext.sessionState.path.getUnresolvedProviderPathFromPSPath($path)
$executionContext.sessionState.path.getUnresolvedProviderPathFromPSPath($path)
}
function friendly_path($path) {
return "$path" -replace ([regex]::escape($home)), "~"
return "$path" -replace ([regex]::escape($home)), "~"
}
function resolve($path) { "$($myInvocation.PSScriptRoot)\$path" } # relative to calling script

function installed($name) { return test-path (appdir $name) }
function unzip($path,$to) {
$shell = (new-object -com shell.application)
$zipfiles = $shell.namespace("$path").items()
$shell.namespace("$to").copyHere($zipFiles, 4) # 4 = don't show progress dialog
if(!(test-path $path)) { abort "can't find $path to unzip"}
$shell = (new-object -com shell.application)
$zipfiles = $shell.namespace("$path").items()
$shell.namespace("$to").copyHere($zipFiles, 4) # 4 = don't show progress dialog
}
function coalesce($a, $b) { if($a) { return $a } $b }
function format($str, $hash) {
$hash.keys | % { set-variable $_ $hash[$_] }
$executionContext.invokeCommand.expandString($str)
}

function stub($path) {
if(!(test-path $path)) { abort "can't stub $(fname $path): couldn't find $path" }
$abs_bindir = ensure $bindir
$stub = "$abs_bindir\$(fname $path)"
if(!(test-path $path)) { abort "can't stub $(fname $path): couldn't find $path" }
$abs_bindir = ensure $bindir
$stub = "$abs_bindir\$(strip_ext(fname $path)).ps1"

echo "`$rawargs = `$myInvocation.line -replace `"^`$([regex]::escape(`$myInvocation.invocationName))\s+`", `"`"" >> "$stub"
echo "iex `"$path `$rawargs`"" >> "$stub"
echo "`$rawargs = `$myInvocation.line -replace `"^`$([regex]::escape(`$myInvocation.invocationName))\s+`", `"`"" >> "$stub"
echo "iex `"$path `$rawargs`"" >> "$stub"
}
function ensure_scoop_in_path {
$userpath = env 'path'
$abs_bindir = ensure $bindir
if($userpath -notmatch [regex]::escape($abs_bindir)) {
# be aggressive (b-e-aggressive) and install scoop first in the path
echo "adding $(friendly_path $abs_bindir) to your path"
env 'path' "$abs_bindir;$userpath" # for future sessions
$env:path = "$abs_bindir;$env:path" # for this session
}
}

# failed
<#
$required = @( $myInvocation.myCommand.path.tolower() )
function require($name) {
if(!$name.endsWith('.ps1')) { $name += '.ps1' }
$path = "$($myInvocation.PSScriptRoot)\$name"
if(!(test-path $path)) { abort "$path doesn't exist" }
$path = "$(resolve-path $path)".tolower()
if(!($required -contains $path)) {
$required += $path
#iex $path
#. $path -global
#import-module $path -global
}
}
#>
$userpath = env 'path'
$abs_bindir = ensure $bindir
if($userpath -notmatch [regex]::escape($abs_bindir)) {
# be aggressive (b-e-aggressive) and install scoop first in the path
echo "adding $(friendly_path $abs_bindir) to your path"
env 'path' "$abs_bindir;$userpath" # for future sessions
$env:path = "$abs_bindir;$env:path" # for this session
}
}
4 changes: 2 additions & 2 deletions lib/manifest.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function manifest($app) {
$path = (resolve "..\bucket\$app.json")
if(!(test-path $path)) { return $null }
return gc $path -raw | convertfrom-json
if(!(test-path $path)) { return $null }
return gc $path -raw | convertfrom-json
}
4 changes: 3 additions & 1 deletion scoop.sublime-project
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
}
],
"settings": {
"default_line_ending": "windows"
"default_line_ending": "windows",
"tab_size": 4,
"translate_tabs_to_spaces": false
}
}

0 comments on commit 2a59f70

Please sign in to comment.