Skip to content

Instantly share code, notes, and snippets.

@probonopd
Last active June 15, 2022 16:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save probonopd/e5447a774899006af57f to your computer and use it in GitHub Desktop.
Save probonopd/e5447a774899006af57f to your computer and use it in GitHub Desktop.
Modify stock OpenWrt installation to be a DHCP client and to use USB storage to expand capacity; provide TimeCapsule service
# Installed barrier_breaker rc2 OpenWrt image
# Set computer to 192.168.1.2
telnet 192.168.1.1
passwd
# Set new root password; this enables ssh
# Set up the wired network interface as a DCHP client
cat > /etc/config/network <<\EOF
config interface 'loopback'
option ifname 'lo'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'
config interface 'lan0'
option ifname 'eth0'
option proto 'dhcp'
config interface 'lan1'
option ifname 'eth1'
option proto 'dhcp'
EOF
# Get address (to find the device afterwards)
ifconfig | grep eth0 | grep HWaddr | cut -d " " -f 11
0C:82:xx:xx:xx:xx
sync && reboot
# Connect Ethernet to a router
# Find the device on the network
sudo nmap -sP 192.168.0.1/24 | grep "0C:82" -C 2
# ssh <ip>
opkg update
opkg install block-mount kmod-usb-storage kmod-scsi-core kmod-fs-ext4 e2fsprogs fdisk
sync && reboot
# Make one new partition and format the disk
fdisk /dev/sda
g
n
1
<enter>
<enter>
w
q
mkfs.ext4 /dev/sda1
## WORKING extroot overlay
cat > /etc/config/fstab <<EOF
config global automount
option from_fstab 1
option anon_mount 1
option delay_root 3
config mount
option target /overlay
option device /dev/sda1
option fstype ext4
option options rw,sync,noatime
option enabled 1
option enabled_fsck 0
EOF
# NEED to have /etc/configuration there,
# otherwise openWRT copies in some
# non-working (for me) network configuration
# If we do not copy in a preconfigured password,
# the router is reachable via telnet
# Set up the wired network interface as a DCHP client
mkdir -p etc/config/
cat > etc/config/network <<\EOF
config interface 'loopback'
option ifname 'lo'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'
config interface 'lan0'
option ifname 'eth0'
option proto 'dhcp'
config interface 'lan1'
option ifname 'eth1'
option proto 'dhcp'
EOF
#######################
# What follows is a (stupid) alternative; to use a chroot
# Also see http://wiki.openwrt.org/doc/howto/chroot.external
# and http://wiki.openwrt.org/timemachine
mkdir chroot/
cd chroot/
cp -r /rom/* .
mount -o bind /dev dev/
mount -t proc none proc/
echo "nameserver 8.8.8.8" > etc/resolv.conf
chroot .
mkdir var/lock/
opkg update
opkg install kmod-usb-storage kmod-fs-hfsplus block-mount
opkg install nano
# edit so that we have attitude_adjustment sources (for now)
opkg update
opkg install netatalk
opkg install avahi-daemon
mkdir /TimeMachine
chown root:timemachine /TimeMachine
opkg install shadow-useradd shadow-groupadd
groupadd timemachine
useradd -M -G timemachine tmuser
passwd tmuser
echo '"TimeMachine" -uampath /usr/lib/uams -uamlist uams_dhx2.so -nodebug -nouservol -icon -nosavepassword -mimicmodel RackMac' > /etc/netatalk/afpd.conf
echo '/TimeMachine TimeMachine volsizelimit:150000 allow:@timemachine rwlist:@timemachine cnidscheme:dbd options:searchdb,usedots,invisibledots,tm' >> /etc/netatalk/AppleVolumes.default
nano /etc/avahi/avahi-daemon.conf
host-name=TimeMachine
enable-dbus=no
IP=$(ifconfig | grep eth0 | grep HWaddr | cut -d " " -f 11)
cat > /etc/avahi/services/afpd.service <<EOF
<?xml version="1.0" standalone="no"?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">Time Capsule</name>
<service>
<type>_afpovertcp._tcp</type>
<port>548</port>
</service>
<service>
<type>_device-info._tcp</type>
<port>0</port>
<txt-record>model=TimeCapsule</txt-record>
</service>
<service>
<type>_adisk._tcp</type>
<port>9</port>
<txt-record>sys=waMA=$IP,adVF=0x100</txt-record>
<txt-record>dk1=adVF=0x83,adVN=TimeMachine</txt-record>
</service>
</service-group>
EOF
/etc/init.d/avahi-daemon stop
/etc/init.d/avahi-daemon start
/etc/init.d/avahi-daemon enable
Strangely I have to run avahi-daemon by hand
And when I include in /etc/netatalk/afpd.conf the following line,
-setuplog "default log_maxdebug /tmp/afpd.log"
then i get in /tmp/afpd.log
Aug 09 15:06:50.920948 afpd[2718] {afp_dsi.c:610} (D5:AFPDaemon): <== Start AFP command: AFP_LOGIN_EXT
Aug 09 15:06:50.921759 afpd[2718] {uams_dhx2_passwd.c:275} (I:UAMS): DHX2 login: tmuser
Aug 09 15:06:50.924317 afpd[2713] {main.c:219} (I:AFPDaemon): child[2718]: killed by signal 6
Aug 09 15:06:50.924629 afpd[2713] {main.c:423} (D10:AFPDaemon): main: polling 1 fds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment