-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a6ae356
commit aa3826c
Showing
4 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# get core functions | ||
$init_url = 'https://raw.github.com/lukesampson/scoop/master/lib/init.ps1' | ||
echo 'initializing...' | ||
iex (new-object net.webclient).downloadstring($init_url) | ||
|
||
# prep | ||
assert_not_installed 'scoop' 'bootstrap' | ||
$appdir = appdir 'scoop' 'bootstrap') | ||
$abs_appdir = ensure $appdir | ||
|
||
# download scoop zip | ||
$zipurl = 'https://github.com/lukesampson/scoop/archive/master.zip' | ||
$zipfile = "$abs_appdir\scoop.zip" | ||
echo 'downloading...' | ||
dl $zipurl $zipurl | ||
|
||
echo 'extracting...' | ||
unzip $zipurl $abs_appdir | ||
rm $zipurl | ||
|
||
echo 'creating stub...' | ||
stub "$abs_appdir\scoop.ps1" | ||
|
||
ensure_scoop_in_path | ||
success 'you successfully installed scoop!' | ||
echo 'type "scoop help" for instructions' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
$scoopdir = "~\appdata\local\scoop" | ||
$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 | ||
} | ||
function abort($msg) { write-host $msg -b darkred -f white; exit 1 } | ||
function success($msg) { write-host $msg -b darkgreen -f white; } | ||
function appdir($name, $version) { "$scoopdir\$name\$version" } | ||
function fname($path) { split-path $path -leaf } | ||
function ensure($dir) { if(!(test-path $dir)) { mkdir $dir > $null }; resolve-path $dir } | ||
function stub($path) { | ||
$abs_bindir = ensure $bindir | ||
$stub = "$absbindir\$(fname $path).ps1" | ||
|
||
echo "`$rawargs = `$myInvocation.line -replace `"^`$([regex]::escape(`$myInvocation.invocationName))\s+`", `"`"" >> "$stub" | ||
echo "iex `"$path `$rawargs`"" >> "$stub" | ||
} | ||
function friendly_path($path) { | ||
$home = "$(resolve-path "~")" | ||
return "$path" -replace ([regex]::escape($home)), "~" | ||
} | ||
function ensure_scoop_in_path { | ||
$userpath = env 'path' | ||
$abs_bindir = ensure $bindir | ||
if($userpath -notmatch [regex]::escape($abs_bindir)) { | ||
# be aggressive and install scoop first in the path | ||
echo "adding $(friendly_path $absbindir) to your user path" | ||
env 'path' "$abs_bindir;$userpath" # for future sessions | ||
$env:path = "$abs_bindir;$env:path" # for this session | ||
} | ||
} | ||
function installed($name, $version) { return test-path (appdir $name $version) } | ||
function assert_not_installed($name, $version) { | ||
if(installed $name $version) { | ||
abort("``$name`` ($version) is already installed.") } | ||
} | ||
} | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# 1. installs a powershell script to ~\appdata\local\scoop\[name]\[name].ps1 | ||
# 2. adds a stub to ~\appdata\local\scoop\bin, to avoid path pollution | ||
# 3. makes sure ~\appdata\local\scoop\bin is in your path | ||
function install-ps($name, $url) { | ||
$erroractionpreference = 'stop' | ||
|
||
# helpers | ||
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 | ||
} | ||
function abort($msg) { write-host $msg -b darkred -f white; exit 1 } | ||
|
||
# prep | ||
echo "installing $name..." | ||
if($name.endswith(".ps1")) { $name = $name -replace '\.ps1$', '' } | ||
|
||
$scoopdir = "~\appdata\local\scoop" | ||
$bindir = "$scoopdir\bin" | ||
$appdir = "$scoopdir\$name" | ||
|
||
if(test-path $appdir) { abort("It looks like ``$name`` is already installed. If you'd like to re-install, please run ``rmdir ~\appdata\local\scoop\$name`` first.") } | ||
|
||
# install | ||
mkdir $appdir > $null | ||
$appdir = resolve-path $appdir | ||
echo "downloading $url..." | ||
dl $url "$appdir\$name.ps1" | ||
|
||
# binstub | ||
echo "creating stub in ~\appdata\local\bin" | ||
if(!(test-path $bindir)) { mkdir $bindir > $null } | ||
$bindir = resolve-path $bindir | ||
|
||
echo "`$rawargs = `$myInvocation.line -replace `"^`$([regex]::escape(`$myInvocation.invocationName))\s+`", `"`"" >> "$bindir\$name.ps1" | ||
echo "iex `"$appdir\$name.ps1 `$rawargs`"" >> "$bindir\$name.ps1" | ||
|
||
# ensure path | ||
$userpath = env 'path' | ||
if($userpath -notmatch [regex]::escape($bindir)) { | ||
echo "adding ~\appdata\local\bin to your user path" | ||
env 'path' "$userpath;$bindir" # for future sessions | ||
$env:path = "$env:path;$bindir" # for this session | ||
} | ||
|
||
echo "done!" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
echo "hi, this is scoop!" |