blob: 796de26e19a8d66ccc76c457d09a5a16b49333a3 [file] [log] [blame]
June Tate-Gans84964332018-12-20 14:14:25 -08001#!/bin/bash
2
June Tate-Gans96baa142018-12-20 18:26:51 -08003ADJECTIVES_FILE=/usr/share/aiy-board-tweaks/adjectives.txt
4NOUNS_FILE=/usr/share/aiy-board-tweaks/nouns.txt
5
June Tate-Gans84964332018-12-20 14:14:25 -08006random_word()
7{
8 local wordlist=$1; shift
9 local max=$(wc -l $wordlist |awk '{ print $1 }')
10 local line=$(($RANDOM % $max + 1))
11
12 head -n $line $wordlist |tail -n 1
13}
14
15generate_hostname()
16{
June Tate-Gans96baa142018-12-20 18:26:51 -080017 local adj=$(random_word $ADJECTIVES_FILE)
18 local noun=$(random_word $NOUNS_FILE)
June Tate-Gans84964332018-12-20 14:14:25 -080019
20 echo "${adj}-${noun}"
21}
22
23hostname=$(generate_hostname)
24echo $hostname >/etc/hostname
June Tate-Gans96baa142018-12-20 18:26:51 -080025/bin/hostname $hostname
June Tate-Gans84964332018-12-20 14:14:25 -080026/usr/bin/hostnamectl set-hostname $hostname
June Tate-Gans96baa142018-12-20 18:26:51 -080027echo 127.0.0.1 $hostname >>/etc/hosts