Skip to content

Commit

Permalink
Major changes flattening hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
CMCDragonkai committed Jan 7, 2017
1 parent dabc910 commit 4af6530
Show file tree
Hide file tree
Showing 127 changed files with 567 additions and 453 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions .config/user-dirs.dirs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# While Windows doesn't make use of TEMPLATES directory or PUBLICSHARE directories
# We can still put it in here if we use Cygwin X or other programs expecting these directories
XDG_DESKTOP_DIR="$HOME/Desktop"
XDG_DOWNLOAD_DIR="$HOME/Downloads"
XDG_TEMPLATES_DIR="$HOME/.Templates"
XDG_PUBLICSHARE_DIR="$HOME/Public"
XDG_DOCUMENTS_DIR="$HOME/Documents"
XDG_MUSIC_DIR="$HOME/Music"
XDG_PICTURES_DIR="$HOME/Pictures"
XDG_VIDEOS_DIR="$HOME/Videos"
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ gmp
man-pages-posix
libcaca-bin
fontconfig
xdg-user-dirs

# network
openssh
Expand Down Expand Up @@ -242,4 +243,4 @@ libssh-devel
libgfortran3
attr
libattr1
libattr-devel
libattr-devel
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#!/usr/bin/env powershell
#requires -RunAsAdministrator
#requires -Version 5.0

param (
[switch]$Force
)

if ((Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V -Online).State -eq 'Enabled') {


if ($Force) {
Install-Package -Name 'docker-for-windows' -ProviderName 'chocolateyget' -RequiredVersion '1.12.3.8488' -Force
} else {
Install-Package -Name 'docker-for-windows' -ProviderName 'chocolateyget' -RequiredVersion '1.12.3.8488'
}


} else {

echo 'Microsoft Hyper V is not available on this computer. Instead of Docker for Windows, try: https://www.docker.com/products/docker-toolbox'
echo 'It requires manual installation.'
}

}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
208 changes: 54 additions & 154 deletions install.ps1 → .dotfiles-tools/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,45 @@
#requires -Version 5.0

param (
[ValidateLength(2, 15)][string]$ComputerName = "POLYHACK-" + "$(-join ((65..90) | Get-Random -Count 5 | % {[char]$_}))",
[string]$MainMirror = "http://mirrors.kernel.org/sourceware/cygwin",
[string]$PortMirror = "ftp://ftp.cygwinports.org/pub/cygwinports",
[string]$PortKey = "http://cygwinports.org/ports.gpg",
[string]$InstallationDirectory = "$Env:SystemDrive",
[string]$LogPath = $null,
[ValidateLength(2, 15)][string]$ComputerName = "POLYHACK-" + "$(-join ((65..90) | Get-Random -Count 5 | % {[char]$_}))",
[string]$MainMirror = "http://mirrors.kernel.org/sourceware/cygwin",
[string]$PortMirror = "ftp://ftp.cygwinports.org/pub/cygwinports",
[string]$PortKey = "http://cygwinports.org/ports.gpg",
[string]$InstallationDirectory = "$Env:SystemDrive",
[string]$LogPath = $null,
[int]$Stage = 0
)

if ($LogPath) {
Start-Transcript -Path "$LogPath" -Append
}

# Utility Functions

function Append-Idempotent {

# the delimiter is expected to be just 1 character
param (
[string]$InputString,
[string]$OriginalString,
[string]$Delimiter = '',
[bool]$CaseSensitive = $false
)

if ($CaseSensitive -and ("$OriginalString" -cnotlike "*${InputString}*")) {

"$OriginalString".TrimEnd("$Delimiter") + "$Delimiter" + "$InputString".TrimStart("$Delimiter")

} elseif (! $CaseSensitive -and ("$OriginalString" -inotlike "*${InputString}*")) {

"$OriginalString".TrimEnd("$Delimiter") + "$Delimiter" + "$InputString".TrimStart("$Delimiter")

} else {

"$OriginalString"

}

}
# Utility functions

function ScheduleRebootTask {

param (
[string]$Name,
[int]$Stage
)

# ScheduledTasks action syntax is similar to the syntax used for run.exe commands
# For some reason the normal -File option of powershell.exe doesn't work in run.exe and hence also doesn't work in the task scheduler
# So we use an alternative syntax to execute the script
$Action = New-ScheduledTaskAction -Execute 'powershell.exe' -WorkingDirectory "$($PWD.Path)" -Argument (
'-NoLogo -NoProfile -ExecutionPolicy Unrestricted -NoExit ' +
'-NoLogo -NoProfile -ExecutionPolicy Unrestricted -NoExit ' +
"`"& '${PSCommandPath}' -MainMirror '${MainMirror}' -PortMirror '${PortMirror}' -PortKey '${PortKey}' -InstallationDirectory '${InstallationDirectory}' -LogPath '${LogPath}' -Stage ${Stage}`""
)

# Trigger the script only when the current user has logged on
$Trigger = New-ScheduledTaskTrigger -AtLogOn -User "$([System.Security.Principal.WindowsIdentity]::GetCurrent().Name)"

# -RunLevel Highest will run the job with administrator privileges
$Principal = New-ScheduledTaskPrincipal `
-UserId "$([System.Security.Principal.WindowsIdentity]::GetCurrent().Name)" `
-LogonType Interactive `
-RunLevel Highest

$Settings = New-ScheduledTaskSettingsSet `
-AllowStartIfOnBatteries `
-DontStopIfGoingOnBatteries `
Expand Down Expand Up @@ -98,76 +72,32 @@ if ($Stage -eq 0) {

Write-Host "Before you continue the installation, you should RAID with Storage Spaces, switch on NTFS compression, and encrypt with Bitlocker on your drive(s)."
Read-Host "Enter to continue"
# Copy the transparent.ico icon
Copy-Item "${PSScriptRoot}\data\transparent.ico" "${Env:SYSTEMROOT}\system32"

# Copy the transparent.ico icon for removing NTFS compression arrow icon
Copy-Item "${PSScriptRoot}\..\.dotfiles-data\transparent.ico" "${Env:SYSTEMROOT}\system32"
Unblock-File -Path "${Env:SYSTEMROOT}\system32\transparent.ico"

# Install Powershell Help Files (so we can use -?)
Update-Help

# Import the registry file
Start-Process -FilePath "$Env:SystemRoot\system32\reg.exe" -Wait -Verb RunAs -ArgumentList "IMPORT `"${PSScriptRoot}\windows_registry.reg`""

# Enable Telnet
Get-WindowsOptionalFeature -Online -FeatureName TelnetClient | Enable-WindowsOptionalFeature -Online -All -NoRestart >$null
# Enable .NET Framework 3.5, 3.0 and 2.0
# This is required for some legacy applications and CUDA applications
Get-WindowsOptionalFeature -Online -FeatureName NetFx3 | Enable-WindowsOptionalFeature -Online -All -NoRestart >$null
# Enable Windows Containers
Get-WindowsOptionalFeature -Online -FeatureName Containers | Enable-WindowsOptionalFeature -Online -All -NoRestart >$null
# Enable Hyper-V hypervisor, this will prevent Virtualbox from running concurrently
# However Hyper-V can be disabled at boot for when you need to use virtualbox
# This is needed for Docker on Windows to run
Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V | Enable-WindowsOptionalFeature -Online -All -NoRestart >$null

# Allow Powershell scripts to be executable
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force

# System variables

# Make the `*.ps1` scripts executable without the `.ps1` extension
# By default Windows will have set `.COM;.EXE;.BAT;.CMD` as path extensions
[Environment]::SetEnvironmentVariable(
"PATHEXT",
(Append-Idempotent ".PS1" "$Env:PATHEXT" ";" $False),
[System.EnvironmentVariableTarget]::Machine
)
[Environment]::SetEnvironmentVariable(
"PATHEXT",
(Append-Idempotent ".PS1" "$Env:PATHEXT" ";" $False),
[System.EnvironmentVariableTarget]::Process
)

# Associate `*.ps1` scripts to PowerShell
CMD /C 'assoc .ps1=Microsoft.PowerShellScript.1' >$null
CMD /C 'ftype Microsoft.PowerShellScript.1="%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe" "%1"' >$null

# Make Windows Shortcuts `*.lnk` executable without the `.lnk` extension
[Environment]::SetEnvironmentVariable(
"PATHEXT",
(Append-Idempotent ".LNK" "$Env:PATHEXT" ";" $False),
[System.EnvironmentVariableTarget]::Machine
)
[Environment]::SetEnvironmentVariable(
"PATHEXT",
(Append-Idempotent ".LNK" "$Env:PATHEXT" ";" $False),
[System.EnvironmentVariableTarget]::Process
)

# User variables

# Home environment variables
[Environment]::SetEnvironmentVariable("HOME", $Env:UserProfile, [System.EnvironmentVariableTarget]::User)
[Environment]::SetEnvironmentVariable("HOME", $Env:UserProfile, [System.EnvironmentVariableTarget]::Process)

# Disable Cygwin warning about Unix file paths
[Environment]::SetEnvironmentVariable("CYGWIN", "nodosfilewarning", [System.EnvironmentVariableTarget]::User)
[Environment]::SetEnvironmentVariable("CYGWIN", "nodosfilewarning", [System.EnvironmentVariableTarget]::Process)


# Setup Windows Registry
& "${PSScriptRoot}\set-registry.ps1"

# Setup Windows Environment Variables (not PATH)
& "${PSScriptRoot}\set-environment.ps1"

# Setup Windows Optional Features
& "${PSScriptRoot}\set-features.ps1"

# Setup windows firewall
& "${PSScriptRoot}\tools\set-firewall.ps1" -InstallationDirectory "$InstallationDirectory"
& "${PSScriptRoot}\set-firewall.ps1" -InstallationDirectory "$InstallationDirectory"

# Change power settings for the current plan
& "${PSScriptRoot}\tools\set-power.ps1"
& "${PSScriptRoot}\set-power.ps1"

# Rename the computer to the new name just before a restart
Rename-Computer -NewName "$ComputerName" -Force >$null 2>&1
Expand All @@ -185,63 +115,26 @@ if ($Stage -eq 0) {
# Disable both SSH service and the SSH proxy
Set-Service -Name "SshProxy" -Status Stopped -StartupType Disabled -Confirm:$false -ErrorAction SilentlyContinue
Set-Service -Name "SshBroker" -Status Stopped -StartupType Disabled -Confirm:$false -ErrorAction SilentlyContinue

# Remove useless profile folders
Remove-Item "${Env:UserProfile}\Contacts" -Recurse -Force
Remove-Item "${Env:UserProfile}\Favorites" -Recurse -Force
Remove-Item "${Env:UserProfile}\Links" -Recurse -Force

# Uninstall Useless Applications
$AppsToBeUninstalled = @(
'Microsoft.3DBuilder'
'Microsoft.WindowsFeedbackHub'
'Microsoft.MicrosoftOfficeHub'
'Microsoft.MicrosoftSolitaireCollection*'
'Microsoft.BingFinance'
'Microsoft.BingNews'
'Microsoft.SkypeApp'
'Microsoft.BingSports'
'Microsoft.Office.Sway'
'Microsoft.XboxApp'
'Microsoft.MicrosoftStickyNotes'
'Microsoft.ConnectivityStore'
'Microsoft.CommsPhone'
'Microsoft.WindowsPhone'
'Microsoft.OneConnect'
'Microsoft.People'
'Microsoft.Appconnector'
'Microsoft.Getstarted'
'Microsoft.WindowsMaps'
'Microsoft.ZuneMusic'
'Microsoft.Freshpaint'
'Flipboard.Flipboard'
'9E2F88E3.Twitter'
'king.com.CandyCrushSodaSaga'
'Drawboard.DrawboardPDF'
'Facebook.Facebook'
)

foreach ($App in $AppsToBeUninstalled) {
Get-AppxPackage -AllUsers -Name "$App" | Remove-AppxPackage -Confirm:$false
Get-AppxProvisionedPackage -Online | Where DisplayName -EQ "$App" | Remove-AppxProvisionedPackage -Online
}

# Uninstall Windows 10 Bloat
& "${PSScriptRoot}\uninstall-windows-apps.ps1"

# Setup Windows Package Management
& "${PSScriptRoot}\tools\upstall-windows-packages.ps1" -Force
& "${PSScriptRoot}\upstall-windows-packages.ps1" -Force

# Install Powershell Help Files (so we can use -?)
Update-Help -Force

# Setup Chrome App Shortcuts and Symlinks to Native Packages
& "${PSScriptRoot}\tools\upstall-windows-symlinks-shortcuts.ps1"
& "${PSScriptRoot}\upstall-windows-symlinks-shortcuts.ps1"

# Installing Cygwin Packages
& "${PSScriptRoot}\tools\upstall-cygwin-packages.ps1" -MainMirror "$MainMirror" -PortMirror "$PortMirror" -PortKey "$PortKey" -InstallationDirectory "$InstallationDirectory" -CleanInstallation

# Schedule a final reboot to start the Cygwin setup process
Unregister-ScheduledTask -TaskName "Dotfiles - 2" -Confirm:$false -ErrorAction SilentlyContinue
ScheduleRebootTask -Name "Dotfiles - " -Stage 2

} elseif ($Stage -eq 2) {

Unregister-ScheduledTask -TaskName "Dotfiles - 2" -Confirm:$false
& "${PSScriptRoot}\upstall-cygwin-packages.ps1" -MainMirror "$MainMirror" -PortMirror "$PortMirror" -PortKey "$PortKey" -InstallationDirectory "$InstallationDirectory" -CleanInstallation

# Use Carbon's Grant-Privilege feature to give us the ability to create Windows symbolic links
# Because I am an administrator user, this doesn't give me unelevated access to creating native symlinks.
Expand All @@ -250,28 +143,35 @@ if ($Stage -eq 0) {
# However if UAC is disabled, then the administrator user can create symlinks without elevating.
# If I was a non-administrator user, then I would have the ability to create symlinks without any more work.
# See: http://superuser.com/q/839580
Import-Module 'Carbon'
Import-Module Carbon -Force
Grant-Privilege -Identity "$Env:UserName" -Privilege SeCreateSymbolicLinkPrivilege

# Schedule a final reboot to start the Cygwin setup process
Unregister-ScheduledTask -TaskName "Dotfiles - 2" -Confirm:$false -ErrorAction SilentlyContinue
ScheduleRebootTask -Name "Dotfiles - " -Stage 2

} elseif ($Stage -eq 2) {

Unregister-ScheduledTask -TaskName "Dotfiles - 2" -Confirm:$false

# Add the primary Cygwin bin paths to PATH before launching install.sh directly from Powershell
# This is because the PATH is not been completely configured for Cygwin before install.sh runs
# This is only needed temporarily

$Env:Path = (
"${InstallationDirectory}\cygwin64\usr\bin;" +
"${InstallationDirectory}\cygwin64\usr\sbin;" +
"${InstallationDirectory}\cygwin64\bin;" +
"${InstallationDirectory}\cygwin64\sbin;" +
"${InstallationDirectory}\cygwin64\usr\bin;" +
"${InstallationDirectory}\cygwin64\usr\sbin;" +
"${InstallationDirectory}\cygwin64\bin;" +
"${InstallationDirectory}\cygwin64\sbin;" +
"${Env:Path};"
)
Start-Process -FilePath "$InstallationDirectory\cygwin64\bin\bash.exe" -Wait -Verb RunAs -ArgumentList "`"${PSScriptRoot}\install.sh`""

echo "Finished deploying on Windows."
echo "Finished deploying on Windows."
echo "There are some final tasks to remember!"
echo "1. Install any not-yet-automated packages."
echo "2. Use gpedit.msc to disable OneDrive by going to Local Computer Policy\Computer Configuration\Administrative Templates\Windows Components\OneDrive, and also remove the OneDrive environment variable."
echo "3. Use msconfig to disable startup services and tasks that are unnecessary. This will speed up bootup and restarts."
echo "4. Remember to run ${PSScriptRoot}\tools\clean-windows-path.ps1."
echo "4. Remember to run ${PSScriptRoot}\set-windows-path.ps1."
echo "5. Configure to use your local DNS server and Hosts file, point your DNS address on relevant network interfaces to 127.0.0.1 and ::1."
echo "6. Finally restart your computer!"

Expand All @@ -281,4 +181,4 @@ if ($Stage -eq 0) {
# But if you've reached here, then the script has ended!
if ($LogPath) {
Stop-Transcript
}
}
Loading

0 comments on commit 4af6530

Please sign in to comment.