dropshell/install.sh
Your Name 093dee3fd3 .
2025-04-21 09:58:37 +12:00

106 lines
2.7 KiB
Bash
Executable File

#!/bin/bash
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Check if USER_DEFINITIONS is provided
if [ -z "$1" ]; then
echo -e "${RED}Error: USER_DEFINITIONS path is required${NC}"
echo "Usage: $0 <USER_DEFINITIONS_PATH>"
echo "Example: $0 ~/.config/dropshell"
exit 1
fi
USER_DEFINITIONS="$1"
# Script locations
SCRIPT_SOURCE="$(pwd)/src/dropshell.sh"
SCRIPT_DEST="/usr/local/bin/dropshell"
COMPLETION_SOURCE="$(pwd)/src/dropshell-completion.bash"
COMPLETION_DEST="/etc/bash_completion.d/dropshell"
# Check if running with sudo/root
if [ "$EUID" -ne 0 ]; then
echo -e "${RED}Please run as root or with sudo${NC}"
exit 1
fi
# Check if source script exists
if [ ! -f "$SCRIPT_SOURCE" ]; then
echo -e "${RED}Error: $SCRIPT_SOURCE not found${NC}"
echo "Please ensure the script exists in the src directory"
exit 1
fi
# Check if completion script exists
if [ ! -f "$COMPLETION_SOURCE" ]; then
echo -e "${RED}Error: $COMPLETION_SOURCE not found${NC}"
echo "Please ensure the completion script exists in the src directory"
exit 1
fi
if [ ! -d "$USER_DEFINITIONS" ]; then
# Create user definitions directory structure
echo "Creating user definitions directory structure..."
mkdir -p "$USER_DEFINITIONS/servers"
mkdir -p "$USER_DEFINITIONS/templates"
# Create example files
mkdir -p "$USER_DEFINITIONS/servers/example.com"
cat > "$USER_DEFINITIONS/services/example.com/server.json" << 'EOF'
{
"ssh_address": "localhost",
"ssh_port": 22,
"ssh_user": "$(whoami)"
}
EOF
# cat > "$USER_DEFINITIONS/services/example.com/server.json" << 'EOF'
# {
# "ssh_address": "localhost",
# "ssh_port": 22,
# "ssh_user": "$(whoami)"
# }
# EOF
fi
# Create symbolic link
echo "Creating symbolic link..."
if [ -L "$SCRIPT_DEST" ]; then
rm "$SCRIPT_DEST"
fi
ln -s "$SCRIPT_SOURCE" "$SCRIPT_DEST"
# Make sure the scripts are executable
chmod +x "$SCRIPT_SOURCE"
chmod +x "$COMPLETION_SOURCE"
# Install bash completion
echo "Installing bash completion..."
if [ ! -d "/etc/bash_completion.d" ]; then
mkdir -p "/etc/bash_completion.d"
fi
# Install completion script
cp "$COMPLETION_SOURCE" "$COMPLETION_DEST"
chmod 644 "$COMPLETION_DEST"
# Create environment file
cat > "/etc/dropshell.conf" << EOF
# Dropshell configuration
USER_DEFINITIONS="$USER_DEFINITIONS"
EOF
# Source the completion script
echo "source $COMPLETION_DEST" >> ~/.bashrc
echo -e "${GREEN}Installation completed successfully!${NC}"
echo "User definitions directory created at: $USER_DEFINITIONS"
echo
echo "Please run 'source ~/.bashrc' or start a new terminal to enable completion"
exit 0