diff --git a/cli/main.go b/cli/main.go index ee0e54c..4899ae2 100644 --- a/cli/main.go +++ b/cli/main.go @@ -41,9 +41,13 @@ var SERVER_LOG_FILE_PATH = filepath.Join(RUNTIME_DIR, "server.log") func getRuntimeDirectory() string { if runtime.GOOS == "windows" { return filepath.Join(os.Getenv("APPDATA"), "shareit") - } else { - return filepath.Join(os.Getenv("HOME"), ".shareit") } + + if runtime.GOOS == "darwin" { + return filepath.Join(os.Getenv("HOME"), "Library", "Application Support", "shareit") + } + + return filepath.Join(os.Getenv("HOME"), ".shareit") } func main() { diff --git a/scripts/install.sh b/scripts/install.sh index a452f34..fd9d183 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -14,7 +14,7 @@ GITHUB_REPO="harshrai654/shareit" CLI_EXECUTABLE="shareit.cli.linux" SERVER_EXECUTABLE="shareit.server.linux" INSTALL_DIR="/usr/local/bin" -RUNTIME_DIR="$HOME/.local/share/shareit" +RUNTIME_DIR="$HOME/.shareit/" if [ "${OS}" == "Mac" ]; then RUNTIME_DIR="$HOME/Library/Application Support/shareit" diff --git a/scripts/uninstall.ps1 b/scripts/uninstall.ps1 new file mode 100644 index 0000000..ea644ec --- /dev/null +++ b/scripts/uninstall.ps1 @@ -0,0 +1,44 @@ +Write-Host "Uninstalling ShareIT for Windows..." + +# Variables +$CLI_EXECUTABLE = "shareit.cli.exe" +$SERVER_EXECUTABLE = "shareit.server.exe" +$INSTALL_DIR = "$env:ProgramFiles\ShareIT" +$RUNTIME_DIR = "$env:LOCALAPPDATA\ShareIT" + +# Function to check if a process is running +function Is-ProcessRunning { + param ( + [string]$ProcessName + ) + $process = Get-Process -Name $ProcessName -ErrorAction SilentlyContinue + return $process -ne $null +} + +# Check if CLI executable is running +if (Is-ProcessRunning -ProcessName "shareit.cli") { + Write-Host "Error: CLI executable ($CLI_EXECUTABLE) is running. Please stop it before uninstalling." + exit 1 +} + +# Check if Server executable is running +if (Is-ProcessRunning -ProcessName "shareit.server") { + Write-Host "Server executable ($SERVER_EXECUTABLE) is running. Stopping it..." + Stop-Process -Name "shareit.server" -Force + Start-Sleep -Seconds 2 + if (Is-ProcessRunning -ProcessName "shareit.server") { + Write-Host "Error: Unable to stop the server executable. Please stop it manually and try again." + exit 1 + } +} + +# Remove installed files +Write-Host "Removing installed files..." +Remove-Item -Path "$INSTALL_DIR\$CLI_EXECUTABLE" -Force +Remove-Item -Path "$INSTALL_DIR\$SERVER_EXECUTABLE" -Force + +# Remove runtime directory +Write-Host "Removing runtime directory..." +Remove-Item -Path $RUNTIME_DIR -Recurse -Force + +Write-Host "Uninstallation complete." diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh new file mode 100755 index 0000000..917635b --- /dev/null +++ b/scripts/uninstall.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +# Determine OS +OS="$(uname -s)" +case "${OS}" in + Linux*) OS=Linux;; + Darwin*) OS=Mac;; + *) echo "Unsupported OS: ${OS}"; exit 1;; +esac + +echo "Uninstalling ShareIT for ${OS}..." + +# Variables +CLI_EXECUTABLE="shareit.cli.linux" +SERVER_EXECUTABLE="shareit.server.linux" +INSTALL_DIR="/usr/local/bin" +RUNTIME_DIR="$HOME/.shareit/" + +if [ "${OS}" == "Mac" ]; then + RUNTIME_DIR="$HOME/Library/Application Support/shareit" + CLI_EXECUTABLE="shareit.cli.darwin" + SERVER_EXECUTABLE="shareit.server.darwin" +fi + +# Function to check if a process is running +is_running() { + pgrep -f "$1" > /dev/null 2>&1 +} + +# Check if CLI executable is running +if is_running "$INSTALL_DIR/$CLI_EXECUTABLE"; then + echo "Error: CLI executable ($CLI_EXECUTABLE) is running. Please stop it before uninstalling." + exit 1 +fi + +# Check if Server executable is running +if is_running "$INSTALL_DIR/$SERVER_EXECUTABLE"; then + echo "Server executable ($SERVER_EXECUTABLE) is running. Stopping it..." + pkill -f "$INSTALL_DIR/$SERVER_EXECUTABLE" + # Wait for the process to stop + sleep 2 + if is_running "$INSTALL_DIR/$SERVER_EXECUTABLE"; then + echo "Error: Unable to stop the server executable. Please stop it manually and try again." + exit 1 + fi +fi + +# Remove installed files +echo "Removing installed files..." +sudo rm -f "$INSTALL_DIR/$CLI_EXECUTABLE" +sudo rm -f "$INSTALL_DIR/$SERVER_EXECUTABLE" + +# Remove runtime directory +echo "Removing runtime directory..." +rm -rf "$RUNTIME_DIR" + +echo "Uninstallation complete." diff --git a/server/main.go b/server/main.go index fd0c8fd..05f195b 100644 --- a/server/main.go +++ b/server/main.go @@ -57,9 +57,13 @@ func (fv *FileVault) Write(key string, value filePathDetails) { func getRuntimeDirectory() string { if runtime.GOOS == "windows" { return filepath.Join(os.Getenv("APPDATA"), "shareit") - } else { - return filepath.Join(os.Getenv("HOME"), ".shareit") } + + if runtime.GOOS == "darwin" { + return filepath.Join(os.Getenv("HOME"), "Library", "Application Support", "shareit") + } + + return filepath.Join(os.Getenv("HOME"), ".shareit") } func (*FileVault) New() *FileVault {