Skip to content

Commit

Permalink
runtime directory and uninstall scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
harshrai654 committed Jun 8, 2024
1 parent 4973f54 commit d62cdd8
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 5 deletions.
8 changes: 6 additions & 2 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
44 changes: 44 additions & 0 deletions scripts/uninstall.ps1
Original file line number Diff line number Diff line change
@@ -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."
57 changes: 57 additions & 0 deletions scripts/uninstall.sh
Original file line number Diff line number Diff line change
@@ -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."
8 changes: 6 additions & 2 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d62cdd8

Please sign in to comment.