Skip to content

Commit

Permalink
Add support for installing PowerShell modules (see ScoopInstaller#1246)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukesampson committed Jan 22, 2017
1 parent 98be5a2 commit d15bb91
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function install_app($app, $architecture, $global) {
$dir = link_current $dir
create_shims $manifest $dir $global $architecture
create_startmenu_shortcuts $manifest $dir $global
install_psmodule $manifest $dir $global
if($global) { ensure_scoop_in_path $global } # can assume local scoop is in path
env_add_path $manifest $dir $global
env_set $manifest $dir $global
Expand Down
57 changes: 57 additions & 0 deletions lib/psmodules.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
$modulesdir = "$scoopdir\modules"

function install_psmodule($manifest, $dir, $global) {
$psmodule = $manifest.psmodule
if(!$psmodule) { return }

if($global) {
abort "global installs for powershell modules is not implemented!"
}

$modulesdir = ensure $modulesdir
ensure_in_psmodulepath $modulesdir $global

$module_name = $psmodule.name
if(!$module_name) {
abort "invalid manifest: the 'name' property is missing from 'psmodule'"
return
}

$linkfrom = "$modulesdir\$module_name"
write-host "installing PowerShell module '$module_name'"

write-host "linking $(friendly_path $linkfrom) => $(friendly_path $dir)"

if(test-path $linkfrom) {
warn "$(friendly_path $linkfrom) already exists: will be replaced"
cmd /c rmdir $linkfrom
}

cmd /c mklink /j $linkfrom $dir | out-null
}

function uninstall_psmodule($manifest, $dir, $global) {
$psmodule = $manifest.psmodule
if(!$psmodule) { return }

$module_name = $psmodule.name
write-host "uninstalling PowerShell module '$module_name'"

$linkfrom = "$modulesdir\$module_name"
if(test-path $linkfrom) {
write-host "removing $(friendly_path $linkfrom)"
$linkfrom = resolve-path $linkfrom
cmd /c rmdir $linkfrom
}
}

function ensure_in_psmodulepath($dir, $global) {
$path = env 'psmodulepath' $global
$dir = fullpath $dir
if($path -notmatch [regex]::escape($dir)) {
echo "adding $(friendly_path $dir) to $(if($global){'global'}else{'your'}) PowerShell module path"

env 'psmodulepath' $global "$dir;$path" # for future sessions...
$env:psmodulepath = "$dir;$env:psmodulepath" # for this session
}
}
1 change: 1 addition & 0 deletions libexec/scoop-install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
. "$psscriptroot\..\lib\decompress.ps1"
. "$psscriptroot\..\lib\install.ps1"
. "$psscriptroot\..\lib\shortcuts.ps1"
. "$psscriptroot\..\lib\psmodules.ps1"
. "$psscriptroot\..\lib\versions.ps1"
. "$psscriptroot\..\lib\help.ps1"
. "$psscriptroot\..\lib\getopt.ps1"
Expand Down
5 changes: 4 additions & 1 deletion libexec/scoop-uninstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
. "$psscriptroot\..\lib\help.ps1"
. "$psscriptroot\..\lib\install.ps1"
. "$psscriptroot\..\lib\shortcuts.ps1"
. "$psscriptroot\..\lib\psmodules.ps1"
. "$psscriptroot\..\lib\versions.ps1"
. "$psscriptroot\..\lib\getopt.ps1"
. "$psscriptroot\..\lib\config.ps1"
Expand Down Expand Up @@ -64,10 +65,12 @@ foreach($app in $apps) {
rm_startmenu_shortcuts $manifest $global

# If a junction was used during install, that will have been used
# as the reference directory. Othewise it will just be the version
# as the reference directory. Otherwise it will just be the version
# directory.
$refdir = unlink_current $dir

uninstall_psmodule $manifest $refdir $global

env_rm_path $manifest $refdir $global
env_rm $manifest $global

Expand Down
1 change: 1 addition & 0 deletions libexec/scoop-update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
. "$psscriptroot\..\lib\core.ps1"
. "$psscriptroot\..\lib\install.ps1"
. "$psscriptroot\..\lib\shortcuts.ps1"
. "$psscriptroot\..\lib\psmodules.ps1"
. "$psscriptroot\..\lib\decompress.ps1"
. "$psscriptroot\..\lib\manifest.ps1"
. "$psscriptroot\..\lib\buckets.ps1"
Expand Down

0 comments on commit d15bb91

Please sign in to comment.