-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_obsidian.ps1
99 lines (83 loc) · 3.79 KB
/
install_obsidian.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
# PowerShell script to install Obsidian and configure plugins on Windows
function Test-Administrator {
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
return $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
function Install-Obsidian-Windows {
Write-Output "Installing Obsidian for Windows..."
if (-Not (Get-Command choco -ErrorAction SilentlyContinue)) {
Write-Output "Chocolatey is not installed. Installing Chocolatey..."
Set-ExecutionPolicy Bypass -Scope Process -Force;
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;
$script = (New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')
Invoke-Command -ScriptBlock ([ScriptBlock]::Create($script))
}
choco install -y jq
Write-Output "Downloading Obsidian installer..."
Invoke-WebRequest -Uri "https://github.com/obsidianmd/obsidian-releases/releases/download/v1.7.4/Obsidian.1.7.4.exe" -OutFile "ObsidianInstaller.exe"
# Check if the installer was downloaded
if (Test-Path "ObsidianInstaller.exe") {
Write-Output "Running Obsidian installer..."
$startProcess = Start-Process -FilePath .\ObsidianInstaller.exe -ArgumentList "/S" -PassThru -Wait
Write-Output "Installer exit code: $($startProcess.ExitCode)"
# Check for Obsidian executable in possible installation paths
$obsidianPaths = @(
"C:\Program Files\Obsidian\Obsidian.exe",
"$env:LOCALAPPDATA\Programs\Obsidian\Obsidian.exe",
"$env:LOCALAPPDATA\Obsidian\Obsidian.exe"
)
$obsidianInstalled = $false
foreach ($path in $obsidianPaths) {
if (Test-Path $path) {
$obsidianInstalled = $true
Write-Output "Obsidian found at $path"
break
}
}
if ($obsidianInstalled) {
Write-Output "Obsidian installed successfully."
} else {
Write-Output "Obsidian installation failed."
exit 1
}
} else {
Write-Output "Failed to download Obsidian installer."
exit 1
}
}
function Install-Plugin {
Write-Output "Installing plugins..."
# Kill Obsidian process if running
$obsidianProcess = Get-Process -Name "Obsidian" -ErrorAction SilentlyContinue
if ($obsidianProcess) {
Stop-Process -Name "Obsidian" -Force
}
# Create the plugins directory if it doesn't exist
$pluginsDir = "$env:APPDATA\obsidian\plugins"
if (-Not (Test-Path $pluginsDir)) {
New-Item -ItemType Directory -Path $pluginsDir | Out-Null
}
# Read plugins configuration file
$pluginsConfig = Get-Content -Raw -Path "plugins.json" | ConvertFrom-Json
$corePlugins = $pluginsConfig.core_plugins
$communityPlugins = $pluginsConfig.community_plugins
# Enable core plugins
foreach ($plugin in $corePlugins) {
Write-Output "Enabling core plugin: $plugin"
New-Item -ItemType File -Path "$pluginsDir\$plugin" | Out-Null
}
# Install community plugins
foreach ($plugin in $communityPlugins) {
Write-Output "Installing community plugin: $plugin"
New-Item -ItemType Directory -Path "$pluginsDir\$plugin" | Out-Null
}
Write-Output "Plugins installed successfully."
}
if (-Not (Test-Administrator)) {
Write-Output "This script needs to be run as an administrator. Re-launching with elevated privileges..."
Start-Process -FilePath "powershell.exe" -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
exit
}
# Directly run Windows installation and plugin configuration
Install-Obsidian-Windows
Install-Plugin