#! /usr/bin/perl -w
use strict;
use File::Copy;

# Installer for tellem, tellme, and tellem.conf tellme.conf

# You must run this as root, eg "sudo ./LanDNS" from wherever this is all
# located.  Get a terminal and cd to "here" first, as we assume the
# files to copy are "here" - we can't know where you unzipped them to.

# We copy tellem and tellme to /usr/bin and make them executable 
# We copy the .conf files to /etc/init so next boot the executables are run
# as root.  They are daemons that produce no output to terminals.

# If you set your system monitor preferences to "all processes" you
# should then see tellem and tellme in the process list, probably "sleeping"
# since that is what they do nearly all the time.

# tellem simply broadcasts our hostname and LAN IP address about once a minute.
# tellme looks for these and updates /etc/hosts as required, recognizing
# and ignoring broadcasts from "self" because that would otherwise
# create an additional copy of "self" in /etc/hosts that is slower to 
# access than 127.0.0.1, which is already there.

# once you have a working setup, you can erase all these files from wherever
# you unzipped them to - we've made copies in the system directories.

print "Copying tellem to /usr/bin\n";
copy ("tellem", "/usr/bin") or die "Copy failed, are you root? $!";

print "Copying tellme to /usr/bin\n";
copy ("tellme", "/usr/bin") or die "Copy failed, are you root? $!";

print "Copying tellem.conf to /etc/init\n";
copy ("tellem.conf", "/etc/init") or die "Copy failed, are you root? $!";

print "Copying tellme.conf to /etc/init\n";
copy ("tellme.conf", "/etc/init") or die "Copy failed, are you root? $!";

# might have to mark the scripts as executable here, yup
print "Setting root/execute permissions\n"; # chmod 6711 filepath
my @args = ("chmod", "6711", "/usr/bin/tellem");
system(@args) == 0 or die "system @args failed: $?";
print "tellem now root and executable\n";

@args = ("chmod", "6711", "/etc/init/tellem.conf");
system(@args) == 0 or die "system @args failed: $?";
print "tellem.conf now root and executable\n";

@args = ("chmod", "6711", "/usr/bin/tellme");
system(@args) == 0 or die "system @args failed: $?";
print "tellme now root and executable\n";

@args = ("chmod", "6711", "/etc/init/tellme.conf");
system(@args) == 0 or die "system @args failed: $?";
print "tellme.conf now root and executable\n";


print "Install complete, you must restart for this to take effect.\n";
