Permalink
Browse files

much improved IPKG version added

  • Loading branch information...
1 parent 4170519 commit aa0405cb130cfb814128a8eca45ab60a879370e5 @cr committed Jan 30, 2011
View
@@ -0,0 +1,30 @@
+NAME = piratebox
+VERSION = 1-1
+ARCH = all
+IPK = $(NAME)_$(VERSION)_$(ARCH).ipk
+IPKDIR = src
+
+.DEFAULT_GOAL = all
+
+$(IPKDIR)/control.tar.gz: $(IPKDIR)/control
+ tar czf $@ -C $(IPKDIR)/control .
+control: $(IPKDIR)/control.tar.gz
+
+$(IPKDIR)/data.tar.gz: $(IPKDIR)/data
+ tar czf $@ -C $(IPKDIR)/data .
+data: $(IPKDIR)/data.tar.gz
+
+$(IPK): $(IPKDIR)/control.tar.gz $(IPKDIR)/data.tar.gz $(IPKDIR)/control $(IPKDIR)/data
+ tar czf $@ -C $(IPKDIR) control.tar.gz data.tar.gz debian-binary
+
+all: $(IPK)
+
+cleanbuild:
+ -rm -f $(IPKDIR)/control.tar.gz
+ -rm -f $(IPKDIR)/data.tar.gz
+
+clean: cleanbuild
+ -rm -f $(IPK)
+
+.PHONY: all clean
+
View
37 README
@@ -1,27 +1,27 @@
###########################################################################
-# mkPirateBox.sh v0.1
-# Shell script that installs PirateBox to your fresh OpenWRT router
+# mkPirateBox v0.2
+# IPKG that installs PirateBox to your fresh OpenWRT router
# (C) 2011, Christiane Ruetten, cr@23bit.net
#
# Released under GPLv2, see http://www.gnu.org/licenses/gpl-2.0.html
FEATURES:
- - Execute this script on your fresh OpenWRT Backfire installation
- and out comes (hopefully) a ready-to-use PirateBox.
+ - Install this IPKG on your fresh OpenWRT "Backfire", and out comes
+ (hopefully) a ready-to-use PirateBox.
+ - Now supports devices with 4 MByte flash
+ - Tested on Asus WL-500gP, Asus WL-500g and Buffalo WZR-HP-G300NH
TODO:
- - Test other Platforms than Asus WL-500gP
+ - Test other platforms
- Error checking
- - Move stage two completely into the init script
- - Wrap it up in an opk package
+ - Gracefully handle fresh USB storage after setup
REQUIREMENTS:
- Decently powerful router with USB2.0 port which is supported by OpenWRT.
- It should have 200MHz, 32 MByte RAM and 8 MByte flash. If you want a
+ It should have 200MHz, 32 MByte RAM and 4 MByte flash. If you want a
recommendation: get a Buffalo WZR-HP-G300NH or an Asus WL-500gP.
- - PirateBox can be installed on 4 MByte flash, but there is no space
- for e2fsprogs which are required for automated setup of the loop
- ext3 partition on the USB disk.
+ - A 125 MHz system works, but HTTP uploads may drop dramatically to
+ about 100 KByte/s. Also observed instability.
- An external USB hard drive (UMS compatible) formattet with FAT32.
- Two ethernet cables
@@ -34,17 +34,16 @@ INSTALL:
with a FAT32 file system.
- telnet into the router on 192.168.1.1.
- cd /tmp
- - opkg update && opkg install wget
- - wget --no-check-certificate https://github.com/cr/mkPirateBox/raw/master/mkPirateBox.sh
- - chmod +x mkPirateBox.sh
- - ./mkPirateBox.sh
- - Follow the instructions until the first reset.
+ - wget http://cr.23bit.net/piratebox/piratebox_1-1_all.ipk
+ (Sorry, github only supports https downloads.)
+ - opkg update && opkg install piratebox*
+ - When prompted, set a root password.
+ - After setup has finished, reboot the router.
- Wait for the open wireless network "PirateBox" to appear.
- Connect and open any web page.
- If you see the PirateBox menu, you're done.
- - See /root/mkPirateBox.log in case anything went wrong during
- the invisible setup phase 2.
- - To start over, rm -rf /overlay/* or reflash OpenWRT.
+ - You can disconnect the WAN connection now.
+ - To start over, rm -rf /overlay/* and reboot or reflash OpenWRT.
REFERENCES:
- The PirateBox project:
View
@@ -0,0 +1,14 @@
+Package: piratebox
+Version: 1-1
+Depends: kmod-usb2, kmod-usb-storage, kmod-fs-vfat, kmod-nls-cp437, kmod-nls-cp850, kmod-nls-iso8859-1, kmod-nls-iso8859-15, kmod-fs-ext3, kmod-loop, block-mount
+Provides:
+Source: package/piratebox
+Section: net
+Status: unknown ok not-installed
+Essential: no
+Priority: optional
+Maintainer: Christiane Ruetten <cr@23bit.net>
+Architecture: all
+Installed-Size: 32768
+Description: Turns OpenWRT into a PirateBox, see http://wiki.daviddarts.com/PirateBox
+
View
@@ -0,0 +1,74 @@
+#!/bin/ash
+
+. /etc/piratebox.conf
+
+# check if root password is not set yet
+if grep '^root:!:' /etc/passwd >/dev/null
+then
+ echo "Please set a decent root password..."
+ while ! passwd
+ do
+ echo "Try again!"
+ done
+ echo "Next time you log in, you must use ssh."
+fi
+
+# prepare usb disk for mounting
+mkdir -p "$pb_usbmount"
+id=$(uci add fstab mount)
+uci set "fstab.$id=mount"
+uci set "fstab.$id.target=$pb_usbmount"
+uci set "fstab.$id.device=$pb_usbdevice"
+uci set "fstab.$id.fstype=vfat"
+uci set "fstab.$id.options=rw,sync"
+uci set "fstab.$id.enabled=1"
+uci set "fstab.$id.enabled_fsck=0"
+
+# configure network
+uci set "system.@system[0].hostname=$pb_hostname"
+echo "127.0.0.1 $pb_hostname localhost." >/etc/hosts
+echo "$pb_ip $pb_hostname" >>/etc/hosts
+uci set "wireless.radio0.disabled=0"
+uci set "wireless.@wifi-iface[0].ssid=$pb_wireless_ssid"
+uci set "network.lan.ipaddr=$pb_ip"
+
+# redirect all 80/tcp traffic to the PirateBox
+id=$(uci add firewall redirect)
+uci set "firewall.$id=redirect"
+uci set "firewall.$id.src=lan"
+uci set "firewall.$id.proto=tcp"
+uci set "firewall.$id.src_dport=80"
+uci set "firewall.$id.dest_ip=$pb_ip"
+uci set "firewall.$id.dest_port=80"
+
+# redirect all DNS requests to PirateBox IP
+id=$(uci add dhcp domain)
+uci set "dhcp.$id=domain"
+uci set "dhcp.$id.name=#"
+uci set "dhcp.$id.ip=$pb_ip"
+
+# CAVE: ugly hack, patching a preinstalled file
+# patch dnsmasq start script to properly handle domain wildcards
+sed -i 's#^.*\${fqdn\%\.\*}\" ==.*$## ; s#^.*fqdn=\"\$fqdn.*$##' \
+ /etc/init.d/dnsmasq
+
+# commit all UCI changes
+uci commit
+
+# disable web interface, start droopy instead
+/etc/init.d/uhttpd stop
+/etc/init.d/uhttpd disable
+/etc/init.d/luci_fixtime stop
+/etc/init.d/luci_fixtime disable
+/etc/init.d/luci_dhcp_migrate stop
+/etc/init.d/luci_dhcp_migrate disable
+/etc/init.d/piratebox enable
+
+echo
+echo "PirateBox wireless SSID: $pb_wireless_ssid"
+echo "PirateBox DNS and hostname: $pb_hostname"
+echo "PirateBox IP address: $pb_ip"
+echo
+echo "Reboot the router and reconnect wirelessly."
+
+
View
@@ -0,0 +1,9 @@
+#!/bin/ash
+
+# TODO: undo UCI changes, undo dnsmasq patch
+
+/etc/init.d/luci_fixtime enable
+/etc/init.d/luci_dhcp_migrate enable
+/etc/init.d/uhttpd enable
+/etc/init.d/piratebox disable
+
@@ -0,0 +1,141 @@
+#!/bin/sh /etc/rc.common
+START=80
+
+. /etc/piratebox.conf
+
+piratebox_init() {
+
+ #CAVE: /etc/config/fstab is currently broken
+ #Workaround time
+
+ # mount USB disk
+ [ -d "$pb_usbmount" ] || mkdir -p "$pb_usbmount"
+ if ! mount "$pb_usbdevice" "$pb_usbmount"
+ then
+ echo "ERROR: piratebox: unable to mount USB storage" >&2
+ exit 5
+ fi
+
+ [ -d "$pb_usbdir" ] || mkdir -p "$pb_usbdir"
+
+ # create a swap file
+ echo "Creating swapspace..."
+ swapoff "$pb_swapimg" &>/dev/null
+ dd if=/dev/zero of="$pb_swapimg" bs=1M count=32
+ mkswap "$pb_swapimg"
+ uci set "fstab.@swap[0].device=$pb_swapimg"
+ uci set "fstab.@swap[0].enabled=1"
+
+ # create an ext3 image file
+ echo "Creating ext loop image..."
+ # use a preformatted image to get rid of e2fsprogs dependency
+ #dd if=/dev/zero of="$pb_extimg" bs=1M count=16
+ #echo y | mkfs.ext3 "$pb_extimg"
+ umount "$pb_extimg" &>/dev/null
+ gzip -dc /usr/share/piratebox/OpenWRT.img.gz >"$pb_extimg"
+ [ -d "$pb_extmount" ] || mkdir -p "$pb_extmount"
+ id=$(uci add fstab mount)
+ uci set "fstab.$id=mount"
+ uci set "fstab.$id.target=$pb_extmount"
+ uci set "fstab.$id.device=$pb_extimg"
+ uci set "fstab.$id.options=loop"
+ uci set "fstab.$id.enabled=1"
+
+ # temporarily manually mount ext fs
+ if ! mount -o loop "$pb_extimg" "$pb_extmount"
+ then
+ echo "ERROR: piratebox: unable to mount ext loop image" >&2
+ exit 5
+ fi
+
+ # prepare opkg, PATH and LD_LIBRARY_PATH for /usr/local
+ grep "^dest piratebox" /etc/opkg.conf \
+ || echo "dest piratebox $pb_extmount" >>/etc/opkg.conf
+ # CAVE: a bug during startup time prevents LD_LIBRARY_PATH
+ # and PATH from working as expected. For now, both are set
+ # directly in the init script.
+ #sed -i 's#export PATH=\(.*\)#export PATH=\1:/usr/local/bin\nexport LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib#' \
+ # /etc/profile
+ #sed -i 's#export PATH=\(.*\)#export PATH=\1:/usr/local/bin\nexport LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib#' \
+ # /etc/preinit
+
+ # fix for ext packages not installing to usr
+ [ -d "$pb_extmount/usr/lib" ] || mkdir -p "$pb_extmount/usr/lib"
+ ln -sf "$pb_extmount/usr/lib" "$pb_extmount/lib"
+
+ # temporarily disable local DNS per dnsmasq
+ cp /tmp/resolv.conf.auto /tmp/resolv.conf
+
+ # install python to piratebox storage
+ opkg update
+ opkg -d piratebox install python
+
+ # link ext /usr to local file system
+ ln -s "$pb_extmount/usr" /usr/local
+
+ # get PirateBox files
+ [ -d "$pb_share" ] || mkdir -p "$pb_share"
+ mkdir -p "$pb_share"
+ cd "$pb_share"
+ wget http://daviddarts.com/piratebox/piratebox-logo.png -O piratebox-logo.png
+ wget http://daviddarts.com/piratebox/.READ.ME.htm -O .READ.ME.htm
+ wget http://daviddarts.com/piratebox/.BACK.TO.MENU.htm -O .BACK.TO.MENU.htm
+ # adjust hostname
+ sed -i "s#://http://piratebox#http://$pb_hostname#g" .READ.ME.htm
+ sed -i "s#://http://piratebox#http://$pb_hostname#g" .BACK.TO.MENU.htm
+
+ # install PirateBox's droopy port
+ [ -d /usr/local/bin ] || mkdir -p /usr/local/bin
+ cd /usr/local/bin
+ wget http://daviddarts.com/piratebox/droopy -O droopy
+ chmod +x droopy
+
+ # commit UCI changes
+ uci commit
+
+}
+
+startsrv() {
+ # CAVE: /etc/config/fstab is currently broken
+ # Ugly workaround time
+ # CAVE: more workarounds for early start-up
+ export PATH=$PATH:/usr/local/bin
+ export LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib
+ cd "$pb_share"
+ python /usr/local/bin/droopy \
+ -p "$pb_share/piratebox-logo.png" \
+ -d "$pb_share" \
+ -m "<p><br><b>1.</b> Learn more about the project \
+ <a href="http://$pb_hostname:8001/.READ.ME.htm"><b>here</b></a>. \
+ <p><b>2.</b> Click above to begin sharing.</p> \
+ <b>3.</b> Browse and download files \
+ <a href="http://$pb_hostname:8001"><b>here</b></a>." &
+ python -m SimpleHTTPServer 8001 &
+}
+
+start() {
+ if [ ! -e "$pb_usbdevice" ]
+ then
+ echo "ERROR: piratebox requires USB storage to run" >&2
+ exit 5
+ fi
+
+ mount "$pb_device" "$pb_usbmount" &>/dev/null
+ mount -o loop "$pb_extimg" "$pb_extmount" &>/dev/null
+ swapon "$pb_swapimg" &>/dev/null
+
+ if [ "$2" == "init" ] || [ ! -d "$pb_usbdir" ]
+ then
+ piratebox_init
+ fi
+ if [ "$2" != "init" ]
+ then
+ startsrv &>/dev/null &
+ fi
+}
+
+stop() {
+ # CAVE: a bit strong
+ killall python
+}
+
@@ -0,0 +1,12 @@
+# PirateBox config.
+pb_ip="192.168.23.1"
+pb_wireless_ssid="PirateBox"
+pb_hostname="piratebox"
+pb_usbdevice="/dev/sda1"
+pb_usbmount="/mnt/usb"
+pb_usbdir="$pb_usbmount/PirateBox"
+pb_share="$pb_usbdir/Shared"
+pb_extimg="$pb_usbdir/OpenWRT.img"
+pb_extmount="/mnt/ext"
+pb_swapimg="$pb_usbdir/OpenWRT.swap"
+
Binary file not shown.
View
@@ -0,0 +1 @@
+2.0

0 comments on commit aa0405c

Please sign in to comment.