mirror of
https://github.com/fosrl/olm.git
synced 2026-02-07 21:46:40 +00:00
Update get olm script to work with sudo
This commit is contained in:
84
get-olm.sh
84
get-olm.sh
@@ -110,22 +110,37 @@ detect_platform() {
|
|||||||
|
|
||||||
# Get installation directory
|
# Get installation directory
|
||||||
get_install_dir() {
|
get_install_dir() {
|
||||||
if [ "$OS" = "windows" ]; then
|
local platform="$1"
|
||||||
|
|
||||||
|
if [[ "$platform" == *"windows"* ]]; then
|
||||||
echo "$HOME/bin"
|
echo "$HOME/bin"
|
||||||
else
|
else
|
||||||
# Try to use a directory in PATH, fallback to ~/.local/bin
|
# For Unix-like systems, prioritize system-wide directories for sudo access
|
||||||
if echo "$PATH" | grep -q "/usr/local/bin"; then
|
# Check in order of preference: /usr/local/bin, /usr/bin, ~/.local/bin
|
||||||
if [ -w "/usr/local/bin" ] 2>/dev/null; then
|
if [ -d "/usr/local/bin" ]; then
|
||||||
echo "/usr/local/bin"
|
echo "/usr/local/bin"
|
||||||
else
|
elif [ -d "/usr/bin" ]; then
|
||||||
echo "$HOME/.local/bin"
|
echo "/usr/bin"
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
|
# Fallback to user directory if system directories don't exist
|
||||||
echo "$HOME/.local/bin"
|
echo "$HOME/.local/bin"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Check if we need sudo for installation
|
||||||
|
need_sudo() {
|
||||||
|
local install_dir="$1"
|
||||||
|
|
||||||
|
# If installing to system directory and we don't have write permission, need sudo
|
||||||
|
if [[ "$install_dir" == "/usr/local/bin" || "$install_dir" == "/usr/bin" ]]; then
|
||||||
|
if [ ! -w "$install_dir" ] 2>/dev/null; then
|
||||||
|
return 0 # Need sudo
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
return 1 # Don't need sudo
|
||||||
|
}
|
||||||
|
|
||||||
# Download and install olm
|
# Download and install olm
|
||||||
install_olm() {
|
install_olm() {
|
||||||
local platform="$1"
|
local platform="$1"
|
||||||
@@ -155,22 +170,43 @@ install_olm() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Check if we need sudo for installation
|
||||||
|
local use_sudo=""
|
||||||
|
if need_sudo "$install_dir"; then
|
||||||
|
print_status "Administrator privileges required for system-wide installation"
|
||||||
|
if command -v sudo >/dev/null 2>&1; then
|
||||||
|
use_sudo="sudo"
|
||||||
|
else
|
||||||
|
print_error "sudo is required for system-wide installation but not available"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Create install directory if it doesn't exist
|
# Create install directory if it doesn't exist
|
||||||
mkdir -p "$install_dir"
|
if [ -n "$use_sudo" ]; then
|
||||||
|
$use_sudo mkdir -p "$install_dir"
|
||||||
|
else
|
||||||
|
mkdir -p "$install_dir"
|
||||||
|
fi
|
||||||
|
|
||||||
# Move binary to install directory
|
# Move binary to install directory
|
||||||
mv "$temp_file" "$final_path"
|
if [ -n "$use_sudo" ]; then
|
||||||
|
$use_sudo mv "$temp_file" "$final_path"
|
||||||
# Make executable (not needed on Windows, but doesn't hurt)
|
$use_sudo chmod +x "$final_path"
|
||||||
chmod +x "$final_path"
|
else
|
||||||
|
mv "$temp_file" "$final_path"
|
||||||
|
chmod +x "$final_path"
|
||||||
|
fi
|
||||||
|
|
||||||
print_status "olm installed to ${final_path}"
|
print_status "olm installed to ${final_path}"
|
||||||
|
|
||||||
# Check if install directory is in PATH
|
# Check if install directory is in PATH (only warn for non-system directories)
|
||||||
if ! echo "$PATH" | grep -q "$install_dir"; then
|
if [[ "$install_dir" != "/usr/local/bin" && "$install_dir" != "/usr/bin" ]]; then
|
||||||
print_warning "Install directory ${install_dir} is not in your PATH."
|
if ! echo "$PATH" | grep -q "$install_dir"; then
|
||||||
print_warning "Add it to your PATH by adding this line to your shell profile:"
|
print_warning "Install directory ${install_dir} is not in your PATH."
|
||||||
print_warning " export PATH=\"${install_dir}:\$PATH\""
|
print_warning "Add it to your PATH by adding this line to your shell profile:"
|
||||||
|
print_warning " export PATH=\"${install_dir}:\$PATH\""
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,19 +248,27 @@ main() {
|
|||||||
print_status "Detected platform: ${PLATFORM}"
|
print_status "Detected platform: ${PLATFORM}"
|
||||||
|
|
||||||
# Get install directory
|
# Get install directory
|
||||||
INSTALL_DIR=$(get_install_dir)
|
INSTALL_DIR=$(get_install_dir "$PLATFORM")
|
||||||
print_status "Install directory: ${INSTALL_DIR}"
|
print_status "Install directory: ${INSTALL_DIR}"
|
||||||
|
|
||||||
|
# Inform user about system-wide installation
|
||||||
|
if [[ "$INSTALL_DIR" == "/usr/local/bin" || "$INSTALL_DIR" == "/usr/bin" ]]; then
|
||||||
|
print_status "Installing system-wide for sudo access"
|
||||||
|
fi
|
||||||
|
|
||||||
# Install olm
|
# Install olm
|
||||||
install_olm "$PLATFORM" "$INSTALL_DIR"
|
install_olm "$PLATFORM" "$INSTALL_DIR"
|
||||||
|
|
||||||
# Verify installation
|
# Verify installation
|
||||||
if verify_installation "$INSTALL_DIR"; then
|
if verify_installation "$INSTALL_DIR"; then
|
||||||
print_status "olm is ready to use!"
|
print_status "olm is ready to use!"
|
||||||
|
if [[ "$INSTALL_DIR" == "/usr/local/bin" || "$INSTALL_DIR" == "/usr/bin" ]]; then
|
||||||
|
print_status "olm is installed system-wide and accessible via sudo"
|
||||||
|
fi
|
||||||
if [[ "$PLATFORM" == *"windows"* ]]; then
|
if [[ "$PLATFORM" == *"windows"* ]]; then
|
||||||
print_status "Run 'olm --help' to get started"
|
print_status "Run 'olm --help' to get started"
|
||||||
else
|
else
|
||||||
print_status "Run 'olm --help' to get started"
|
print_status "Run 'olm --help' or 'sudo olm --help' to get started"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
Reference in New Issue
Block a user