mirror of
https://github.com/DeBrosOfficial/network.git
synced 2025-12-15 22:58:49 +00:00
fix: enforce interactive mode requirement in installation script
- Added a check to ensure the script is run in an interactive terminal, providing clear error messages and instructions if not. - Removed non-interactive mode handling for user creation, streamlining the user experience and ensuring necessary prompts are displayed. - Updated instructions for re-running the script after user creation to enhance clarity.
This commit is contained in:
parent
46d69baf63
commit
33a13db44d
@ -15,6 +15,19 @@ BLUE='\033[38;2;2;128;175m'
|
|||||||
YELLOW='\033[1;33m'
|
YELLOW='\033[1;33m'
|
||||||
NOCOLOR='\033[0m'
|
NOCOLOR='\033[0m'
|
||||||
|
|
||||||
|
# REQUIRE INTERACTIVE MODE - This script must be run in a terminal
|
||||||
|
if [ ! -t 0 ]; then
|
||||||
|
echo -e "${RED}[ERROR]${NOCOLOR} This script requires an interactive terminal."
|
||||||
|
echo -e ""
|
||||||
|
echo -e "${YELLOW}Please run this script directly in a terminal:${NOCOLOR}"
|
||||||
|
echo -e "${CYAN} sudo bash scripts/install-debros-network.sh${NOCOLOR}"
|
||||||
|
echo -e ""
|
||||||
|
echo -e "${YELLOW}Do NOT pipe this script:${NOCOLOR}"
|
||||||
|
echo -e "${RED} curl ... | bash${NOCOLOR} ← This will NOT work"
|
||||||
|
echo -e ""
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Get absolute path of this script
|
# Get absolute path of this script
|
||||||
SCRIPT_PATH="$(cd "$(dirname "$0")" && pwd)/$(basename "$0")"
|
SCRIPT_PATH="$(cd "$(dirname "$0")" && pwd)/$(basename "$0")"
|
||||||
|
|
||||||
@ -27,7 +40,6 @@ RQLITE_PORT="5001"
|
|||||||
GATEWAY_PORT="6001"
|
GATEWAY_PORT="6001"
|
||||||
RAFT_PORT="7001"
|
RAFT_PORT="7001"
|
||||||
UPDATE_MODE=false
|
UPDATE_MODE=false
|
||||||
NON_INTERACTIVE=false
|
|
||||||
DEBROS_USER="debros"
|
DEBROS_USER="debros"
|
||||||
|
|
||||||
log() { echo -e "${CYAN}[$(date '+%Y-%m-%d %H:%M:%S')]${NOCOLOR} $1"; }
|
log() { echo -e "${CYAN}[$(date '+%Y-%m-%d %H:%M:%S')]${NOCOLOR} $1"; }
|
||||||
@ -35,12 +47,6 @@ error() { echo -e "${RED}[ERROR]${NOCOLOR} $1"; }
|
|||||||
success() { echo -e "${GREEN}[SUCCESS]${NOCOLOR} $1"; }
|
success() { echo -e "${GREEN}[SUCCESS]${NOCOLOR} $1"; }
|
||||||
warning() { echo -e "${YELLOW}[WARNING]${NOCOLOR} $1"; }
|
warning() { echo -e "${YELLOW}[WARNING]${NOCOLOR} $1"; }
|
||||||
|
|
||||||
# Detect non-interactive mode EARLY (before any function calls that require user input)
|
|
||||||
if [ ! -t 0 ]; then
|
|
||||||
NON_INTERACTIVE=true
|
|
||||||
log "Running in non-interactive mode"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if we need to create debros user first (requires root)
|
# Check if we need to create debros user first (requires root)
|
||||||
check_and_setup_debros_user() {
|
check_and_setup_debros_user() {
|
||||||
CURRENT_USER=$(whoami)
|
CURRENT_USER=$(whoami)
|
||||||
@ -52,13 +58,9 @@ check_and_setup_debros_user() {
|
|||||||
|
|
||||||
# If running as root via sudo from debros user, that's also okay for proceeding with installation
|
# If running as root via sudo from debros user, that's also okay for proceeding with installation
|
||||||
if [ "$CURRENT_USER" = "root" ] && [ "$SUDO_USER" = "$DEBROS_USER" ]; then
|
if [ "$CURRENT_USER" = "root" ] && [ "$SUDO_USER" = "$DEBROS_USER" ]; then
|
||||||
# Skip re-exec in non-interactive mode (piped script)
|
|
||||||
if [ "$NON_INTERACTIVE" != true ]; then
|
|
||||||
# Switch back to debros user to run the installation properly
|
# Switch back to debros user to run the installation properly
|
||||||
exec sudo -u "$DEBROS_USER" bash "$SCRIPT_PATH"
|
exec sudo -u "$DEBROS_USER" bash "$SCRIPT_PATH"
|
||||||
fi
|
fi
|
||||||
# In non-interactive mode, just proceed as root (user already explicitly used sudo)
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If not debros user and not root, abort and give instructions
|
# If not debros user and not root, abort and give instructions
|
||||||
if [ "$CURRENT_USER" != "root" ]; then
|
if [ "$CURRENT_USER" != "root" ]; then
|
||||||
@ -78,22 +80,6 @@ check_and_setup_debros_user() {
|
|||||||
echo -e "${YELLOW}DeBros requires a '$DEBROS_USER' system user to run services.${NOCOLOR}"
|
echo -e "${YELLOW}DeBros requires a '$DEBROS_USER' system user to run services.${NOCOLOR}"
|
||||||
echo -e ""
|
echo -e ""
|
||||||
|
|
||||||
# In non-interactive mode, automatically create the user
|
|
||||||
if [ "$NON_INTERACTIVE" = true ]; then
|
|
||||||
log "Non-interactive mode: automatically creating '$DEBROS_USER' user..."
|
|
||||||
useradd -r -m -s /bin/bash -d "$INSTALL_DIR" "$DEBROS_USER" 2>/dev/null || true
|
|
||||||
if id "$DEBROS_USER" &>/dev/null; then
|
|
||||||
success "System user '$DEBROS_USER' created"
|
|
||||||
# Enable passwordless login in non-interactive mode
|
|
||||||
TEMP_PASS="temp123"
|
|
||||||
echo "$DEBROS_USER:$TEMP_PASS" | chpasswd
|
|
||||||
passwd -d "$DEBROS_USER" 2>/dev/null || true
|
|
||||||
success "Passwordless login enabled for '$DEBROS_USER' user"
|
|
||||||
else
|
|
||||||
error "Failed to create user '$DEBROS_USER'"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
# Ask for permission to create the user
|
# Ask for permission to create the user
|
||||||
while true; do
|
while true; do
|
||||||
read -rp "Would you like to create the '$DEBROS_USER' user? (yes/no): " CREATE_USER_CHOICE
|
read -rp "Would you like to create the '$DEBROS_USER' user? (yes/no): " CREATE_USER_CHOICE
|
||||||
@ -156,7 +142,6 @@ check_and_setup_debros_user() {
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
log "User '$DEBROS_USER' already exists"
|
log "User '$DEBROS_USER' already exists"
|
||||||
fi
|
fi
|
||||||
@ -180,7 +165,8 @@ check_and_setup_debros_user() {
|
|||||||
echo -e "${GREEN}Run the following command:${NOCOLOR}"
|
echo -e "${GREEN}Run the following command:${NOCOLOR}"
|
||||||
echo -e "${YELLOW} su - $DEBROS_USER${NOCOLOR}"
|
echo -e "${YELLOW} su - $DEBROS_USER${NOCOLOR}"
|
||||||
echo -e ""
|
echo -e ""
|
||||||
echo -e "${CYAN}Then re-run the script${NOCOLOR}"
|
echo -e "${CYAN}Then re-run the script with:${NOCOLOR}"
|
||||||
|
echo -e "${YELLOW} bash $SCRIPT_PATH${NOCOLOR}"
|
||||||
echo -e ""
|
echo -e ""
|
||||||
echo -e "${BLUE}========================================================================${NOCOLOR}"
|
echo -e "${BLUE}========================================================================${NOCOLOR}"
|
||||||
echo -e ""
|
echo -e ""
|
||||||
@ -193,16 +179,12 @@ check_and_setup_debros_user
|
|||||||
# Root/sudo checks
|
# Root/sudo checks
|
||||||
if [[ $EUID -eq 0 ]]; then
|
if [[ $EUID -eq 0 ]]; then
|
||||||
warning "Running as root is not recommended for security reasons."
|
warning "Running as root is not recommended for security reasons."
|
||||||
if [ "$NON_INTERACTIVE" != true ]; then
|
|
||||||
echo -n "Are you sure you want to continue? (yes/no): "
|
echo -n "Are you sure you want to continue? (yes/no): "
|
||||||
read -r ROOT_CONFIRM
|
read -r ROOT_CONFIRM
|
||||||
if [[ "$ROOT_CONFIRM" != "yes" ]]; then
|
if [[ "$ROOT_CONFIRM" != "yes" ]]; then
|
||||||
error "Installation cancelled for security reasons."
|
error "Installation cancelled for security reasons."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
log "Non-interactive mode: proceeding with root (use at your own risk)"
|
|
||||||
fi
|
|
||||||
alias sudo=''
|
alias sudo=''
|
||||||
else
|
else
|
||||||
if ! command -v sudo &>/dev/null; then
|
if ! command -v sudo &>/dev/null; then
|
||||||
@ -241,11 +223,6 @@ check_existing_installation() {
|
|||||||
NODE_RUNNING=true
|
NODE_RUNNING=true
|
||||||
log "Node service is currently running"
|
log "Node service is currently running"
|
||||||
fi
|
fi
|
||||||
if [ "$NON_INTERACTIVE" = true ]; then
|
|
||||||
log "Non-interactive mode: updating existing installation"
|
|
||||||
UPDATE_MODE=true
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
echo -e "${YELLOW}Existing installation detected!${NOCOLOR}"
|
echo -e "${YELLOW}Existing installation detected!${NOCOLOR}"
|
||||||
|
|
||||||
# Check if we're running as debros user
|
# Check if we're running as debros user
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user