Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
bamarni committed Apr 11, 2017
1 parent 95eef1c commit 1b2c893
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ echo "dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0
git clone --depth=1 -b rpi-4.9.y https://github.com/raspberrypi/linux.git

cd linux
sed -i 's/^EXTRAVERSION =.*/EXTRAVERSION = pi64/g' Makefile
cp ../../.config ./
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- olddefconfig
make -j 3 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
Expand Down
12 changes: 10 additions & 2 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@ import (
)

func setHostname(hostname string) error {
if err := ioutil.WriteFile("/etc/hostname", []byte(hostname), 0644); err != nil {
if err := ioutil.WriteFile("/etc/hostname", []byte(hostname+"\n"), 0644); err != nil {
return err
}

hosts, err := ioutil.ReadFile("/etc/hosts")
if err != nil {
return err
}

reg, _ := regexp.Compile(`(127\.0\.1\.1[\t ]+).*`)
return ioutil.WriteFile("/etc/hosts", reg.ReplaceAll(hosts, []byte("${1}"+hostname)), 0644)
if reg.Match(hosts) {
hosts = reg.ReplaceAll(hosts, []byte("${1}"+hostname))
} else {
hosts = append([]byte("127.0.1.1 "+hostname+"\n"), hosts...)
}

return ioutil.WriteFile("/etc/hosts", hosts, 0644)
}

0 comments on commit 1b2c893

Please sign in to comment.