Updated testing
This commit is contained in:
@@ -77,12 +77,13 @@ function Test-ObsidianInstallation {
|
|||||||
choco install -y jq
|
choco install -y jq
|
||||||
|
|
||||||
Write-Output "Downloading Obsidian installer..."
|
Write-Output "Downloading Obsidian installer..."
|
||||||
Invoke-WebRequest -Uri "https://github.com/obsidianmd/obsidian-releases/releases/download/v1.6.3/Obsidian.1.6.3.exe" -OutFile "ObsidianInstaller.exe"
|
$installerPath = "$env:TEMP\ObsidianInstaller.exe"
|
||||||
|
Invoke-WebRequest -Uri "https://github.com/obsidianmd/obsidian-releases/releases/download/v1.6.3/Obsidian.1.6.3.exe" -OutFile $installerPath
|
||||||
|
|
||||||
# Check if the installer was downloaded
|
# Check if the installer was downloaded
|
||||||
if (Test-Path "ObsidianInstaller.exe") {
|
if (Test-Path $installerPath) {
|
||||||
Write-Output "Running Obsidian installer..."
|
Write-Output "Running Obsidian installer..."
|
||||||
$startProcess = Start-Process -FilePath .\ObsidianInstaller.exe -ArgumentList "/S" -PassThru -Wait
|
$startProcess = Start-Process -FilePath $installerPath -ArgumentList "/S" -PassThru -Wait
|
||||||
Write-Output "Installer exit code: $($startProcess.ExitCode)"
|
Write-Output "Installer exit code: $($startProcess.ExitCode)"
|
||||||
|
|
||||||
# Check for Obsidian executable in possible installation paths
|
# Check for Obsidian executable in possible installation paths
|
||||||
@@ -113,9 +114,99 @@ function Test-ObsidianInstallation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Initialize-ObsidianConfig {
|
||||||
|
Write-Output "Initializing Obsidian configuration..."
|
||||||
|
$vaultPath = "$env:USERPROFILE\Documents\ObsidianVault"
|
||||||
|
$configPath = "$vaultPath\.obsidian\config"
|
||||||
|
|
||||||
|
if (-Not (Test-Path $vaultPath)) {
|
||||||
|
Write-Output "Creating Obsidian vault directory..."
|
||||||
|
New-Item -ItemType Directory -Path $vaultPath | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-Not (Test-Path $configPath)) {
|
||||||
|
Write-Output "Creating default Obsidian config..."
|
||||||
|
$defaultConfig = @{
|
||||||
|
"plugin:file-explorer" = $true;
|
||||||
|
"plugin:global-search" = $true;
|
||||||
|
}
|
||||||
|
$defaultConfig | ConvertTo-Json -Compress | Set-Content -Path $configPath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Test-PluginInstallation {
|
||||||
|
Write-Output "Testing plugin installation..."
|
||||||
|
|
||||||
|
# Define the vault path and plugins directory
|
||||||
|
$vaultPath = "$env:USERPROFILE\Documents\ObsidianVault" # Update this path as needed
|
||||||
|
$pluginsDir = "$vaultPath\.obsidian\plugins"
|
||||||
|
|
||||||
|
# Ensure the plugins directory exists
|
||||||
|
if (-Not (Test-Path $pluginsDir)) {
|
||||||
|
New-Item -ItemType Directory -Path $pluginsDir | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get the list of installed plugins before installation
|
||||||
|
$pluginsBefore = Get-ChildItem -Path $pluginsDir
|
||||||
|
|
||||||
|
# Simulate plugin installation
|
||||||
|
$pluginsConfigPath = ".\plugins.json"
|
||||||
|
$pluginsConfig = Get-Content -Raw -Path $pluginsConfigPath | ConvertFrom-Json
|
||||||
|
$corePlugins = $pluginsConfig.core_plugins
|
||||||
|
$communityPlugins = $pluginsConfig.community_plugins
|
||||||
|
|
||||||
|
# Enable core plugins
|
||||||
|
$configPath = "$vaultPath\.obsidian\config"
|
||||||
|
if (-Not (Test-Path $configPath)) {
|
||||||
|
Initialize-ObsidianConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
$config = Get-Content -Raw -Path $configPath | ConvertFrom-Json
|
||||||
|
foreach ($plugin in $corePlugins) {
|
||||||
|
Write-Output "Enabling core plugin: $plugin"
|
||||||
|
$config["plugin:$plugin"] = $true
|
||||||
|
}
|
||||||
|
$config | ConvertTo-Json -Compress | Set-Content -Path $configPath
|
||||||
|
|
||||||
|
# Install community plugins
|
||||||
|
foreach ($plugin in $communityPlugins) {
|
||||||
|
Write-Output "Installing community plugin: $plugin"
|
||||||
|
$pluginName = $plugin -replace '/','-'
|
||||||
|
$pluginUrl = "https://github.com/$plugin/releases/latest/download/main.js"
|
||||||
|
$pluginDir = "$pluginsDir\$pluginName"
|
||||||
|
if (-Not (Test-Path $pluginDir)) {
|
||||||
|
New-Item -ItemType Directory -Path $pluginDir | Out-Null
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Invoke-WebRequest -Uri $pluginUrl -OutFile "$pluginDir\main.js" -ErrorAction Stop
|
||||||
|
} catch {
|
||||||
|
Write-Output "Failed to download plugin from $pluginUrl"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get the list of installed plugins after installation
|
||||||
|
$pluginsAfter = Get-ChildItem -Path $pluginsDir
|
||||||
|
|
||||||
|
# Compare the before and after lists
|
||||||
|
Write-Output "Plugins before installation:"
|
||||||
|
$pluginsBefore | ForEach-Object { Write-Output $_.Name }
|
||||||
|
|
||||||
|
Write-Output "Plugins after installation:"
|
||||||
|
$pluginsAfter | ForEach-Object { Write-Output $_.Name }
|
||||||
|
|
||||||
|
# Check if new plugins were installed
|
||||||
|
$newPlugins = Compare-Object -ReferenceObject $pluginsBefore -DifferenceObject $pluginsAfter
|
||||||
|
if ($newPlugins) {
|
||||||
|
Write-Output "New plugins installed successfully."
|
||||||
|
} else {
|
||||||
|
Write-Output "No new plugins were installed."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Run tests
|
# Run tests
|
||||||
Test-AdminPrivilege
|
Test-AdminPrivilege
|
||||||
Test-ChocolateyInstallation
|
Test-ChocolateyInstallation
|
||||||
Test-ObsidianDownload
|
Test-ObsidianDownload
|
||||||
Test-InvalidPluginConfig
|
Test-InvalidPluginConfig
|
||||||
Test-ObsidianInstallation
|
Test-ObsidianInstallation
|
||||||
|
Test-PluginInstallation
|
||||||
|
|||||||
@@ -40,9 +40,9 @@ function test_obsidian_download_failure {
|
|||||||
|
|
||||||
# Create an invalid plugins.json file
|
# Create an invalid plugins.json file
|
||||||
echo '{
|
echo '{
|
||||||
"core_plugins": ["plugin1", "plugin2"]
|
"core_plugins": ["plugin1", "plugin2"],
|
||||||
"community_plugins": ["plugin3", "plugin4"]
|
"community_plugins": ["plugin3", "plugin4"]
|
||||||
' > invalid_plugins.json
|
}' > invalid_plugins.json
|
||||||
|
|
||||||
function test_invalid_plugins_config {
|
function test_invalid_plugins_config {
|
||||||
echo "Testing with invalid plugins.json..."
|
echo "Testing with invalid plugins.json..."
|
||||||
@@ -53,8 +53,60 @@ function test_invalid_plugins_config {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_plugin_installation {
|
||||||
|
echo "Testing plugin installation..."
|
||||||
|
|
||||||
|
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||||
|
CONFIG_DIR="$HOME/.config/obsidian"
|
||||||
|
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
|
CONFIG_DIR="$HOME/Library/Application Support/obsidian"
|
||||||
|
fi
|
||||||
|
|
||||||
|
PLUGINS_DIR="$CONFIG_DIR/plugins"
|
||||||
|
|
||||||
|
mkdir -p "$PLUGINS_DIR"
|
||||||
|
|
||||||
|
PLUGINS_FILE=plugins.json
|
||||||
|
echo '{
|
||||||
|
"core_plugins": [
|
||||||
|
"file-explorer",
|
||||||
|
"global-search"
|
||||||
|
],
|
||||||
|
"community_plugins": [
|
||||||
|
"tgrosinger/advanced-tables-obsidian",
|
||||||
|
"mgmeyers/obsidian-kanban"
|
||||||
|
]
|
||||||
|
}' > "$PLUGINS_FILE"
|
||||||
|
|
||||||
|
# Capture the list of installed plugins before running the installation script
|
||||||
|
PLUGINS_BEFORE=$(ls -1 "$PLUGINS_DIR")
|
||||||
|
|
||||||
|
# Run the installation script
|
||||||
|
./install_obsidian.sh
|
||||||
|
|
||||||
|
# Capture the list of installed plugins after running the installation script
|
||||||
|
PLUGINS_AFTER=$(ls -1 "$PLUGINS_DIR")
|
||||||
|
|
||||||
|
# Compare the lists of plugins
|
||||||
|
echo "Plugins before installation:"
|
||||||
|
echo "$PLUGINS_BEFORE"
|
||||||
|
|
||||||
|
echo "Plugins after installation:"
|
||||||
|
echo "$PLUGINS_AFTER"
|
||||||
|
|
||||||
|
# Check for newly installed plugins
|
||||||
|
NEW_PLUGINS=$(comm -13 <(echo "$PLUGINS_BEFORE") <(echo "$PLUGINS_AFTER"))
|
||||||
|
if [ -n "$NEW_PLUGINS" ]; then
|
||||||
|
echo "New plugins installed successfully:"
|
||||||
|
echo "$NEW_PLUGINS"
|
||||||
|
else
|
||||||
|
echo "No new plugins were installed."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Run tests
|
# Run tests
|
||||||
test_os_selection
|
test_os_selection
|
||||||
test_dependencies_installation
|
test_dependencies_installation
|
||||||
test_obsidian_download_failure
|
test_obsidian_download_failure
|
||||||
test_invalid_plugins_config
|
test_invalid_plugins_config
|
||||||
|
test_plugin_installation
|
||||||
|
|||||||
+33
-9
@@ -9,20 +9,21 @@ function Install-Obsidian-Windows {
|
|||||||
Write-Output "Installing Obsidian for Windows..."
|
Write-Output "Installing Obsidian for Windows..."
|
||||||
if (-Not (Get-Command choco -ErrorAction SilentlyContinue)) {
|
if (-Not (Get-Command choco -ErrorAction SilentlyContinue)) {
|
||||||
Write-Output "Chocolatey is not installed. Installing Chocolatey..."
|
Write-Output "Chocolatey is not installed. Installing Chocolatey..."
|
||||||
Set-ExecutionPolicy Bypass -Scope Process -Force;
|
Set-ExecutionPolicy Bypass -Scope Process -Force
|
||||||
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;
|
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
|
||||||
$script = (New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')
|
$script = (New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')
|
||||||
Invoke-Command -ScriptBlock ([ScriptBlock]::Create($script))
|
Invoke-Command -ScriptBlock ([ScriptBlock]::Create($script))
|
||||||
}
|
}
|
||||||
choco install -y jq
|
choco install -y jq
|
||||||
|
|
||||||
Write-Output "Downloading Obsidian installer..."
|
Write-Output "Downloading Obsidian installer..."
|
||||||
Invoke-WebRequest -Uri "https://github.com/obsidianmd/obsidian-releases/releases/download/v1.6.3/Obsidian.1.6.3.exe" -OutFile "ObsidianInstaller.exe"
|
$installerPath = "$env:TEMP\ObsidianInstaller.exe"
|
||||||
|
Invoke-WebRequest -Uri "https://github.com/obsidianmd/obsidian-releases/releases/download/v1.6.3/Obsidian.1.6.3.exe" -OutFile $installerPath
|
||||||
|
|
||||||
# Check if the installer was downloaded
|
# Check if the installer was downloaded
|
||||||
if (Test-Path "ObsidianInstaller.exe") {
|
if (Test-Path $installerPath) {
|
||||||
Write-Output "Running Obsidian installer..."
|
Write-Output "Running Obsidian installer..."
|
||||||
$startProcess = Start-Process -FilePath .\ObsidianInstaller.exe -ArgumentList "/S" -PassThru -Wait
|
$startProcess = Start-Process -FilePath $installerPath -ArgumentList "/S" -PassThru -Wait
|
||||||
Write-Output "Installer exit code: $($startProcess.ExitCode)"
|
Write-Output "Installer exit code: $($startProcess.ExitCode)"
|
||||||
|
|
||||||
# Check for Obsidian executable in possible installation paths
|
# Check for Obsidian executable in possible installation paths
|
||||||
@@ -62,27 +63,50 @@ function Install-Plugin {
|
|||||||
Stop-Process -Name "Obsidian" -Force
|
Stop-Process -Name "Obsidian" -Force
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Define the vault path and plugins directory
|
||||||
|
$vaultPath = "$env:USERPROFILE\Documents\ObsidianVault" # Update this path as needed
|
||||||
|
$pluginsDir = "$vaultPath\.obsidian\plugins"
|
||||||
|
|
||||||
# Create the plugins directory if it doesn't exist
|
# Create the plugins directory if it doesn't exist
|
||||||
$pluginsDir = "$env:APPDATA\obsidian\plugins"
|
|
||||||
if (-Not (Test-Path $pluginsDir)) {
|
if (-Not (Test-Path $pluginsDir)) {
|
||||||
New-Item -ItemType Directory -Path $pluginsDir | Out-Null
|
New-Item -ItemType Directory -Path $pluginsDir | Out-Null
|
||||||
}
|
}
|
||||||
|
|
||||||
# Read plugins configuration file
|
# Read plugins configuration file
|
||||||
$pluginsConfig = Get-Content -Raw -Path "plugins.json" | ConvertFrom-Json
|
$pluginsConfigPath = ".\plugins.json" # Ensure this is the correct path to your plugins.json file
|
||||||
|
if (-Not (Test-Path $pluginsConfigPath)) {
|
||||||
|
Write-Output "plugins.json file not found."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
$pluginsConfig = Get-Content -Raw -Path $pluginsConfigPath | ConvertFrom-Json
|
||||||
$corePlugins = $pluginsConfig.core_plugins
|
$corePlugins = $pluginsConfig.core_plugins
|
||||||
$communityPlugins = $pluginsConfig.community_plugins
|
$communityPlugins = $pluginsConfig.community_plugins
|
||||||
|
|
||||||
# Enable core plugins
|
# Enable core plugins
|
||||||
|
$configPath = "$vaultPath\.obsidian\config"
|
||||||
|
if (-Not (Test-Path $configPath)) {
|
||||||
|
Write-Output "Obsidian config not found. Ensure Obsidian has been started at least once with the vault."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
$config = Get-Content -Raw -Path $configPath | ConvertFrom-Json
|
||||||
foreach ($plugin in $corePlugins) {
|
foreach ($plugin in $corePlugins) {
|
||||||
Write-Output "Enabling core plugin: $plugin"
|
Write-Output "Enabling core plugin: $plugin"
|
||||||
New-Item -ItemType File -Path "$pluginsDir\$plugin" | Out-Null
|
$config["plugin:$plugin"] = $true
|
||||||
}
|
}
|
||||||
|
$config | ConvertTo-Json -Compress | Set-Content -Path $configPath
|
||||||
|
|
||||||
# Install community plugins
|
# Install community plugins
|
||||||
foreach ($plugin in $communityPlugins) {
|
foreach ($plugin in $communityPlugins) {
|
||||||
Write-Output "Installing community plugin: $plugin"
|
Write-Output "Installing community plugin: $plugin"
|
||||||
New-Item -ItemType Directory -Path "$pluginsDir\$plugin" | Out-Null
|
$pluginName = $plugin -replace '/','-'
|
||||||
|
$pluginUrl = "https://github.com/$plugin/releases/latest/download/main.js"
|
||||||
|
$pluginDir = "$pluginsDir\$pluginName"
|
||||||
|
if (-Not (Test-Path $pluginDir)) {
|
||||||
|
New-Item -ItemType Directory -Path $pluginDir | Out-Null
|
||||||
|
}
|
||||||
|
Invoke-WebRequest -Uri $pluginUrl -OutFile "$pluginDir\main.js"
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Output "Plugins installed successfully."
|
Write-Output "Plugins installed successfully."
|
||||||
|
|||||||
+26
-12
@@ -9,6 +9,10 @@ install_obsidian_linux() {
|
|||||||
chmod +x obsidian.AppImage
|
chmod +x obsidian.AppImage
|
||||||
./obsidian.AppImage &
|
./obsidian.AppImage &
|
||||||
|
|
||||||
|
# Wait a bit to ensure Obsidian initializes its config
|
||||||
|
sleep 10
|
||||||
|
pkill -f obsidian.AppImage
|
||||||
|
|
||||||
# Simulate creating a command alias for testing
|
# Simulate creating a command alias for testing
|
||||||
sudo ln -sf $(pwd)/obsidian.AppImage /usr/local/bin/obsidian
|
sudo ln -sf $(pwd)/obsidian.AppImage /usr/local/bin/obsidian
|
||||||
}
|
}
|
||||||
@@ -27,40 +31,50 @@ install_obsidian_macos() {
|
|||||||
hdiutil detach /Volumes/Obsidian
|
hdiutil detach /Volumes/Obsidian
|
||||||
open /Applications/Obsidian.app &
|
open /Applications/Obsidian.app &
|
||||||
|
|
||||||
|
# Wait a bit to ensure Obsidian initializes its config
|
||||||
|
sleep 10
|
||||||
|
pkill Obsidian
|
||||||
|
|
||||||
# Simulate creating a command alias for testing
|
# Simulate creating a command alias for testing
|
||||||
sudo ln -sf /Applications/Obsidian.app/Contents/MacOS/Obsidian /usr/local/bin/obsidian
|
sudo ln -sf /Applications/Obsidian.app/Contents/MacOS/Obsidian /usr/local/bin/obsidian
|
||||||
}
|
}
|
||||||
|
|
||||||
install_plugins() {
|
install_plugins() {
|
||||||
echo "Installing plugins..."
|
echo "Installing plugins..."
|
||||||
|
|
||||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||||
pkill Obsidian
|
pkill -f obsidian.AppImage
|
||||||
|
CONFIG_DIR="$HOME/.config/obsidian"
|
||||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
pkill Obsidian
|
pkill Obsidian
|
||||||
elif [[ "$OSTYPE" == "cygwin" || "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
|
CONFIG_DIR="$HOME/Library/Application Support/obsidian"
|
||||||
taskkill /IM Obsidian.exe /F
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$OSTYPE" == "linux-gnu"* || "$OSTYPE" == "darwin"* ]]; then
|
mkdir -p "$CONFIG_DIR/plugins"
|
||||||
mkdir -p ~/.config/obsidian/plugins
|
|
||||||
elif [[ "$OSTYPE" == "cygwin" || "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
|
|
||||||
mkdir -p "$APPDATA\obsidian\plugins"
|
|
||||||
fi
|
|
||||||
|
|
||||||
PLUGINS_FILE=plugins.json
|
PLUGINS_FILE=plugins.json
|
||||||
CORE_PLUGINS=$(jq -r '.core_plugins[]' $PLUGINS_FILE)
|
CORE_PLUGINS=$(jq -r '.core_plugins[]' $PLUGINS_FILE)
|
||||||
COMMUNITY_PLUGINS=$(jq -r '.community_plugins[]' $PLUGINS_FILE)
|
COMMUNITY_PLUGINS=$(jq -r '.community_plugins[]' $PLUGINS_FILE)
|
||||||
|
|
||||||
|
# Enable core plugins
|
||||||
|
CONFIG_FILE="$CONFIG_DIR/config"
|
||||||
|
if [[ ! -f "$CONFIG_FILE" ]]; then
|
||||||
|
echo "{}" > "$CONFIG_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
for plugin in $CORE_PLUGINS; do
|
for plugin in $CORE_PLUGINS; do
|
||||||
echo "Enabling core plugin: $plugin"
|
echo "Enabling core plugin: $plugin"
|
||||||
# Simulate enabling core plugin by creating a file
|
jq ". + {\"plugin:$plugin\": true}" "$CONFIG_FILE" > tmp.json && mv tmp.json "$CONFIG_FILE"
|
||||||
touch "$HOME/.config/obsidian/plugins/$plugin"
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Install community plugins
|
||||||
for plugin in $COMMUNITY_PLUGINS; do
|
for plugin in $COMMUNITY_PLUGINS; do
|
||||||
echo "Installing community plugin: $plugin"
|
echo "Installing community plugin: $plugin"
|
||||||
# Simulate installing community plugin by creating a directory
|
PLUGIN_NAME=$(echo $plugin | sed 's/\//-/g')
|
||||||
mkdir -p "$HOME/.config/obsidian/plugins/$plugin"
|
PLUGIN_URL="https://github.com/$plugin/releases/latest/download/main.js"
|
||||||
|
PLUGIN_DIR="$CONFIG_DIR/plugins/$PLUGIN_NAME"
|
||||||
|
mkdir -p "$PLUGIN_DIR"
|
||||||
|
wget "$PLUGIN_URL" -O "$PLUGIN_DIR/main.js" || echo "Failed to download plugin $plugin"
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Plugins installed successfully!"
|
echo "Plugins installed successfully!"
|
||||||
|
|||||||
Reference in New Issue
Block a user