Enhance customization script to optionally change server hostname and improve user prompts. Update setup script to copy customization script to sysadmin user's home directory, with fallback to download if local file is missing. Include new password notification for sysadmin user during setup.

This commit is contained in:
2025-09-20 15:43:06 +01:00
parent 037a59039a
commit 55dbf5e37c
2 changed files with 32 additions and 9 deletions

View File

@@ -39,6 +39,14 @@ set_hostname() {
echo -e "${BLUE}=== Server Hostname Configuration ===${NC}"
echo "Current hostname: $(hostname)"
echo ""
read -p "Do you want to change the hostname? (y/N): " change_hostname
if [[ ! "$change_hostname" =~ ^[Yy]$ ]]; then
log "Keeping current hostname: $(hostname)"
return 0
fi
read -p "Enter new hostname for this server: " new_hostname
if [[ -z "$new_hostname" ]]; then
@@ -223,7 +231,7 @@ show_deploy_instructions() {
main() {
echo -e "${BLUE}=== Server Customization Script ===${NC}"
echo "This script will:"
echo "1. Set server hostname"
echo "1. Optionally set server hostname"
echo "2. Create Git deploy keys"
echo "3. Configure SSH for Git repositories"
echo ""

View File

@@ -327,10 +327,10 @@ create_sysadmin_user() {
# Check if the existing user has the default password "hhh"
if echo "hhh" | su - "$SYSADMIN_USER" -c "exit" 2>/dev/null; then
warn "User $SYSADMIN_USER has default password 'hhh', changing to random password"
local random_password=$(openssl rand -base64 12)
echo "$SYSADMIN_USER:$random_password" | chpasswd
SYSADMIN_NEW_PASSWORD=$(openssl rand -base64 12)
echo "$SYSADMIN_USER:$SYSADMIN_NEW_PASSWORD" | chpasswd
echo "=========================================="
echo "NEW PASSWORD for $SYSADMIN_USER: $random_password"
echo "NEW PASSWORD for $SYSADMIN_USER: $SYSADMIN_NEW_PASSWORD"
echo "=========================================="
log "Password changed for existing user $SYSADMIN_USER"
fi
@@ -600,14 +600,23 @@ finalize_setup() {
log "SSH service restarted successfully"
# Download customization script for sysadmin user
log "Downloading customization script..."
if wget -O /home/$SYSADMIN_USER/costumize.sh "https://git.del-c.net/Del-c.net/debian-first-boot-setup/raw/branch/main/costumize.sh"; then
# Copy customization script to sysadmin user home folder
log "Copying customization script..."
if [[ -f "costumize.sh" ]]; then
cp costumize.sh /home/$SYSADMIN_USER/costumize.sh
chmod +x /home/$SYSADMIN_USER/costumize.sh
chown $SYSADMIN_USER:$SYSADMIN_USER /home/$SYSADMIN_USER/costumize.sh
log "Customization script downloaded to /home/$SYSADMIN_USER/costumize.sh"
log "Customization script copied to /home/$SYSADMIN_USER/costumize.sh"
else
warn "Failed to download customization script"
# Fallback to download if local file doesn't exist
log "Local costumize.sh not found, attempting download..."
if wget -O /home/$SYSADMIN_USER/costumize.sh "https://git.del-c.net/Del-c.net/debian-first-boot-setup/raw/branch/main/costumize.sh"; then
chmod +x /home/$SYSADMIN_USER/costumize.sh
chown $SYSADMIN_USER:$SYSADMIN_USER /home/$SYSADMIN_USER/costumize.sh
log "Customization script downloaded to /home/$SYSADMIN_USER/costumize.sh"
else
warn "Failed to copy or download customization script"
fi
fi
# Clean up
@@ -620,8 +629,14 @@ finalize_setup() {
echo -e "${BLUE}=== SETUP SUMMARY ===${NC}"
echo -e "${YELLOW}• Root SSH login: DISABLED${NC}"
echo -e "${YELLOW}• Root password: LOCKED${NC}"
echo -e "${YELLOW}• Sysadmin SSH login: DISABLED${NC}"
echo -e "${YELLOW}• Sysadmin password: LOCKED${NC}"
echo -e "${YELLOW}• Main user: $SYSADMIN_USER (sudo access)${NC}"
if [[ -n "$SYSADMIN_NEW_PASSWORD" ]]; then
echo -e "${RED}• IMPORTANT: Sysadmin password was changed from 'hhh' to: $SYSADMIN_NEW_PASSWORD${NC}"
fi
if [[ "$CREATE_ADDITIONAL_USER" == "yes" && -n "$ADDITIONAL_USER" ]]; then
echo -e "${YELLOW}• Additional user: $ADDITIONAL_USER (sudo access)${NC}"
fi