-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.ps1
167 lines (142 loc) · 6.24 KB
/
setup.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# cek winget sudah terinstall atau belum
if (-not (Get-Command winget -ErrorAction SilentlyContinue)) {
Write-Host "Error: winget tidak terinstal. Silakan instal winget dan jalankan skrip lagi."
exit
}
# cek git sudah terinstall atau belum
if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
Write-Host "Git tidak diinstal. Menginstal Git..."
winget install -e --id Git.Git
}
# cek oh-my-posh sudah terinstall atau belum
$ohMyPoshInstalled = Get-Command oh-my-posh -ErrorAction SilentlyContinue
if (-not $ohMyPoshInstalled) {
Write-Host "Oh My Posh tidak terinstal. Menginstal Oh My Posh..."
winget install -e --accept-source-agreements --accept-package-agreements JanDeDobbeleer.OhMyPosh
}
else {
Write-Host "Oh My Posh Sudah Terinstall."
}
# penginstalan Font
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
$fontFamilies = (New-Object System.Drawing.Text.InstalledFontCollection).Families
if ($fontFamilies -notcontains "CaskaydiaCove NF") {
# Download Font Dari github
$webClient = New-Object System.Net.WebClient
$webClient.DownloadFile("https://github.com/ryanoasis/nerd-fonts/releases/download/v3.0.2/CascadiaCode.zip", ".\CascadiaCode.zip")
# extract font dan install ke direktori font windows
Expand-Archive -Path ".\CascadiaCode.zip" -DestinationPath ".\CascadiaCode" -Force
$destination = (New-Object -ComObject Shell.Application).Namespace(0x14)
Get-ChildItem -Path ".\CascadiaCode" -Recurse -Filter "*.ttf" | ForEach-Object {
If (-not(Test-Path "C:\Windows\Fonts\$($_.Name)")) {
# Install font
$destination.CopyHere($_.FullName, 0x10)
}
}
# Bersihkan file yang tidak diperlukan setelah instalasi font
Remove-Item -Path ".\CascadiaCode" -Recurse -Force
Remove-Item -Path ".\CascadiaCode.zip" -Force
}
# cek chocolatey sudah terinstall atau belum
$chocolateyInstalled = Get-Command choco -ErrorAction SilentlyContinue
if (-not $chocolateyInstalled) {
# Set execution policy and download/run Chocolatey installer
Set-ExecutionPolicy Bypass -Scope Process -Force
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
}
else {
Write-Host "Chocolatey sudah terinstal."
}
# cek fzf sudah terinstall atau belum
$fzfInstalled = Get-Command fzf -ErrorAction SilentlyContinue
if (-not $fzfInstalled) {
choco install fzf -y
}
else {
Write-Host "fzf sudah terinstal."
}
# cek gsudo sudah terinstall atau belum
$gsudoInstalled = Get-Command gsudo -ErrorAction SilentlyContinue
if (-not $gsudoInstalled) {
choco install gsudo -y
}
else {
Write-Host "gsudo sudah terinstal."
}
# Membuat direktori jika tidak ada
$githubDirectory = Join-Path $env:userprofile "Documents\Github"
if (!(Test-Path -Path $githubDirectory -PathType Container)) {
New-Item -Path $githubDirectory -ItemType Directory | Out-Null
}
# Fungsi untuk membuka PowerShell sebagai administrator
function Run-As-Administrator {
param([scriptblock]$ScriptBlock)
Start-Process -FilePath powershell.exe -ArgumentList "-NoProfile -ExecutionPolicy Bypass -Command $($ScriptBlock | Out-String)" -Verb RunAs
}
# installer ke 2
# Periksa apakah file profil pengguna ada, jika tidak, buat profil baru
if (!(Test-Path -Path $PROFILE -PathType Leaf)) {
try {
# Periksa versi PowerShell yang digunakan (Core atau Desktop)
if ($PSVersionTable.PSEdition -eq "Core") {
if (!(Test-Path -Path ($env:userprofile + "\Documents\Powershell"))) {
New-Item -Path ($env:userprofile + "\Documents\Powershell") -ItemType "directory"
}
}
elseif ($PSVersionTable.PSEdition -eq "Desktop") {
if (!(Test-Path -Path ($env:userprofile + "\Documents\WindowsPowerShell"))) {
New-Item -Path ($env:userprofile + "\Documents\WindowsPowerShell") -ItemType "directory"
}
}
# Unduh profil dari GitHub dan tulis ke $PROFILE
Invoke-RestMethod https://github.com/rezapace/ps/raw/main/Microsoft.PowerShell_profile.ps1 -OutFile $PROFILE
Write-Host "Profil @ [$PROFILE] telah dibuat."
}
catch {
throw $_.Exception.Message
}
}
else {
# Pindahkan profil lama ke oldprofile.ps1 dan unduh profil baru dari GitHub
Get-Item -Path $PROFILE | Move-Item -Destination oldprofile.ps1 -Force
Invoke-RestMethod https://github.com/rezapace/ps/raw/main/Microsoft.PowerShell_profile.ps1 -OutFile $PROFILE
Write-Host "Profil @ [$PROFILE] telah dibuat dan profil lama dihapus."
}
# Eksekusi profil
& $profile
# Instalasi NuGet provider jika belum terinstal
$nugetProviderInstalled = Get-Command NuGet -ErrorAction SilentlyContinue
if (-not $nugetProviderInstalled) {
Install-PackageProvider -Name NuGet -Force
}
# Instalasi modul-modul yang dibutuhkan melalui PowerShellGet dan Chocolatey
Install-Module -Name Terminal-Icons -Repository PSGallery -Force
Install-Module -Name posh-git -Scope CurrentUser -Force
Install-Module -Name PowerShellGet -Scope CurrentUser -Force
Install-Module -Name z -Scope CurrentUser -Force
Install-Module -Name PSReadLine -Scope CurrentUser -Force
Install-Module -Name PSFzf -Scope CurrentUser -Force
# Set execution policy
Set-ExecutionPolicy RemoteSigned
Set-ExecutionPolicy Restricted
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
# Skrip untuk dijalankan sebagai administrator
$adminScript = {
# clone github repository
Set-Location -Path $env:userprofile\Documents\Github
git clone "https://github.com/rezapace/ps"
}
# Jalankan skrip sebagai administrator
Run-As-Administrator -ScriptBlock $adminScript
# Tentukan path ke executable WindowsTerminal.exe
$windowsTerminalPath = "$env:userprofile\Documents\Github\ps\terminal\WindowsTerminal.exe"
# Tentukan lokasi untuk menyimpan shortcut
$shortcutPath = [System.IO.Path]::Combine($env:USERPROFILE, 'Desktop\Windows Terminal.lnk')
# Buat objek untuk membuat shortcut
$WshShell = New-Object -ComObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($shortcutPath)
# Atur properti shortcut
$Shortcut.TargetPath = $windowsTerminalPath
$Shortcut.Save()
Write-Host "Shortcut untuk Windows Terminal telah dibuat di desktop."