Skip to content

Commit

Permalink
Merge pull request #26 from Badgerati/develop
Browse files Browse the repository at this point in the history
v0.2.0
  • Loading branch information
Badgerati authored Oct 14, 2019
2 parents c5c5ee4 + 4af0da6 commit 0cd5f58
Show file tree
Hide file tree
Showing 22 changed files with 779 additions and 114 deletions.
148 changes: 134 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Parcel

[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/Badgerati/Parcel/master/LICENSE.txt)
[![PowerShell](https://img.shields.io/powershellgallery/dt/parcel.svg?label=PowerShell&colorB=085298)](https://www.powershellgallery.com/packages/Parcel)

> This is still a work in progress!
Parcel is a cross-platform PowerShell package manager and provisioner for a number of different package managers.
Expand All @@ -10,26 +13,33 @@ You define a package file using YAML, and Parcel will install/uninstall the pack

These are the currently support package providers (more to come!):

* Chocolatey (choco)
* PowerShell Gallery (psgallery)
* Scoop (scoop)
* More to come, like brew, yum, docker, etc.
* Chocolatey
* PowerShell Gallery
* Scoop
* Homebrew
* Docker
* Windows Features
* Apt-get
* Yum

## Install

```powershell
Install-Module -Name Parcel
```

## Usage

You define the packages using a YAML file - the default is `parcel.yml`, but can be anything. Then, you can run one of the following:

```powershell
Import-Module ./src/Parcel.psd1 -Force
# then
Install-ParcelPackages [-Path <string>] [-Environment <string>] [-IgnoreEnsures] [-WhatIf]
Uninstall-ParcelPackages [-Path <string>] [-Environment <string>] [-IgnoreEnsures] [-WhatIf]
Install-ParcelPackages [-Path <string>] [-Environment <string>] [-IgnoreEnsures] [-WhatIf] [-Verbose]
Uninstall-ParcelPackages [-Path <string>] [-Environment <string>] [-IgnoreEnsures] [-WhatIf] [-Verbose]
```

## Examples

To install 7zip using Chocolatey, the following could be used. For each `name` and `provider` are mandatory.
To install 7zip using Chocolatey, the following could be used. For each `name`/`names` and `provider` are mandatory, and the name *must* match precisely on all providers:

```yaml
---
Expand Down Expand Up @@ -60,7 +70,7 @@ The properties that are currently supported are in packages are:
* args (extra arguments to run, can also be split into `install:` and `uninstall:`)
* ensure (can be empty, or present/absent)
* os (can be windows, linux, or macos - package will only run if running on that OS)
* environment (can be anything, default is 'none'. packages will run based on `-Environment`)
* environment (can be anything, default is 'all'. packages will run based on `-Environment`)
* when (powershell script that returns a boolean value, if true then package will run)
* pre/post scritps (allows you to define powershell scripts to run pre/post install/uninstall)

Expand All @@ -69,16 +79,17 @@ There is also a scripts block that allows for defining pre/post scripts that run
```yaml
---
packages:
- name: <some-name>
provider: <choco|scoop|psgallery>
- name: <package-name>
names: <an array of package names>
provider: provider-name>
version: <version|empty|latest>
source: <source>
args:
install: <custom-install-arguments>
uninstall: <custom-uninstall-arguments>
ensure: <present|absent|neutral (default)>
os: <linux|macos|windows|all (default)>
environment: <environment>
environment: <environment(s)>
when: <powershell-query>
pre:
install: <powershell-script>
Expand Down Expand Up @@ -121,3 +132,112 @@ $parcel = @{
}
}
```

## Providers

### Chocolatey

```yaml
packages:
- name: 7zip.install
provider: <choco|chocolatey>
version: 19.0
```

### Scoop

```yaml
packages:
- name: 7zip
provider: scoop
version: 19.00
```

### PowerShell Gallery

```yaml
packages:
- name: Pester
provider: <psgallery|ps-gallery>
version: 4.8.0
```

### Homebrew

* Self-installation is not supported due to some quirks with PowerShell
* Sources are not supported, due to Homebrew not having them
* Latest does work, but Parcel cannot retrieve the latest version as Homebrew doesn't display it
* Since Parcel can't get the latest version, using it will always "Change"

```yaml
packages:
- name: p7zip
provider: <brew|homebrew>
```

> If you face issues installing casks, try running: `sudo chown -R $USER:admin /usr/local/Caskroom`

### Docker

* Self-installation is not supported - it's best to include this as another package to be installed
* Sources are not supported, due to Docker not having them (unless you pre-login to your own registry first)

```yaml
packages:
- name: badgerati/pode
provider: docker
version: 1.1.0
```

### Windows Features

* Only supported in Windows (Desktop PowerShell only)
* Version is always latest (as features have no version)

```yaml
packages:
- name: Microsoft-Hyper-V
provider: <winfeature|windows-feature|win-feature>
```

### DISM

* Only supported in Windows (Desktop/Core PowerShell)
* Version is always latest

```yaml
- name: ActiveDirectory-PowerShell
provider: <dism>
```

### Apt-Get

* Self-installation is not supported - if `apt-get` is not there, Parcel will fail
* Sources are not supported

```yaml
packages:
- name: vim
provider: <aptget|apt-get>
version: latest
```

or:

```yaml
packages:
- name: vim
provider: <aptget|apt-get>
version: 2:7.4.1689-3ubuntu1.3
```

### Yum

* Self-installation is not supported - if `yum` is not there, Parcel will fail
* Sources are not supported

```yaml
packages:
- name: ansible
provider: yum
```
7 changes: 7 additions & 0 deletions examples/centos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
packages:
- name: Pester
provider: psgallery

- name: git
provider: yum
9 changes: 6 additions & 3 deletions examples/parcel.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
packages:
- name: 7zip.install
#provider: choco
provider: scoop
provider: choco
#provider: scoop
version: 19.0
#os: linux
#when: ($parcel.os.type -eq 'linux')
Expand All @@ -13,4 +13,7 @@ packages:

- name: pester
provider: psgallery
version: 4.8.1
version: 4.8.1
environment:
- developer
- devops
29 changes: 29 additions & 0 deletions examples/sysadmin_mac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
packages:
- name: docker
provider: brew
- name: spotify
provider: homebrew
- name: slack
provider: homebrew
version: 4.0.3
- name: vagrant
provider: brew
- name: cheatsheet
provider: brew
- name: evernote
provider: brew
- name: slack
provider: brew
- name: visual-studio-code
provider: brew
- name: awscli
provider: brew
- name: azure-cli
provider: brew
- name: vlc
provider: brew
- name: skitch
provider: brew
- name: powershell
provider: brew
31 changes: 31 additions & 0 deletions examples/sysadmin_win.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
packages:
- name: IIS-ManagementConsole
provider: winfeature
- name: RSAT
provider: DISM
source: c:\windows|sources\winsxs
- name: RSAT
provider: windowsfeatures
- name: ActiveDirectory-PowerShell
provider: dism
- name: RSAT-AD-Tools-Feature
provider: dism
- name: ServerManager-Core-RSAT
provider: dism
- name: RSAT-Hyper-V-Tools-Feature
provider: dism
- name: powershell-core
provider: choco
- name: notepadplusplus.install
provider: choco
- name: git.install
provider: choco
- name: vscode
provider: choco
- name: docker-desktop
provider: choco
- name: 7zip
provider: scoop
- name: treesizefree
provider: choco
7 changes: 7 additions & 0 deletions examples/ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
packages:
- name: Pester
provider: psgallery

- name: vim
provider: apt-get
4 changes: 3 additions & 1 deletion ideas.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# parcel.yml
# yes: choco, scoop, yum, apt-get, ps-gallery, nuget, win-features, script, brew, docker
# done: choco, scoop, ps-gallery, brew, docker
# yes: yum, apt-get, nuget, win-features, script
# maybe: git, npm, yarn, bower (all global)
# others: windows-appx (win-store), snap

# PACKAGE [<name> - <version> - <provider>]
# > [updated|installed|uninstalled]
Expand Down
38 changes: 32 additions & 6 deletions src/Classes/ParcelFactory.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,23 @@ class ParcelFactory
$this.Providers[$_name] = $_provider
}

[int] InstallProviders([bool]$_dryRun)
[int] InstallProviders([hashtable]$_context, [bool]$_dryRun)
{
$_installed = 0

foreach ($_name in $this.Providers.Keys)
{
$_provider = $this.Providers[$_name]

if ($_provider.TestProviderInstalled()) {
# do nothing if provider is installed
if ($_provider.TestProviderInstalled($_context)) {
continue
}

# otherwise, attempt at installing it
Write-ParcelPackageHeader -Message "$($_provider.Name) [Provider]"

$result = $_provider.InstallProvider($_dryRun)
$result = $_provider.InstallProvider($_context, $_dryRun)
$result.WriteStatusMessage($_dryRun)
$_installed++

Expand All @@ -67,18 +69,42 @@ class ParcelFactory
$_provider = $null

switch ($_name.ToLowerInvariant()) {
'choco' {
{ @('choco', 'chocolatey') -icontains $_name } {
$_provider = [ChocoParcelProvider]::new()
}

'psgallery' {
{ @('psgallery', 'ps-gallery') -icontains $_name } {
$_provider = [PSGalleryParcelProvider]::new()
}

'scoop' {
{ @('scoop') -icontains $_name} {
$_provider = [ScoopParcelProvider]::new()
}

{ @('brew', 'homebrew') -icontains $_name } {
$_provider = [BrewParcelProvider]::new()
}

{ @('docker') -icontains $_name} {
$_provider = [DockerParcelProvider]::new()
}

{ @('winfeature', 'win-feature', 'windows-feature', 'windowsfeatures', 'windows-features') -icontains $_name } {
$_provider = [WindowsFeatureParcelProvider]::new()
}

{ @('dism', 'windowsdism', 'win-dism') -icontains $_name } {
$_provider = [WindowsDISMParcelProvider]::new()
}

{ @('aptget', 'apt-get') -icontains $_name} {
$_provider = [AptGetParcelProvider]::new()
}

{ @('yum') -icontains $_name} {
$_provider = [YumParcelProvider]::new()
}

default {
throw "Invalid package provider supplied: $($_name)"
}
Expand Down
Loading

0 comments on commit 0cd5f58

Please sign in to comment.