Files
bananarchy/scripts/set-bananarchy-hostname.sh
T

47 lines
1.1 KiB
Bash
Raw Normal View History

#!/bin/sh
# Install the target-specific hostname, hosts file and hostname service link.
set -eu
ROOTFS="${1:-}"
DEVICE="${2:-nokia-argon}"
if [ -z "$ROOTFS" ] || [ ! -d "$ROOTFS" ]; then
echo "Usage: $0 <rootfs-dir> <device>" >&2
exit 1
fi
case "$DEVICE" in
nokia-argon|argon)
DEVICE="nokia-argon"
;;
nokia-beatles|beatles)
DEVICE="nokia-beatles"
;;
nokia-tough|nokia-coconut|tough|coconut)
DEVICE="nokia-tough"
;;
nokia-sparkler|sparkler)
DEVICE="nokia-sparkler"
;;
nokia-leo|leo)
DEVICE="nokia-leo"
;;
*)
echo "Error: Unsupported device '$DEVICE'." >&2
echo "Supported devices: nokia-argon, nokia-beatles, nokia-tough, nokia-sparkler, nokia-leo" >&2
exit 1
;;
esac
mkdir -p "$ROOTFS/etc" "$ROOTFS/etc/runlevels/boot"
printf '%s\n' "$DEVICE" > "$ROOTFS/etc/hostname"
cat > "$ROOTFS/etc/hosts" <<EOF
127.0.0.1 $DEVICE localhost.localdomain localhost
::1 $DEVICE localhost ipv6-localhost ipv6-loopback
fe00::0 ipv6-localnet
ff00::0 ipv6-mcastprefix
ff02::1 ipv6-allnodes
ff02::2 ipv6-allrouters
ff02::3 ipv6-allhosts
EOF
ln -sfn /etc/init.d/hostname "$ROOTFS/etc/runlevels/boot/hostname"