Fix Linux installer ownership and path issues
- Use SCRIPT_DIR to find source files from any directory - Create venv as target user (sudo -u) for correct ownership - Add python3 existence check - Add source file existence check - Add group to systemd service - Fix uninstall.sh root check Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
54
install.sh
54
install.sh
@@ -6,34 +6,65 @@ set -e
|
|||||||
|
|
||||||
INSTALL_DIR="/opt/kao"
|
INSTALL_DIR="/opt/kao"
|
||||||
SERVICE_FILE="/etc/systemd/system/kao.service"
|
SERVICE_FILE="/etc/systemd/system/kao.service"
|
||||||
CURRENT_USER=$(whoami)
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
|
# Use SUDO_USER if running via sudo, otherwise current user
|
||||||
|
CURRENT_USER="${SUDO_USER:-$(whoami)}"
|
||||||
|
CURRENT_GROUP="$(id -gn "$CURRENT_USER")"
|
||||||
|
|
||||||
echo "===================================="
|
echo "===================================="
|
||||||
echo " Kao Installer"
|
echo " Kao Installer"
|
||||||
echo "===================================="
|
echo "===================================="
|
||||||
echo "Install directory: $INSTALL_DIR"
|
echo "Install directory: $INSTALL_DIR"
|
||||||
echo "Running as user: $CURRENT_USER"
|
echo "Running as user: $CURRENT_USER"
|
||||||
|
echo "Source: $SCRIPT_DIR"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Check if running with appropriate permissions
|
# Check if running as root
|
||||||
if [ ! -w "/opt" ]; then
|
if [ "$EUID" -ne 0 ]; then
|
||||||
echo "Error: Need write access to /opt"
|
echo "Error: Must run as root"
|
||||||
echo "Run with: sudo $0"
|
echo "Run with: sudo $0"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -z "$CURRENT_USER" ] || [ "$CURRENT_USER" = "root" ]; then
|
||||||
|
echo "Error: Could not determine target user"
|
||||||
|
echo "Run with: sudo $0"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check for python3
|
||||||
|
if ! command -v python3 &> /dev/null; then
|
||||||
|
echo "Error: python3 not found"
|
||||||
|
echo "Install with: sudo apt install python3 python3-venv"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check source files exist
|
||||||
|
if [ ! -f "$SCRIPT_DIR/kao.py" ]; then
|
||||||
|
echo "Error: Source files not found in $SCRIPT_DIR"
|
||||||
|
echo "Run this script from the Kao repository directory"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Create install directory
|
# Create install directory
|
||||||
echo "[1/5] Creating install directory..."
|
echo "[1/5] Creating install directory..."
|
||||||
mkdir -p "$INSTALL_DIR"
|
mkdir -p "$INSTALL_DIR"
|
||||||
cp -r aggregator.py kao.py index.html config.json requirements.txt detectors "$INSTALL_DIR/"
|
cp "$SCRIPT_DIR/aggregator.py" "$INSTALL_DIR/"
|
||||||
chown -R "$CURRENT_USER:$CURRENT_USER" "$INSTALL_DIR"
|
cp "$SCRIPT_DIR/kao.py" "$INSTALL_DIR/"
|
||||||
|
cp "$SCRIPT_DIR/index.html" "$INSTALL_DIR/"
|
||||||
|
cp "$SCRIPT_DIR/config.json" "$INSTALL_DIR/"
|
||||||
|
cp "$SCRIPT_DIR/requirements.txt" "$INSTALL_DIR/"
|
||||||
|
cp -r "$SCRIPT_DIR/detectors" "$INSTALL_DIR/"
|
||||||
|
|
||||||
# Create virtual environment
|
# Set ownership before venv creation
|
||||||
|
chown -R "$CURRENT_USER:$CURRENT_GROUP" "$INSTALL_DIR"
|
||||||
|
|
||||||
|
# Create virtual environment as target user
|
||||||
echo "[2/5] Creating virtual environment..."
|
echo "[2/5] Creating virtual environment..."
|
||||||
cd "$INSTALL_DIR"
|
sudo -u "$CURRENT_USER" python3 -m venv "$INSTALL_DIR/venv"
|
||||||
python3 -m venv venv
|
sudo -u "$CURRENT_USER" "$INSTALL_DIR/venv/bin/pip" install --upgrade pip -q
|
||||||
./venv/bin/pip install --upgrade pip -q
|
sudo -u "$CURRENT_USER" "$INSTALL_DIR/venv/bin/pip" install -r "$INSTALL_DIR/requirements.txt" -q
|
||||||
./venv/bin/pip install -r requirements.txt -q
|
|
||||||
|
|
||||||
# Create systemd service
|
# Create systemd service
|
||||||
echo "[3/5] Creating systemd service..."
|
echo "[3/5] Creating systemd service..."
|
||||||
@@ -45,6 +76,7 @@ After=network.target
|
|||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
User=$CURRENT_USER
|
User=$CURRENT_USER
|
||||||
|
Group=$CURRENT_GROUP
|
||||||
WorkingDirectory=$INSTALL_DIR
|
WorkingDirectory=$INSTALL_DIR
|
||||||
ExecStart=$INSTALL_DIR/venv/bin/python $INSTALL_DIR/kao.py
|
ExecStart=$INSTALL_DIR/venv/bin/python $INSTALL_DIR/kao.py
|
||||||
Restart=always
|
Restart=always
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ echo "===================================="
|
|||||||
echo " Kao Uninstaller"
|
echo " Kao Uninstaller"
|
||||||
echo "===================================="
|
echo "===================================="
|
||||||
|
|
||||||
# Check permissions
|
# Check if running as root
|
||||||
if [ ! -w "/opt" ]; then
|
if [ "$EUID" -ne 0 ]; then
|
||||||
echo "Error: Need write access"
|
echo "Error: Must run as root"
|
||||||
echo "Run with: sudo $0"
|
echo "Run with: sudo $0"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user