This commit is contained in:
Your Name
2025-04-21 09:58:37 +12:00
parent 9e5a54ff36
commit 093dee3fd3
14 changed files with 577 additions and 36 deletions

30
src/dropshell-completion.bash Executable file
View File

@ -0,0 +1,30 @@
#!/bin/bash
_dropshell_completions() {
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
# List of main commands
opts="help version status"
# If we're completing the first argument, show all commands
if [[ ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi
# Command-specific completions
case "${prev}" in
status)
# No additional completions for status
COMPREPLY=()
;;
*)
;;
esac
}
# Register the completion function
complete -F _dropshell_completions dropshell

142
src/dropshell.sh Executable file
View File

@ -0,0 +1,142 @@
#!/bin/bash
# Script name: dropshell.sh
# Description: A basic shell script for common operations
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Source version information
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
source "$SCRIPT_DIR/version.sh"
# Source configuration
if [ -f "/etc/dropshell.conf" ]; then
source "/etc/dropshell.conf"
else
echo -e "${RED}Error: Configuration file not found${NC}"
echo "Please run the installation script first"
exit 1
fi
# Check if USER_DEFINITIONS is set
if [ -z "$USER_DEFINITIONS" ]; then
echo -e "${RED}Error: USER_DEFINITIONS not set${NC}"
echo "Please run the installation script first"
exit 1
fi
# Function to print usage
print_usage() {
echo "Usage: $0 <command> [options]"
echo
echo "Commands:"
echo " help - Show this help message"
echo " version - Show version information"
echo " status - Check system status"
echo " servers - List configured servers"
echo " services - List configured services"
echo " templates - List available templates"
echo
echo "Options:"
echo " -v, --verbose Enable verbose output"
}
# Function to print version
print_version() {
get_version_info
}
# Function to check status
check_status() {
echo -e "${GREEN}System Status:${NC}"
echo "Date: $(date)"
echo "Uptime: $(uptime)"
echo "Memory Usage:"
free -h
echo
echo "Disk Usage:"
df -h /
}
# Function to list servers
list_servers() {
echo -e "${GREEN}Configured Servers:${NC}"
if [ -d "$USER_DEFINITIONS/servers" ]; then
for server in "$USER_DEFINITIONS/servers"/*.json; do
if [ -f "$server" ]; then
name=$(jq -r '.name' "$server")
host=$(jq -r '.host' "$server")
echo "- $name ($host)"
fi
done
else
echo "No servers configured"
fi
}
# Function to list services
list_services() {
echo -e "${GREEN}Configured Services:${NC}"
if [ -d "$USER_DEFINITIONS/services" ]; then
for service in "$USER_DEFINITIONS/services"/*.json; do
if [ -f "$service" ]; then
name=$(jq -r '.name' "$service")
echo "- $name"
fi
done
else
echo "No services configured"
fi
}
# Function to list templates
list_templates() {
echo -e "${GREEN}Available Templates:${NC}"
if [ -d "$USER_DEFINITIONS/templates" ]; then
for template in "$USER_DEFINITIONS/templates"/*.sh; do
if [ -f "$template" ]; then
echo "- $(basename "$template")"
fi
done
else
echo "No templates available"
fi
}
# Main script logic
case "$1" in
"help"|"-h"|"--help")
print_usage
;;
"version"|"-V"|"--version")
print_version
;;
"status")
check_status
;;
"servers")
list_servers
;;
"services")
list_services
;;
"templates")
list_templates
;;
"")
echo -e "${RED}Error: No command provided${NC}"
print_usage
exit 1
;;
*)
echo -e "${RED}Error: Unknown command '$1'${NC}"
print_usage
exit 1
;;
esac
exit 0

15
src/version.sh Normal file
View File

@ -0,0 +1,15 @@
#!/bin/bash
# Version information
DROPSHELL_VERSION="1.0.0"
DROPSHELL_RELEASE_DATE="2025-04-21"
DROPSHELL_AUTHOR="j842"
DROPSHELL_LICENSE="MIT"
# Function to get full version information
get_version_info() {
echo "dropshell version $DROPSHELL_VERSION"
echo "Release date: $DROPSHELL_RELEASE_DATE"
echo "Author: $DROPSHELL_AUTHOR"
echo "License: $DROPSHELL_LICENSE"
}