From 0de54388b429756f630e186d1fe1caed1bdbbec9 Mon Sep 17 00:00:00 2001 From: Quinta <0pietroquintavalle0@gmail.com> Date: Sun, 9 Jun 2024 01:27:44 +0200 Subject: [PATCH] Added powershell script --- install_obsidian.ps1 | 91 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 install_obsidian.ps1 diff --git a/install_obsidian.ps1 b/install_obsidian.ps1 new file mode 100644 index 0000000..877710b --- /dev/null +++ b/install_obsidian.ps1 @@ -0,0 +1,91 @@ +# PowerShell script to install Obsidian and configure plugins + +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; + iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')); + } + choco install -y wget jq + + Write-Output "Downloading Obsidian installer..." + wget https://github.com/obsidianmd/obsidian-releases/releases/download/v1.6.3/Obsidian.1.6.3.exe -OutFile ObsidianInstaller.exe + + # Check if the installer was downloaded + if (Test-Path "ObsidianInstaller.exe") { + Write-Output "Running Obsidian installer..." + Start-Process -FilePath .\ObsidianInstaller.exe -ArgumentList "/S" -NoNewWindow -Wait + + # Check if Obsidian was installed and create a symbolic link for testing + if (Test-Path "C:\Program Files\Obsidian\Obsidian.exe") { + 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-Plugins { + 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." +} + +Write-Output "Please select your operating system:" +Write-Output "L) Linux" +Write-Output "M) macOS" +Write-Output "W) Windows" + +$osChoice = Read-Host "Enter your choice" + +switch ($osChoice.ToUpper()) { + "L" { + Write-Output "Please run the script install_obsidian.sh on Linux." + } + "M" { + Write-Output "Please run the script install_obsidian.sh on macOS." + } + "W" { + Install-Obsidian-Windows + Install-Plugins + } + default { + Write-Output "Invalid choice. Exiting." + exit 1 + } +}