blob: 796de26e19a8d66ccc76c457d09a5a16b49333a3 [file] [log] [blame]
#!/bin/bash
ADJECTIVES_FILE=/usr/share/aiy-board-tweaks/adjectives.txt
NOUNS_FILE=/usr/share/aiy-board-tweaks/nouns.txt
random_word()
{
local wordlist=$1; shift
local max=$(wc -l $wordlist |awk '{ print $1 }')
local line=$(($RANDOM % $max + 1))
head -n $line $wordlist |tail -n 1
}
generate_hostname()
{
local adj=$(random_word $ADJECTIVES_FILE)
local noun=$(random_word $NOUNS_FILE)
echo "${adj}-${noun}"
}
hostname=$(generate_hostname)
echo $hostname >/etc/hostname
/bin/hostname $hostname
/usr/bin/hostnamectl set-hostname $hostname
echo 127.0.0.1 $hostname >>/etc/hosts