Private/GetMacOSScripts.ps1

function GetMacOSScripts {
    [CmdletBinding()]
    Param()

    $BrewInstallNoSudoUrl = 'https://raw.githubusercontent.com/pldmgg/BootstrapPowerShellCore/master/BootstrapPowerShellCore/Private/brewinstall.rb'
    [System.Collections.ArrayList]$MacOSPMInstallScript = @(
        'usrlocaldir=$(echo "$HOME/usr/local")'
        'if [ ! -d "$usrlocaldir/Cellar" ]; then mkdir -p "$usrlocaldir/Cellar"; fi'
        'chown -R $USER $usrlocaldir'
        'checkbrew=$(command -v brew)'
        $('if test -z $checkbrew; then echo $PATH | tr {0} | grep -xc /usr/local/bin > /dev/null && echo true || PATH=$PATH:/usr/local/bin; fi' -f "':' '\n'")
        'checkbrew=$(command -v brew)'
        $('if test -z $checkbrew; then echo $PATH | tr {0} | grep -xc $usrlocaldir/bin > /dev/null && echo true || PATH=$PATH:$usrlocaldir/bin; fi' -f "':' '\n'")
        'checkbrew=$(command -v brew)'
        'if test -z $checkbrew; then brew cask uninstall powershell; fi'
        $('if test -z $checkbrew; then curl -fsSL {0} > ./brewinstall.rb && chmod +x ./brewinstall.rb; fi' -f $BrewInstallNoSudoUrl)
        "if test -z `$checkbrew; then yes '' | ./brewinstall.rb `$HOME && export HOMEBREW_PREFIX=`$usrlocaldir; fi"
        'brew update'
        'brew tap caskroom/cask'
        'brew install openssl'
        'brew cask reinstall powershell' # IMPORTANT NOTE: This will prompt for a password!
    )

    [System.Collections.ArrayList]$MacOSUninstallScript = @('brew cask uninstall powershell')

    [System.Collections.ArrayList]$MacPwshRemotingScript = @(
        "cat /etc/ssh/sshd_config | grep -Eic 'Subsystem.*powershell' > /dev/null && echo sed -i '' '/^Subsystem powershell/d' /etc/ssh/sshd_config || echo false"
        'command -v pwsh > /dev/null && echo true || echo pwshNotFound'
        "sed -i '' -e 's/sftp-server/\'`$'\nSubsystem powershell \/usr\/local\/bin\/pwsh -sshs -NoLogo -NoProfile/g' /etc/ssh/sshd_config"
        "sed -i '' -e 's/libexec\/`$/libexec\/sftp-server/g' /etc/ssh/sshd_config"
        'launchctl stop com.openssh.sshd && launchctl start com.openssh.sshd'
    )

    $MacOS = [pscustomobject]@{
        PackageManagerInstallScript                 = [System.Collections.ArrayList]$MacOSPMInstallScript
        ManualInstallScript                         = [System.Collections.ArrayList]$MacOSPMInstallScript
        UninstallScript                             = [System.Collections.ArrayList]$MacOSUninstallScript
        ConfigurePwshRemotingScript                 = [System.Collections.ArrayList]$MacPwshRemotingScript
    }
}