Mowson.org/karl

Here is a basic script used to set time/date on the Evo T20 at powerup - this is necessary because the T20 has no hardware real-time-clock (RTC), so it thinks the year is 1970 unless you tell it differently.

Note: this all might need changing if you’re not using a fixed IP address like me - the network needs to be up before we call the ntp-time script, and that may not be the case if there is a background task getting a DHCP address.

Save this script as /opt/ntp-time.lua

#! /bin/lua
--[[
# This script based on:
#   http://www.damnsmalllinux.org/f/topic-3-23-17618-0.html
#
# Modified by Karl Mowatt-Wilson, 24 Apr 2007.
# Needed to change host (time.nist.gov no longer serves on port 13)
#  See http://tf.nist.gov/service/its.htm
# Added receive of line before loop.
#----------------
# This lua script based in part of the idea expressed in
# the bash script from newOldUser of the damnsmall linux forums
# by Robert Shingledecker - 2007/02/17
# This script gets time information from time.nist.gov in
# universal time format. It then rearranges it into
# the format that the date command uses MMDDhhmmCCYY.ss
# and issues the date command as super user.
#
# An internet connection must be available
#
#  sample of returned information follows
#54144 07-02-13 16:14:43 00 0 0  95.3 UTC(NIST) *
#1---0----1----1----2----2----3----3----4----4----5
#1---5----0----5----0----5----0----5----0----5----0
--]]

host = "time-a.nist.gov"
port = 13
target = {10,13,16,19,7,22}
date = ""

timeserver,err = socket.connect(host,port)
if err then
  print("Could not connect "..err)
  os.exit(1)
end
_,err = timeserver:send("anything\n")
if err then
  print("Error in sending "..err)
  os.exit(1)
end

-- KMW: need to rx a line, otherwise error.
_,_ = timeserver:receive('*l')

timeserver:settimeout(0.10)
while 1 do
  line,err = timeserver:receive('*l')
  if err then
     print("Error in receiving - "..err)
     os.exit(1)
  end
  if string.find(line,"UTC") then
     for i = 1, 6 do
        if i == 5 then date = date .. "20" end
        if i == 6 then date = date .. "." end
        date = date .. string.sub(line,target[i],target[i]+1)
     end
     os.execute("date -u "..date)
     os.exit(0)
  end
end

Add this line to ~/.filetool.lst (this is the list of files/dirs which DSL saves on shutdown)

opt/ntp-time.lua

Your .filetool.lst will end up looking something like this:

opt/ppp
opt/bootlocal.sh
opt/powerdown.sh
opt/ntp-time.lua
opt/.dslrc
opt/.mydsl_dir
home/dsl/

I’m not sure what is in there by default, but you will at least need the bootlocal line as well as the ntp-time line.

Add these lines to /opt/bootlocal.sh, somewhere near the end, perhaps (certainly after any network setup you may have):

# set time from ntp server
lua /opt/ntp-time.lua

Restart DSL to see if it all works.


My complete bootlocal.sh contains this, at the moment (some of it may not be necessary - I’ve not got around to tidying yet):

#!/bin/bash
# put other system startup command here
loadkeys us

# Get rid of annoying "eth0: Wake-up event" messages
# Proper fix is to recompile driver, but I've not done it yet
sysctl -w kernel.printk=5

# setup audio driver for Evo T20
modprobe sb mpu_io=0

# setup a fixed IP address
ifconfig eth0 192.168.1.30
route add default gw 192.168.1.1
echo nameserver 192.168.1.1 > /etc/resolv.conf
ifup eth0

# set time from ntp server
lua /opt/ntp-time.lua

# configure sshd for public-key only
grep 'PasswordAuthentication' -v  /etc/ssh/sshd_config >|/etc/ssh/sshd_config.tmp
echo 'PasswordAuthentication no'  >>/etc/ssh/sshd_config.tmp
echo 'PubkeyAuthentication   yes' >>/etc/ssh/sshd_config.tmp
mv /etc/ssh/sshd_config.tmp /etc/ssh/sshd_config

# setup sshd with some saved host keys, for consistency
cp /home/dsl/.ssh/ssh_host* /etc/ssh
chown root:root /etc/ssh/ssh_host*

# start sshd
/etc/init.d/ssh start