|
| 1 | +#!/bin/bash |
| 2 | +####################################################### |
| 3 | +# Script: update_issue.sh |
| 4 | +# Description: Generate and update /etc/issue with dynamic system information |
| 5 | +# Author: Websoft9 |
| 6 | +# Date: 2025-11-27 |
| 7 | +####################################################### |
| 8 | + |
| 9 | +set -e |
| 10 | + |
| 11 | +OUTPUT_FILE="/etc/issue" |
| 12 | + |
| 13 | +# Get dynamic system information |
| 14 | +CPU_CORES=$(nproc) |
| 15 | +MEMORY_USAGE=$(free -h | awk 'NR==2 {print $3 "/" $2}') |
| 16 | +DISK_SIZE=$(df -h / | awk 'NR==2 {print $2}') |
| 17 | +DISK_USAGE=$(df -h / | awk 'NR==2 {print $5}') |
| 18 | +IP_ADDRESS=$(hostname -I | cut -d" " -f1) |
| 19 | + |
| 20 | +# Generate /etc/issue content directly |
| 21 | +cat > "$OUTPUT_FILE" <<'EOF' |
| 22 | +Welcome to Websoft9 IoT applications management platform |
| 23 | +
|
| 24 | +Get Support: https://www.websoft9.com |
| 25 | +
|
| 26 | +================================================== |
| 27 | +
|
| 28 | +-------------------------------------------------- |
| 29 | +Hostname: \n |
| 30 | +OS: \s \v \n \r \m |
| 31 | +CPU core: CPU_CORES_PLACEHOLDER |
| 32 | +Memory usage: MEMORY_USAGE_PLACEHOLDER |
| 33 | +Disk: DISK_SIZE_PLACEHOLDER, DISK_USAGE_PLACEHOLDER usage |
| 34 | +-------------------------------------------------- |
| 35 | +
|
| 36 | +Login to Websoft9 Console |
| 37 | +
|
| 38 | +URL: http://IP_ADDRESS_PLACEHOLDER:9000 |
| 39 | +Username: websoft9 |
| 40 | +
|
| 41 | +
|
| 42 | +Latest starting time: \t |
| 43 | +
|
| 44 | +\l |
| 45 | +EOF |
| 46 | + |
| 47 | +# Replace placeholders with actual values (using | as delimiter to avoid issues with /) |
| 48 | +sed -i "s|CPU_CORES_PLACEHOLDER|$CPU_CORES|g" "$OUTPUT_FILE" |
| 49 | +sed -i "s|MEMORY_USAGE_PLACEHOLDER|$MEMORY_USAGE|g" "$OUTPUT_FILE" |
| 50 | +sed -i "s|DISK_SIZE_PLACEHOLDER|$DISK_SIZE|g" "$OUTPUT_FILE" |
| 51 | +sed -i "s|DISK_USAGE_PLACEHOLDER|$DISK_USAGE|g" "$OUTPUT_FILE" |
| 52 | +sed -i "s|IP_ADDRESS_PLACEHOLDER|$IP_ADDRESS|g" "$OUTPUT_FILE" |
| 53 | + |
| 54 | +# Set proper permissions |
| 55 | +chmod 644 "$OUTPUT_FILE" |
| 56 | + |
| 57 | +echo "Successfully updated $OUTPUT_FILE" |
| 58 | + |
| 59 | + |
| 60 | +# delete cockpit issue file content |
| 61 | +[ -f /usr/share/cockpit/issue/update-issue ] && sed -i '/\/run\/cockpit\/active\.issue/d' /usr/share/cockpit/issue/update-issue |
| 62 | + |
| 63 | +# Set GRUB timeout to 0 if not already set |
| 64 | +if [ -f /etc/grub.d/40_custom ] && ! grep -q "set timeout=0" /etc/grub.d/40_custom; then |
| 65 | + tee -a /etc/grub.d/40_custom << EOF |
| 66 | +set timeout=0 |
| 67 | +set timeout_style=hidden |
| 68 | +EOF |
| 69 | +fi |
| 70 | +exit 0 |
0 commit comments