summaryrefslogtreecommitdiff
path: root/package
diff options
context:
space:
mode:
authornbd <nbd@3c298f89-4303-0410-b956-a3cf2f4a3e73>2005-07-17 22:52:59 +0000
committernbd <nbd@3c298f89-4303-0410-b956-a3cf2f4a3e73>2005-07-17 22:52:59 +0000
commit7619fe0848dc5f31d5c4c4cadd2ec067bd5c55d1 (patch)
tree2b6844c3bb5831e464ea4625441fd91543579b32 /package
parent1ab4141e381fc5672c3b9c6e54ec46d6b360be7e (diff)
move target/default/target_skeleton into package/base-files, put all the default files in ipkg packages, cleanup some junk in toolchain/, toolchain/ no longer changes build_mipsel/root
git-svn-id: svn://svn.openwrt.org/openwrt/trunk/openwrt@1494 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'package')
-rw-r--r--package/Makefile9
-rw-r--r--package/base-files/Makefile64
-rwxr-xr-xpackage/base-files/default/bin/firstboot63
-rwxr-xr-xpackage/base-files/default/bin/ipkg1188
-rwxr-xr-xpackage/base-files/default/bin/login20
-rw-r--r--package/base-files/default/etc/banner6
-rw-r--r--package/base-files/default/etc/dnsmasq.conf25
-rwxr-xr-xpackage/base-files/default/etc/firewall.user27
-rwxr-xr-xpackage/base-files/default/etc/functions.sh57
-rw-r--r--package/base-files/default/etc/group2
-rw-r--r--package/base-files/default/etc/hosts1
-rwxr-xr-xpackage/base-files/default/etc/init.d/S10boot38
-rwxr-xr-xpackage/base-files/default/etc/init.d/S40network14
-rwxr-xr-xpackage/base-files/default/etc/init.d/S45firewall92
-rwxr-xr-xpackage/base-files/default/etc/init.d/S50dnsmasq27
-rwxr-xr-xpackage/base-files/default/etc/init.d/S50httpd2
-rwxr-xr-xpackage/base-files/default/etc/init.d/S50telnet2
-rwxr-xr-xpackage/base-files/default/etc/init.d/S99done4
-rwxr-xr-xpackage/base-files/default/etc/init.d/rcS8
-rw-r--r--package/base-files/default/etc/inittab3
-rw-r--r--package/base-files/default/etc/ipkg.conf3
-rw-r--r--package/base-files/default/etc/modules2
-rw-r--r--package/base-files/default/etc/nvram.overrides96
-rw-r--r--package/base-files/default/etc/passwd2
-rwxr-xr-xpackage/base-files/default/etc/preinit17
-rw-r--r--package/base-files/default/etc/profile11
-rw-r--r--package/base-files/default/etc/protocols56
-rw-r--r--package/base-files/default/etc/shells1
-rw-r--r--package/base-files/default/etc/sysctl.conf7
-rw-r--r--package/base-files/default/rom/note3
-rwxr-xr-xpackage/base-files/default/sbin/backup32
-rwxr-xr-xpackage/base-files/default/sbin/halt3
-rwxr-xr-xpackage/base-files/default/sbin/hotplug6
-rwxr-xr-xpackage/base-files/default/sbin/ifdown9
-rwxr-xr-xpackage/base-files/default/sbin/ifup59
-rwxr-xr-xpackage/base-files/default/sbin/mount_root25
-rwxr-xr-xpackage/base-files/default/sbin/restore71
-rwxr-xr-xpackage/base-files/default/usr/share/udhcpc/default.script38
-rw-r--r--package/base-files/default/www/index.html7
39 files changed, 2098 insertions, 2 deletions
diff --git a/package/Makefile b/package/Makefile
index 1128f9c8c1..7df1c594d4 100644
--- a/package/Makefile
+++ b/package/Makefile
@@ -146,11 +146,16 @@ DEV_LIBS:=tcp_wrappers glib ncurses openssl pcre popt zlib libnet libpcap mysql
DEV_LIBS_COMPILE:=$(patsubst %,%-compile,$(DEV_LIBS))
SDK_DEFAULT_PACKAGES:=busybox dnsmasq iptables wireless-tools dropbear bridge ipkg ppp
SDK_DEFAULT_COMPILE:=$(patsubst %,%-compile,$(SDK_DEFAULT_PACKAGES))
+COMPILE_PACKAGES:=$(patsubst %,%-compile,$(package-y) $(package-m))
+INSTALL_PACKAGES:=$(patsubst %,%-install,$(package-y))
all: compile install
clean: $(patsubst %,%-clean,$(package-) $(package-y) $(package-m))
-compile: $(patsubst %,%-compile,$(package-y) $(package-m))
-install: $(patsubst %,%-install,$(package-y))
+compile: $(COMPILE_PACKAGES)
+install: base-files-install $(INSTALL_PACKAGES)
+
+$(COMPILE_PACKAGES): base-files-install
+$(INSTALL_PACKAGES): base-files-install
amwall-compile: libamsel-compile
arpwatch-compile: libpcap-compile
diff --git a/package/base-files/Makefile b/package/base-files/Makefile
new file mode 100644
index 0000000000..fbd7b9e44c
--- /dev/null
+++ b/package/base-files/Makefile
@@ -0,0 +1,64 @@
+# $Id$
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=base-files
+PKG_RELEASE:=1
+
+IDIR_BASE:=$(BUILD_DIR)/base-files
+IPKG_BASE:=$(PACKAGE_DIR)/$(PKG_NAME)_$(PKG_RELEASE)_$(ARCH).ipk
+
+LIBC_VERSION:=${shell cat $(STAGING_DIR)/uclibc_version}
+IDIR_LIBC:=$(BUILD_DIR)/uclibc
+IPKG_LIBC:=$(PACKAGE_DIR)/uclibc_$(LIBC_VERSION)-$(PKG_RELEASE)_$(ARCH).ipk
+
+GCC_VERSION:=${shell cat $(STAGING_DIR)/gcc_version}
+IDIR_GCC:=$(BUILD_DIR)/libgcc
+IPKG_GCC:=$(PACKAGE_DIR)/libgcc_$(GCC_VERSION)-$(PKG_RELEASE)_$(ARCH).ipk
+
+PACKAGES:=$(IPKG_BASE) $(IPKG_LIBC) $(IPKG_GCC)
+
+$(PACKAGE_DIR):
+ mkdir -p $(PACKAGE_DIR)
+
+$(IPKG_BASE): $(PACKAGE_DIR)
+ $(SCRIPT_DIR)/make-ipkg-dir.sh $(IDIR_BASE) ipkg/$(PKG_NAME).control $(PKG_RELEASE) $(ARCH)
+ cp -a ./default/* $(IDIR_BASE)
+ mkdir -p $(IDIR_BASE)/jffs
+ mkdir -p $(IDIR_BASE)/dev
+ mkdir -p $(IDIR_BASE)/proc
+ mkdir -p $(IDIR_BASE)/tmp
+ mkdir -p $(IDIR_BASE)/lib
+ mkdir -p $(IDIR_BASE)/usr/lib
+ mkdir -p $(IDIR_BASE)/usr/bin
+ ln -sf /tmp/resolv.conf $(IDIR_BASE)/etc/resolv.conf
+ rm -rf $(IDIR_BASE)/var
+ ln -sf /tmp $(IDIR_BASE)/var
+ -find $(IDIR_BASE) -type d -name CVS | xargs rm -rf
+ -find $(IDIR_BASE) -type d -name .svn | xargs rm -rf
+ mkdir -p $(IDIR_BASE)/etc
+ -grep \^BR2_SYSCONF $(TOPDIR)/.config > $(IDIR_BASE)/etc/sysconf
+ $(IPKG_BUILD) $(IDIR_BASE) $(PACKAGE_DIR)
+
+$(IPKG_LIBC): $(PACKAGE_DIR)
+ $(SCRIPT_DIR)/make-ipkg-dir.sh $(IDIR_LIBC) ipkg/uclibc.control $(LIBC_VERSION)-$(PKG_RELEASE) $(ARCH)
+ mkdir -p $(IDIR_LIBC)/lib
+ cp -a $(STAGING_DIR)/lib/ld-uClibc*.so* $(IDIR_LIBC)/lib/
+ for file in c crypt dl m nsl resolv rt uClibc util; do \
+ cp -a $(STAGING_DIR)/lib/lib$$file*.so* $(IDIR_LIBC)/lib/; \
+ done
+ -$(STRIP) $(IDIR_LIBC)/lib/*
+ $(IPKG_BUILD) $(IDIR_LIBC) $(PACKAGE_DIR)
+
+$(IPKG_GCC): $(PACKAGE_DIR)
+ $(SCRIPT_DIR)/make-ipkg-dir.sh $(IDIR_GCC) ipkg/libgcc.control $(GCC_VERSION)-$(PKG_RELEASE) $(ARCH)
+ mkdir -p $(IDIR_GCC)/lib
+ cp -a $(STAGING_DIR)/lib/libgcc*.so* $(IDIR_GCC)/lib/
+ -$(STRIP) $(IDIR_GCC)/lib/*
+ $(IPKG_BUILD) $(IDIR_GCC) $(PACKAGE_DIR)
+
+prepare:
+compile: $(PACKAGES)
+install: compile
+ mkdir -p $(TARGET_DIR)
+ $(IPKG) install $(PACKAGES)
diff --git a/package/base-files/default/bin/firstboot b/package/base-files/default/bin/firstboot
new file mode 100755
index 0000000000..cef258cf39
--- /dev/null
+++ b/package/base-files/default/bin/firstboot
@@ -0,0 +1,63 @@
+#!/bin/sh
+# $Id$
+
+mount | grep squashfs >&- || {
+ echo "You do not have a squashfs partition; aborting"
+ echo "(firstboot cannot be run on jffs2 based firmwares)"
+ return
+}
+
+[ -f "/tmp/.firstboot" ] && {
+ echo "firstboot is already running"
+ return
+}
+touch /tmp/.firstboot
+
+jdev=$(mount | awk '/jffs2/ {print $3}')
+
+if [ -z "$jdev" ]; then
+ echo -n "Creating jffs2 partition... "
+ mtd erase OpenWrt >&-
+ mount -t jffs2 /dev/mtdblock/4 /jffs
+ echo "done"
+ cd /jffs
+else
+ echo "firstboot has already been run"
+ echo "jffs2 partition is mounted, only resetting files"
+ cd $jdev
+fi
+
+exec 2>/dev/null
+
+mount /dev/mtdblock/2 /rom -o ro
+
+echo -n "creating directories... "
+{
+ cd /rom
+ find . -type d
+ cd -
+} | xargs mkdir
+echo "done"
+
+echo -n "setting up symlinks... "
+for file in $(cd /rom; find * -type f; find * -type l;)
+do {
+ [ "${file%/*}" = "usr/lib/ipkg/info" ] && {
+ cp -f /rom/$file $file
+ } || {
+ ln -sf /rom/$file $file
+ }
+} done
+echo "done"
+
+touch /tmp/resolv.conf
+ln -s /tmp/resolv.conf /etc/resolv.conf
+
+umount /rom
+mount none /jffs/proc -t proc
+pivot_root /jffs /jffs/rom
+mount none /dev -t devfs
+mount none /tmp -t ramfs
+umount /rom/proc
+umount /rom/tmp
+umount /rom/dev
diff --git a/package/base-files/default/bin/ipkg b/package/base-files/default/bin/ipkg
new file mode 100755
index 0000000000..dd44dd609e
--- /dev/null
+++ b/package/base-files/default/bin/ipkg
@@ -0,0 +1,1188 @@
+#!/bin/sh
+# ipkg - the itsy package management system
+#
+# Copyright (C) 2001 Carl D. Worth
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+set -e
+
+# By default do not do globbing. Any command wanting globbing should
+# explicitly enable it first and disable it afterwards.
+set -o noglob
+
+ipkg_is_upgrade () {
+ local A B a b
+ A=$(echo $1 | sed -r "s/([0-9]+)[^[:alnum:]]*/ \1 /g").
+ B=$(echo $2 | sed -r "s/([0-9]+)[^[:alnum:]]*/ \1 /g").
+ while [ \! -z "$A" ] && [ \! -z "$B" ]; do {
+ set $A; a=$1; shift; A=$*
+ set $B; b=$1; shift; B=$*
+ [ "$a" -lt "$b" ] 2>&- && return 1
+ { [ "$a" -gt "$b" ] 2>&- || [ "$a" ">" "$b" ]; } && return
+ }; done
+ return 1
+}
+
+ipkg_srcs() {
+ local srcre="$1"
+ sed -ne "s/^src[[:space:]]\+$srcre[[:space:]]\+//p" < $IPKG_CONF
+}
+
+ipkg_src_names() {
+ sed -ne "s/^src[[:space:]]\+\([^[:space:]]\+\).*/\1/p" < $IPKG_CONF
+}
+
+ipkg_src_byname() {
+ local src="$1"
+ ipkg_srcs $src | head -1
+}
+
+ipkg_dests() {
+ local destre="`echo $1 | ipkg_protect_slashes`"
+ sed -ne "/^dest[[:space:]]\+$destre/{
+s/^dest[[:space:]]\+[^[:space:]]\+[[:space:]]\+//
+s/^/`echo $IPKG_OFFLINE_ROOT | ipkg_protect_slashes`/
+p
+}" < $IPKG_CONF
+}
+
+ipkg_dest_names() {
+ sed -ne "s/^dest[[:space:]]\+\([^[:space:]]\+\).*/\1/p" < $IPKG_CONF
+}
+
+ipkg_dests_all() {
+ ipkg_dests '.*'
+}
+
+ipkg_state_dirs() {
+ ipkg_dests_all | sed "s|\$|/$IPKG_DIR_PREFIX|"
+}
+
+ipkg_dest_default() {
+ ipkg_dests_all | head -1
+}
+
+ipkg_dest_default_name() {
+ ipkg_dest_names | head -1
+}
+
+ipkg_dest_byname() {
+ local dest="$1"
+ ipkg_dests $dest | head -1
+}
+
+ipkg_option() {
+ local option="$1"
+ sed -ne "s/^option[[:space:]]\+$option[[:space:]]\+//p" < $IPKG_CONF
+}
+
+ipkg_load_configuration() {
+ if [ -z "$IPKG_CONF_DIR" ]; then
+ IPKG_CONF_DIR=/etc
+ fi
+
+ IPKG_CONF="$IPKG_CONF_DIR/ipkg.conf"
+
+ if [ -z "$IPKG_OFFLINE_ROOT" ]; then
+ IPKG_OFFLINE_ROOT="`ipkg_option offline_root`"
+ fi
+ # Export IPKG_OFFLINE_ROOT for use by update-alternatives
+ export IPKG_OFFLINE_ROOT
+ if [ -n "$DEST_NAME" ]; then
+ IPKG_ROOT="`ipkg_dest_byname $DEST_NAME`"
+ if [ -z "$IPKG_ROOT" ]; then
+ if [ -d "$IPKG_OFFLINE_ROOT$DEST_NAME" ]; then
+ IPKG_ROOT="$IPKG_OFFLINE_ROOT$DEST_NAME";
+ else
+ echo "ipkg: invalid destination specification: $DEST_NAME
+Valid destinations are directories or one of the dest names from $IPKG_CONF:" >&2
+ ipkg_dest_names >&2
+ return 1
+ fi
+ fi
+ else
+ IPKG_ROOT="`ipkg_dest_default`"
+ fi
+
+ # Global ipkg state directories
+ IPKG_DIR_PREFIX=usr/lib/ipkg
+ IPKG_LISTS_DIR=$IPKG_OFFLINE_ROOT/$IPKG_DIR_PREFIX/lists
+ IPKG_PENDING_DIR=$IPKG_OFFLINE_ROOT/$IPKG_DIR_PREFIX/pending
+ IPKG_TMP=$IPKG_ROOT/tmp/ipkg
+
+ # Destination specific ipkg meta-data directory
+ IPKG_STATE_DIR=$IPKG_ROOT/$IPKG_DIR_PREFIX
+
+ # Proxy Support
+ IPKG_PROXY_USERNAME="`ipkg_option proxy_username`"
+ IPKG_PROXY_PASSWORD="`ipkg_option proxy_password`"
+ IPKG_HTTP_PROXY="`ipkg_option http_proxy`"
+ IPKG_FTP_PROXY="`ipkg_option ftp_proxy`"
+ IPKG_NO_PROXY="`ipkg_option no_proxy`"
+ if [ -n "$IPKG_HTTP_PROXY" ]; then
+ export http_proxy="$IPKG_HTTP_PROXY"
+ fi
+
+ if [ -n "$IPKG_FTP_PROXY" ]; then
+ export ftp_proxy="$IPKG_FTP_PROXY"
+ fi
+
+ if [ -n "$IPKG_NO_PROXY" ]; then
+ export no_proxy="$IPKG_NO_PROXY"
+ fi
+
+ IPKG_STATUS_FIELDS='\(Package\|Status\|Essential\|Version\|Conffiles\|Root\)'
+}
+
+ipkg_usage() {
+ [ $# -gt 0 ] && echo "ipkg: $*"
+ echo "
+usage: ipkg [options...] sub-command [arguments...]
+where sub-command is one of:
+
+Package Manipulation:
+ update Update list of available packages
+ upgrade Upgrade all installed packages to latest version
+ install <pkg> Download and install <pkg> (and dependencies)
+ install <file.ipk> Install package <file.ipk>
+ install <file.deb> Install package <file.deb>
+ remove <pkg> Remove package <pkg>
+
+Informational Commands:
+ list List available packages and descriptions
+ files <pkg> List all files belonging to <pkg>
+ search <file> Search for a packaging providing <file>
+ info [pkg [<field>]] Display all/some info fields for <pkg> or all
+ status [pkg [<field>]] Display all/some status fields for <pkg> or all
+ depends <pkg> Print uninstalled package dependencies for <pkg>
+
+Options:
+ -d <dest_name> Use <dest_name> as the the root directory for
+ -dest <dest_name> package installation, removal, upgrading.
+ <dest_name> should be a defined dest name from the
+ configuration file, (but can also be a directory
+ name in a pinch).
+ -o <offline_root> Use <offline_root> as the root for offline installation.
+ -offline <offline_root>
+
+Force Options (use when ipkg is too smart for its own good):
+ -force-depends Make dependency checks warnings instead of errors
+ -force-defaults Use default options for questions asked by ipkg.
+ (no prompts). Note that this will not prevent
+ package installation scripts from prompting.
+" >&2
+ exit 1
+}
+
+ipkg_dir_part() {
+ local dir="`echo $1 | sed -ne 's/\(.*\/\).*/\1/p'`"
+ if [ -z "$dir" ]; then
+ dir="./"
+ fi
+ echo $dir
+}
+
+ipkg_file_part() {
+ echo $1 | sed 's/.*\///'
+}
+
+ipkg_protect_slashes() {
+ sed -e 's/\//\\\//g'
+}
+
+ipkg_download() {
+ local src="$1"
+ local dest="$2"
+
+ local src_file="`ipkg_file_part $src`"
+ local dest_dir="`ipkg_dir_part $dest`"
+ if [ -z "$dest_dir" ]; then
+ dest_dir="$IPKG_TMP"
+ fi
+
+ local dest_file="`ipkg_file_part $dest`"
+ if [ -z "$dest_file" ]; then
+ dest_file="$src_file"
+ fi
+
+ # Proxy support
+ local proxyuser=""
+ local proxypassword=""
+ local proxyoption=""
+
+ if [ -n "$IPKG_PROXY_USERNAME" ]; then
+ proxyuser="--proxy-user=\"$IPKG_PROXY_USERNAME\""
+ proxypassword="--proxy-passwd=\"$IPKG_PROXY_PASSWORD\""
+ fi
+
+ if [ -n "$IPKG_PROXY_HTTP" -o -n "$IPKG_PROXY_FTP" ]; then
+ proxyoption="--proxy=on"
+ fi
+
+ echo "Downloading $src ..."
+ rm -f $IPKG_TMP/$src_file
+ case "$src" in
+ http://* | ftp://*)
+ if ! wget --passive-ftp $proxyoption $proxyuser $proxypassword -P $IPKG_TMP $src; then
+ echo "ipkg_download: ERROR: Failed to retrieve $src, returning $err"
+ return 1
+ fi
+ mv $IPKG_TMP/$src_file $dest_dir/$dest_file 2>/dev/null
+ ;;
+ file:/* )
+ ln -s `echo $src | sed 's/^file://'` $dest_dir/$dest_file 2>/dev/null
+ ;;
+ *)
+ echo "DEBUG: $src"
+ ;;
+ esac
+
+ echo "Done."
+ return 0
+}
+
+ipkg_update() {
+ if [ ! -e "$IPKG_LISTS_DIR" ]; then
+ mkdir -p $IPKG_LISTS_DIR
+ fi
+
+ local err=
+ for src_name in `ipkg_src_names`; do
+ local src="`ipkg_src_byname $src_name`"
+ if ! ipkg_download $src/Packages $IPKG_LISTS_DIR/$src_name; then
+ echo "ipkg_update: Error downloading $src/Packages to $IPKG_LISTS_DIR/$src_name" >&2
+ err=t
+ else
+ echo "Updated list of available packages in $IPKG_LISTS_DIR/$src_name"
+ fi
+ done
+
+ [ -n "$err" ] && return 1
+
+ return 0
+}
+
+ipkg_list() {
+ for src in `ipkg_src_names`; do
+ if ipkg_require_list $src; then
+# black magic...
+sed -ne "
+/^Package:/{
+s/^Package:[[:space:]]*\<\([a-z0-9.+-]*$1[a-z0-9.+-]*\).*/\1/
+h
+}
+/^Description:/{
+s/^Description:[[:space:]]*\(.*\)/\1/
+H
+g
+s/\\
+/ - /
+p
+}
+" $IPKG_LISTS_DIR/$src
+ fi
+ done
+}
+
+ipkg_extract_paragraph() {
+ local pkg="$1"
+ sed -ne "/Package:[[:space:]]*$pkg[[:space:]]*\$/,/^\$/p"
+}
+
+ipkg_extract_field() {
+ local field="$1"
+# blacker magic...
+ sed -ne "
+: TOP
+/^$field:/{
+p
+n
+b FIELD
+}
+d
+: FIELD
+/^$/b TOP
+/^[^[:space:]]/b TOP
+p
+n
+b FIELD
+"
+}
+
+ipkg_extract_value() {
+ sed -e "s/^[^:]*:[[:space:]]*//"
+}
+
+ipkg_require_list() {
+ [ $# -lt 1 ] && return 1
+ local src="$1"
+ if [ ! -f "$IPKG_LISTS_DIR/$src" ]; then
+ echo "ERROR: File not found: $IPKG_LISTS_DIR/$src" >&2
+ echo " You probably want to run \`ipkg update'" >&2
+ return 1
+ fi
+ return 0
+}
+
+ipkg_info() {
+ for src in `ipkg_src_names`; do
+ if ipkg_require_list $src; then
+ case $# in
+ 0)
+ cat $IPKG_LISTS_DIR/$src
+ ;;
+ 1)
+ ipkg_extract_paragraph $1 < $IPKG_LISTS_DIR/$src
+ ;;
+ *)
+ ipkg_extract_paragraph $1 < $IPKG_LISTS_DIR/$src | ipkg_extract_field $2
+ ;;
+ esac
+ fi
+ done
+}
+
+ipkg_status_sd() {
+ [ $# -lt 1 ] && return 0
+ sd="$1"
+ shift
+ if [ -f $sd/status ]; then
+ case $# in
+ 0)
+ cat $sd/status
+ ;;
+ 1)
+ ipkg_extract_paragraph $1 < $sd/status
+ ;;
+ *)
+ ipkg_extract_paragraph $1 < $sd/status | ipkg_extract_field $2
+ ;;
+ esac
+ fi
+ return 0
+}
+
+ipkg_status_all() {
+ for sd in `ipkg_state_dirs`; do
+ ipkg_status_sd $sd $*
+ done
+}
+
+ipkg_status() {
+ if [ -n "$DEST_NAME" ]; then
+ ipkg_status_sd $IPKG_STATE_DIR $*
+ else
+ ipkg_status_all $*
+ fi
+}
+
+ipkg_status_matching_sd() {
+ local sd="$1"
+ local re="$2"
+ if [ -f $sd/status ]; then
+ sed -ne "
+: TOP
+/^Package:/{
+s/^Package:[[:space:]]*//
+s/[[:space:]]*$//
+h
+}
+/$re/{
+g
+p
+b NEXT
+}
+d
+: NEXT
+/^$/b TOP
+n
+b NEXT
+" < $sd/status
+ fi
+ return 0
+}
+
+ipkg_status_matching_all() {
+ for sd in `ipkg_state_dirs`; do
+ ipkg_status_matching_sd $sd $*
+ done
+}
+
+ipkg_status_matching() {
+ if [ -n "$DEST_NAME" ]; then
+ ipkg_status_matching_sd $IPKG_STATE_DIR $*
+ else
+ ipkg_status_matching_all $*
+ fi
+}
+
+ipkg_status_installed_sd() {
+ local sd="$1"
+ local pkg="$2"
+ ipkg_status_sd $sd $pkg Status | grep -q "Status: install ok installed"
+}
+
+ipkg_status_installed_all() {
+ local ret=1
+ for sd in `ipkg_state_dirs`; do
+ if `ipkg_status_installed_sd $sd $*`; then
+ ret=0
+ fi
+ done
+ return $ret
+}
+
+ipkg_status_mentioned_sd() {
+ local sd="$1"
+ local pkg="$2"
+ [ -n "`ipkg_status_sd $sd $pkg Status`" ]
+}
+
+ipkg_files() {
+ local pkg="$1"
+ if [ -n "$DEST_NAME" ]; then
+ dests=$IPKG_ROOT
+ else
+ dests="`ipkg_dests_all`"
+ fi
+ for dest in $dests; do
+ if [ -f $dest/$IPKG_DIR_PREFIX/info/$pkg.list ]; then
+ dest_sed="`echo $dest | ipkg_protect_slashes`"
+ sed -e "s/^/$dest_sed/" < $dest/$IPKG_DIR_PREFIX/info/$pkg.list
+ fi
+ done
+}
+
+ipkg_search() {
+ local pattern="$1"
+
+ for dest_name in `ipkg_dest_names`; do
+ dest="`ipkg_dest_byname $dest_name`"
+ dest_sed="`echo $dest | ipkg_protect_slashes`"
+
+ set +o noglob
+ local list_files="`ls -1 $dest/$IPKG_DIR_PREFIX/info/*.list 2>/dev/null`"
+ set -o noglob
+ for file in $list_files; do
+ if sed "s/^/$dest_sed/" $file | grep -q $pattern; then
+ local pkg="`echo $file | sed "s/^.*\/\(.*\)\.list/\1/"`"
+ [ "$dest_name" != `ipkg_dest_default_name` ] && pkg="$pkg ($dest_name)"
+ sed "s/^/$dest_sed/" $file | grep $pattern | sed "s/^/$pkg: /"
+ fi
+ done
+ done
+}
+
+ipkg_status_remove_sd() {
+ local sd="$1"
+ local pkg="$2"
+
+ if [ ! -f $sd/status ]; then
+ mkdir -p $sd
+ touch $sd/status
+ fi
+ sed -ne "/Package:[[:space:]]*$pkg[[:space:]]*\$/,/^\$/!p" < $sd/status > $sd/status.new
+ mv $sd/status.new $sd/status
+}
+
+ipkg_status_remove_all() {
+ for sd in `ipkg_state_dirs`; do
+ ipkg_status_remove_sd $sd $*
+ done
+}
+
+ipkg_status_remove() {
+ if [ -n "$DEST_NAME" ]; then
+ ipkg_status_remove_sd $IPKG_STATE_DIR $*
+ else
+ ipkg_status_remove_all $*
+ fi
+}
+
+ipkg_status_update_sd() {
+ local sd="$1"
+ local pkg="$2"
+
+ ipkg_status_remove_sd $sd $pkg
+ ipkg_extract_field "$IPKG_STATUS_FIELDS" >> $sd/status
+ echo "" >> $sd/status
+}
+
+ipkg_status_update() {
+ ipkg_status_update_sd $IPKG_STATE_DIR $*
+}
+
+ipkg_unsatisfied_dependences() {
+ local pkg=$1
+ local deps="`ipkg_get_depends $pkg`"
+ local remaining_deps=
+ for dep in $deps; do
+ local installed="`ipkg_get_installed $dep`"
+ if [ "$installed" != "installed" ] ; then
+ remaining_deps="$remaining_deps $dep"
+ fi
+ done
+ ## echo "ipkg_unsatisfied_dependences pkg=$pkg $remaining_deps" > /dev/console
+ echo $remaining_deps
+}
+
+ipkg_safe_pkg_name() {
+ local pkg=$1
+ local spkg="`echo pkg_$pkg | sed -e y/-+./___/`"
+ echo $spkg
+}
+
+ipkg_set_depends() {
+ local pkg=$1; shift
+ local new_deps="$*"
+ pkg="`ipkg_safe_pkg_name $pkg`"
+ ## setvar ${pkg}_depends "$new_deps"
+ echo $new_deps > /tmp/ipkg/${pkg}.depends
+}
+
+ipkg_get_depends() {
+ local pkg=$1
+ pkg="`ipkg_safe_pkg_name $pkg`"
+ cat /tmp/ipkg/${pkg}.depends
+ ## eval "echo \$${pkg}_depends"
+}
+
+ipkg_set_installed() {
+ local pkg=$1
+ pkg="`ipkg_safe_pkg_name $pkg`"
+ echo installed > /tmp/ipkg/${pkg}.installed
+ ## setvar ${pkg}_installed "installed"
+}
+
+ipkg_set_uninstalled() {
+ local pkg=$1
+ pkg="`ipkg_safe_pkg_name $pkg`"
+ ### echo ipkg_set_uninstalled $pkg > /dev/console
+ echo uninstalled > /tmp/ipkg/${pkg}.installed
+ ## setvar ${pkg}_installed "uninstalled"
+}
+
+ipkg_get_installed() {
+ local pkg=$1
+ pkg="`ipkg_safe_pkg_name $pkg`"
+ if [ -f /tmp/ipkg/${pkg}.installed ]; then
+ cat /tmp/ipkg/${pkg}.installed
+ fi
+ ## eval "echo \$${pkg}_installed"
+}
+
+ipkg_depends() {
+ local new_pkgs="$*"
+ local all_deps=
+ local installed_pkgs="`ipkg_status_matching_all 'Status:.*[[:space:]]installed'`"
+ for pkg in $installed_pkgs; do
+ ipkg_set_installed $pkg
+ done
+ while [ -n "$new_pkgs" ]; do
+ all_deps="$all_deps $new_pkgs"
+ local new_deps=
+ for pkg in $new_pkgs; do
+ if echo $pkg | grep -q '[^a-z0-9.+-]'; then
+ echo "ipkg_depends: ERROR: Package name $pkg contains illegal characters (should be [a-z0-9.+-])" >&2
+ return 1
+ fi
+ # TODO: Fix this. For now I am ignoring versions and alternations in dependencies.
+ new_deps="$new_deps "`ipkg_info $pkg '\(Pre-\)\?Depends' | ipkg_extract_value | sed -e 's/([^)]*)//g
+s/\(|[[:space:]]*[a-z0-9.+-]\+[[:space:]]*\)\+//g
+s/,/ /g
+s/ \+/ /g'`
+ ipkg_set_depends $pkg $new_deps
+ done
+
+ new_deps=`echo $new_deps | sed -e 's/[[:space:]]\+/\\
+/g' | sort | uniq`
+
+ local maybe_new_pkgs=
+ for pkg in $new_deps; do
+ if ! echo $installed_pkgs | grep -q "\<$pkg\>"; then
+ maybe_new_pkgs="$maybe_new_pkgs $pkg"
+ fi
+ done
+
+ new_pkgs=
+ for pkg in $maybe_new_pkgs; do
+ if ! echo $all_deps | grep -q "\<$pkg\>"; then
+ if [ -z "`ipkg_info $pkg`" ]; then
+ echo "ipkg_depends: Warning: $pkg mentioned in dependency but no package found in $IPKG_LISTS_DIR" >&2
+ ipkg_set_installed $pkg
+ else
+ new_pkgs="$new_pkgs $pkg"
+ ipkg_set_uninstalled $pkg
+ fi
+ else
+ ipkg_set_uninstalled $pkg
+ fi
+ done
+ done
+
+ echo $all_deps
+}
+
+ipkg_get_install_dest() {
+ local dest="$1"
+ shift
+ local sd=$dest/$IPKG_DIR_PREFIX
+ local info_dir=$sd/info
+
+ local requested_pkgs="$*"
+ local pkgs="`ipkg_depends $*`"
+
+ mkdir -p $info_dir
+ for pkg in $pkgs; do
+ if ! ipkg_status_mentioned_sd $sd $pkg; then
+ echo "Package: $pkg
+Status: install ok not-installed" | ipkg_status_update_sd $sd $pkg
+ fi
+ done
+ ## mark the packages that we were directly requested to install as uninstalled
+ for pkg in $requested_pkgs; do ipkg_set_uninstalled $pkg; done
+
+ local new_pkgs=
+ local pkgs_installed=0
+ while [ -n "pkgs" ]; do
+ curcheck=0
+ ## echo "pkgs to install: {$pkgs}" > /dev/console
+ for pkg in $pkgs; do
+ curcheck="`expr $curcheck + 1`"
+ local is_installed="`ipkg_get_installed $pkg`"
+ if [ "$is_installed" = "installed" ]; then
+ echo "$pkg is installed" > /dev/console
+ continue
+ fi
+
+ local remaining_deps="`ipkg_unsatisfied_dependences $pkg`"
+ if [ -n "$remaining_deps" ]; then
+ new_pkgs="$new_pkgs $pkg"
+ ### echo "Dependences not satisfied for $pkg: $remaining_deps"
+ if [ $curcheck -ne `echo $pkgs|wc -w` ]; then
+ continue
+ fi
+ fi
+
+ local filename=
+ for src in `ipkg_src_names`; do
+ if ipkg_require_list $src; then
+ filename="`ipkg_extract_paragraph $pkg < $IPKG_LISTS_DIR/$src | ipkg_extract_field Filename | ipkg_extract_value`"
+ [ -n "$filename" ] && break
+ fi
+ done
+
+ if [ -z "$filename" ]; then
+ echo "ipkg_get_install: ERROR: Cannot find package $pkg in $IPKG_LISTS_DIR"
+ echo "ipkg_get_install: Check the spelling and maybe run \`ipkg update'."
+ ipkg_status_remove_sd $sd $pkg
+ return 1;
+ fi
+
+ [ -e "$IPKG_TMP" ] || mkdir -p $IPKG_TMP
+
+ echo ""
+ local tmp_pkg_file="$IPKG_TMP/"`ipkg_file_part $filename`
+ if ! ipkg_download `ipkg_src_byname $src`/$filename $tmp_pkg_file; then
+ echo "ipkg_get_install: Perhaps you need to run \`ipkg update'?"
+ return 1
+ fi
+
+ if ! ipkg_install_file_dest $dest $tmp_pkg_file; then
+ echo "ipkg_get_install: ERROR: Failed to install $tmp_pkg_file"
+ echo "ipkg_get_install: I'll leave it there for you to try a manual installation"
+ return 1
+ fi
+
+ ipkg_set_installed $pkg
+ pkgs_installed="`expr $pkgs_installed + 1`"
+ rm $tmp_pkg_file
+ done
+ ### echo "Installed $pkgs_installed package(s) this round"
+ if [ $pkgs_installed -eq 0 ]; then
+ if [ -z "$new_pkgs" ]; then
+ break
+ fi
+ fi
+ pkgs_installed=0
+ pkgs="$new_pkgs"
+ new_pkgs=
+ curcheck=0
+ done
+}
+
+ipkg_get_install() {
+ ipkg_get_install_dest $IPKG_ROOT $*
+}
+
+ipkg_install_file_dest() {
+ local dest="$1"
+ local filename="$2"
+ local sd=$dest/$IPKG_DIR_PREFIX
+ local info_dir=$sd/info
+
+ if [ ! -f "$filename" ]; then
+ echo "ipkg_install_file: ERROR: File $filename not found"
+ return 1
+ fi
+
+ local pkg="`ipkg_file_part $filename | sed 's/\([a-z0-9.+-]\+\)_.*/\1/'`"
+ local ext="`echo $filename | sed 's/.*\.//'`"
+ local pkg_extract_stdout
+ if [ "$ext" = "ipk" ]; then
+ pkg_extract_stdout="tar -xzOf"
+ elif [ "$ext" = "deb" ]; then
+ pkg_extract_stdout="ar p"
+ else
+ echo "ipkg_install_file: ERROR: File $filename has unknown extension $ext (not .ipk or .deb)"
+ return 1
+ fi
+
+ # Check dependencies
+ local depends="`ipkg_depends $pkg | sed -e "s/\<$pkg\>//"`"
+
+ # Don't worry about deps that are scheduled for installation
+ local missing_deps=
+ for dep in $depends; do
+ if ! ipkg_status_all $dep | grep -q 'Status:[[:space:]]install'; then
+ missing_deps="$missing_deps $dep"
+ fi
+ done
+
+ if [ ! -z "$missing_deps" ]; then
+ if [ -n "$FORCE_DEPENDS" ]; then
+ echo "ipkg_install_file: Warning: $pkg depends on the following uninstalled programs: $missing_deps"
+ else
+ echo "ipkg_install_file: ERROR: $pkg depends on the following uninstalled programs:
+ $missing_deps"
+ echo "ipkg_install_file: You may want to use \`ipkg install' to install these."
+ return 1
+ fi
+ fi
+
+ mkdir -p $IPKG_TMP/$pkg/control
+ mkdir -p $IPKG_TMP/$pkg/data
+ mkdir -p $info_dir
+
+ if ! $pkg_extract_stdout $filename ./control.tar.gz | (cd $IPKG_TMP/$pkg/control; tar -xzf - ) ; then
+ echo "ipkg_install_file: ERROR unpacking control.tar.gz from $filename"
+ return 1
+ fi
+
+ if [ -n "$IPKG_OFFLINE_ROOT" ]; then
+ if grep -q '^InstallsOffline:[[:space:]]*no' $IPKG_TMP/$pkg/control/control; then
+ echo "*** Warning: Package $pkg may not be installed in offline mode"
+ echo "*** Warning: Scheduling $filename for pending installation (installing into $IPKG_PENDING_DIR)"
+ echo "Package: $pkg
+Status: install ok pending" | ipkg_status_update_sd $sd $pkg
+ mkdir -p $IPKG_PENDING_DIR
+ cp $filename $IPKG_PENDING_DIR
+ rm -r $IPKG_TMP/$pkg/control
+ rm -r $IPKG_TMP/$pkg/data
+ rmdir $IPKG_TMP/$pkg
+ return 0
+ fi
+ fi
+
+
+ echo -n "Unpacking $pkg..."
+ set +o noglob
+ for file in $IPKG_TMP/$pkg/control/*; do
+ local base_file="`ipkg_file_part $file`"
+ mv $file $info_dir/$pkg.$base_file
+ done
+ set -o noglob
+ rm -r $IPKG_TMP/$pkg/control
+
+ if ! $pkg_extract_stdout $filename ./data.tar.gz | (cd $IPKG_TMP/$pkg/data; tar -xzf - ) ; then
+ echo "ipkg_install_file: ERROR unpacking data.tar.gz from $filename"
+ return 1
+ fi
+ echo "Done."
+
+ echo -n "Configuring $pkg..."
+ export PKG_ROOT=$dest
+ if [ -x "$info_dir/$pkg.preinst" ]; then
+ if ! $info_dir/$pkg.preinst install; then
+ echo "$info_dir/$pkg.preinst failed. Aborting installation of $pkg"
+ rm -rf $IPKG_TMP/$pkg/data
+ rmdir $IPKG_TMP/$pkg
+ return 1
+ fi
+ fi
+
+ local old_conffiles="`ipkg_status_sd $sd $pkg Conffiles | ipkg_extract_value`"
+ local new_conffiles=
+ if [ -f "$info_dir/$pkg.conffiles" ]; then
+ for conffile in `cat $info_dir/$pkg.conffiles`; do
+ if [ -f "$dest/$conffile" ] && ! echo " $old_conffiles " | grep -q " $conffile "`md5sum $dest/$conffile | sed 's/ .*//'`; then
+ local use_maintainers_conffile=
+ if [ -z "$FORCE_DEFAULTS" ]; then
+ while true; do
+ echo -n "Configuration file \`$conffile'
+ ==> File on system created by you or by a script.
+ ==> File also in package provided by package maintainer.
+ What would you like to do about it ? Your options are:
+ Y or I : install the package maintainer's version
+ N or O : keep your currently-installed version
+ D : show the differences between the versions (if diff is installed)
+ The default action is to keep your current version.
+*** `ipkg_file_part $conffile` (Y/I/N/O/D) [default=N] ? "
+ read response
+ case "$response" in
+ [YyIi] | [Yy][Ee][Ss])
+ use_maintainers_conffile=t
+ break
+ ;;
+ [Dd])
+ echo "
+diff -u $dest/$conffile $IPKG_TMP/$pkg/data/$conffile"
+ diff -u $dest/$conffile $IPKG_TMP/$pkg/data/$conffile || true
+ echo "[Press ENTER to continue]"
+ read junk
+ ;;
+ *)
+ break
+ ;;
+ esac
+ done
+ fi
+ if [ -n "$use_maintainers_conffile" ]; then
+ local md5sum="`md5sum $IPKG_TMP/$pkg/data/$conffile | sed 's/ .*//'`"
+ new_conffiles="$new_conffiles $conffile $md5sum"
+ else
+ new_conffiles="$new_conffiles $conffile <custom>"
+ rm $IPKG_TMP/$pkg/data/$conffile
+ fi
+ else
+ md5sum="`md5sum $IPKG_TMP/$pkg/data/$conffile | sed 's/ .*//'`"
+ new_conffiles="$new_conffiles $conffile $md5sum"
+ fi
+ done
+ fi
+
+ local owd="`pwd`"
+ (cd $IPKG_TMP/$pkg/data/; tar cf - . | (cd $owd; cd $dest; tar xf -))
+ rm -rf $IPKG_TMP/$pkg/data
+ rmdir $IPKG_TMP/$pkg
+ rm -f $info_dir/$pkg.list
+ $pkg_extract_stdout $filename ./data.tar.gz | tar tzf - | sed -e 's/^\.//' > $info_dir/$pkg.list
+
+ if [ -x "$info_dir/$pkg.postinst" ]; then
+ $info_dir/$pkg.postinst configure
+ fi
+
+ if [ -n "$new_conffiles" ]; then
+ new_conffiles='Conffiles: '`echo $new_conffiles | ipkg_protect_slashes`
+ fi
+ local sed_safe_offline_root="`echo ${IPKG_OFFLINE_ROOT} | ipkg_protect_slashes`"
+ local sed_safe_root="`echo $dest | sed -e "s/^${sed_safe_offline_root}//" | ipkg_protect_slashes`"
+ sed -e "s/\(Package:.*\)/\1\\
+Status: install ok installed\\
+Root: ${sed_safe_root}\\
+${new_conffiles}/" $info_dir/$pkg.control | ipkg_status_update_sd $sd $pkg
+
+ rm -f $info_dir/$pkg.control
+ rm -f $info_dir/$pkg.conffiles
+ rm -f $info_dir/$pkg.preinst
+ rm -f $info_dir/$pkg.postinst
+
+ echo "Done."
+}
+
+ipkg_install_file() {
+ ipkg_install_file_dest $IPKG_ROOT $*
+}
+
+ipkg_install() {
+
+ while [ $# -gt 0 ]; do
+ local pkg="$1"
+ shift
+
+ case "$pkg" in
+ http://* | ftp://*)
+ local tmp_pkg_file="$IPKG_TMP/"`ipkg_file_part $pkg`
+ if ipkg_download $pkg $tmp_pkg_file; then
+ ipkg_install_file $tmp_pkg_file
+ rm $tmp_pkg_file
+ fi
+ ;;
+ file:/*.ipk | file://*.deb)
+ local ipkg_filename="`echo $pkg|sed 's/^file://'`"
+ ipkg_install_file $ipkg_filename
+ ;;
+ *.ipk | *.deb)
+ if [ -f "$pkg" ]; then
+ ipkg_install_file $pkg
+ else
+ echo "File not found $pkg" >&2
+ fi
+ ;;
+ *)
+ ipkg_get_install $pkg || true
+ ;;
+ esac
+ done
+}
+
+ipkg_install_pending() {
+ [ -n "$IPKG_OFFLINE_ROOT" ] && return 0
+
+ if [ -d "$IPKG_PENDING_DIR" ]; then
+ set +o noglob
+ local pending="`ls -1d $IPKG_PENDING_DIR/*.ipk 2> /dev/null`" || true
+ set -o noglob
+ if [ -n "$pending" ]; then
+ echo "The following packages in $IPKG_PENDING_DIR will now be installed:"
+ echo $pending
+ for filename in $pending; do
+ if ipkg_install_file $filename; then
+ rm $filename
+ fi
+ done
+ fi
+ fi
+ return 0
+}
+
+ipkg_install_wanted() {
+ local wanted="`ipkg_status_matching 'Status:[[:space:]]*install.*not-installed'`"
+
+ if [ -n "$wanted" ]; then
+ echo "The following package were previously requested but have not been installed:"
+ echo $wanted
+
+ if [ -n "$FORCE_DEFAULTS" ]; then
+ echo "Installing them now."
+ else
+ echo -n "Install them now [Y/n] ? "
+ read response
+ case "$response" in
+ [Nn] | [Nn][Oo])
+ return 0
+ ;;
+ esac
+ fi
+
+ ipkg_install $wanted
+ fi
+
+ return 0
+}
+
+ipkg_upgrade_pkg() {
+ local pkg="$1"
+ local avail_ver="`ipkg_info $pkg Version | ipkg_extract_value | head -1`"
+
+ is_installed=
+ for dest_name in `ipkg_dest_names`; do
+ local dest="`ipkg_dest_byname $dest_name`"
+ local sd=$dest/$IPKG_DIR_PREFIX
+ local inst_ver="`ipkg_status_sd $sd $pkg Version | ipkg_extract_value`"
+ if [ -n "$inst_ver" ]; then
+ is_installed=t
+
+ if [ -z "$avail_ver" ]; then
+ echo "Assuming locally installed package $pkg ($inst_ver) is up to date"
+ return 0
+ fi
+
+ if [ "$avail_ver" = "$inst_ver" ]; then
+ echo "Package $pkg ($inst_ver) installed in $dest_name is up to date"
+ elif ipkg_is_upgrade "$avail_ver" "$inst_ver"; then
+ echo "Upgrading $pkg ($dest_name) from $inst_ver to $avail_ver"
+ ipkg_get_install_dest $dest $pkg
+ else
+ echo "Not downgrading package $pkg from $inst_ver to $avail_ver"
+ fi
+ fi
+ done
+
+ if [ -z "$is_installed" ]; then
+ echo "Package $pkg does not appear to be installed"
+ return 0
+ fi
+
+}
+
+ipkg_upgrade() {
+ if [ $# -lt 1 ]; then
+ local pkgs="`ipkg_status_matching 'Status:.*[[:space:]]installed'`"
+ else
+ pkgs="$*"
+ fi
+
+ for pkg in $pkgs; do
+ ipkg_upgrade_pkg $pkg
+ done
+}
+
+ipkg_remove_pkg_dest() {
+ local dest="$1"
+ local pkg="$2"
+ local sd=$dest/$IPKG_DIR_PREFIX
+ local info_dir=$sd/info
+
+ if ! ipkg_status_installed_sd $sd $pkg; then
+ echo "ipkg_remove: Package $pkg does not appear to be installed in $dest"
+ if ipkg_status_mentioned_sd $sd $pkg; then
+ echo "Purging mention of $pkg from the ipkg database"
+ ipkg_status_remove_sd $sd $pkg
+ fi
+ return 1
+ fi
+
+ echo "ipkg_remove: Removing $pkg... "
+
+ local files="`cat $info_dir/$pkg.list`"
+
+ export PKG_ROOT=$dest
+ if [ -x "$info_dir/$pkg.prerm" ]; then
+ $info_dir/$pkg.prerm remove
+ fi
+
+ local conffiles="`ipkg_status_sd $sd $pkg Conffiles | ipkg_extract_value`"
+
+ local dirs_to_remove=
+ for file in $files; do
+ if [ -d "$dest/$file" ]; then
+ dirs_to_remove="$dirs_to_remove $dest/$file"
+ else
+ if echo " $conffiles " | grep -q " $file "; then
+ if echo " $conffiles " | grep -q " $file "`md5sum $dest/$file | sed 's/ .*//'`; then
+ rm -f $dest/$file
+ fi
+ else
+ rm -f $dest/$file
+ fi
+ fi
+ done
+
+ local removed_a_dir=t
+ while [ -n "$removed_a_dir" ]; do
+ removed_a_dir=
+ local new_dirs_to_remove=
+ for dir in $dirs_to_remove; do
+ if rmdir $dir >/dev/null 2>&1; then
+ removed_a_dir=t
+ else
+ new_dirs_to_remove="$new_dirs_to_remove $dir"
+ fi
+ done
+ dirs_to_remove="$new_dirs_to_remove"
+ done
+
+ if [ -n "$dirs_to_remove" ]; then
+ echo "ipkg_remove: Warning: Not removing the following directories since they are not empty:" >&2
+ echo "$dirs_to_remove" | sed -e 's/\/[/]\+/\//g' >&2
+ fi
+
+ if [ -x "$info_dir/$pkg.postrm" ]; then
+ $info_dir/$pkg.postrm remove
+ fi
+
+ ipkg_status_remove_sd $sd $pkg
+ set +o noglob
+ rm -f $info_dir/$pkg.*
+ set -o noglob
+
+ echo "Done."
+}
+
+ipkg_remove_pkg() {
+ local pkg="$1"
+ for dest in `ipkg_dests_all`; do
+ local sd=$dest/$IPKG_DIR_PREFIX
+ if ipkg_status_mentioned_sd $sd $pkg; then
+ ipkg_remove_pkg_dest $dest $pkg
+ fi
+ done
+}
+
+ipkg_remove() {
+ while [ $# -gt 0 ]; do
+ local pkg="$1"
+ shift
+ if [ -n "$DEST_NAME" ]; then
+ ipkg_remove_pkg_dest $IPKG_ROOT $pkg
+ else
+ ipkg_remove_pkg $pkg
+ fi
+ done
+}
+
+###########
+# ipkg main
+###########
+
+# Parse options
+while [ $# -gt 0 ]; do
+ arg="$1"
+ case $arg in
+ -d | -dest)
+ [ $# -gt 1 ] || ipkg_usage "option $arg requires an argument"
+ DEST_NAME="$2"
+ shift
+ ;;
+ -o | -offline)
+ [ $# -gt 1 ] || ipkg_usage "option $arg requires an argument"
+ IPKG_OFFLINE_ROOT="$2"
+ shift
+ ;;
+ -force-depends)
+ FORCE_DEPENDS=t
+ ;;
+ -force-defaults)
+ FORCE_DEFAULTS=t
+ ;;
+ -*)
+ ipkg_usage "unknown option $arg"
+ ;;
+ *)
+ break
+ ;;
+ esac
+ shift
+done
+
+[ $# -lt 1 ] && ipkg_usage "ipkg must have one sub-command argument"
+cmd="$1"
+shift
+
+ipkg_load_configuration
+mkdir -p /tmp/ipkg
+
+case "$cmd" in
+update|upgrade|list|info|status|install_pending)
+ ;;
+install|depends|remove|files|search)
+ [ $# -lt 1 ] && ipkg_usage "ERROR: the \`\`$cmd'' command requires an argument"
+ ;;
+*)
+ echo "ERROR: unknown sub-command \`$cmd'"
+ ipkg_usage
+ ;;
+esac
+
+# Only install pending if we have an interactive sub-command
+case "$cmd" in
+upgrade|install)
+ ipkg_install_pending
+ ipkg_install_wanted
+ ;;
+esac
+
+ipkg_$cmd $*
+for a in `ls $IPKG_TMP`; do
+ rm -rf $IPKG_TMP/$a
+done
diff --git a/package/base-files/default/bin/login b/package/base-files/default/bin/login
new file mode 100755
index 0000000000..bb065e54a1
--- /dev/null
+++ b/package/base-files/default/bin/login
@@ -0,0 +1,20 @@
+#!/bin/sh
+. /etc/sysconf 2>&-
+
+[ "$FAILSAFE" != "true" ] &&
+[ "$BR2_SYSCONF_TELNET_FAILSAFE_ONLY" = "y" ] &&
+{
+ grep '^root:[^!]' /etc/passwd >&- 2>&- &&
+ {
+ echo "Login failed."
+ exit 0
+ } || {
+cat << EOF
+ === IMPORTANT ============================
+ Use 'passwd' to set your login password
+ this will disable telnet and enable SSH
+ ------------------------------------------
+EOF
+ }
+}
+exec /bin/ash --login
diff --git a/package/base-files/default/etc/banner b/package/base-files/default/etc/banner
new file mode 100644
index 0000000000..2b2b2c015b
--- /dev/null
+++ b/package/base-files/default/etc/banner
@@ -0,0 +1,6 @@
+ _______ ________ __
+ | |.-----.-----.-----.| | | |.----.| |_
+ | - || _ | -__| || | | || _|| _|
+ |_______|| __|_____|__|__||________||__| |____|
+ |__| W I R E L E S S F R E E D O M
+
diff --git a/package/base-files/default/etc/dnsmasq.conf b/package/base-files/default/etc/dnsmasq.conf
new file mode 100644
index 0000000000..4ef96803a6
--- /dev/null
+++ b/package/base-files/default/etc/dnsmasq.conf
@@ -0,0 +1,25 @@
+# filter what we send upstream
+domain-needed
+bogus-priv
+filterwin2k
+localise-queries
+
+# allow /etc/hosts and dhcp lookups via *.lan
+local=/lan/
+domain=lan
+
+# no dhcp / dns queries from the wan
+except-interface=vlan1
+
+# enable dhcp (start,end,netmask,leasetime)
+dhcp-authoritative
+#dhcp-range=192.168.1.100,192.168.1.250,255.255.255.0,12h
+#dhcp-leasefile=/tmp/dhcp.leases
+
+# use /etc/ethers for static hosts; same format as --dhcp-host
+# <hwaddr> [<hostname>] <ipaddr>
+read-ethers
+
+# other useful options:
+# default route(s): dhcp-option=3,192.168.1.1,192.168.1.2
+# dns server(s): dhcp-option=6,192.168.1.1,192.168.1.2
diff --git a/package/base-files/default/etc/firewall.user b/package/base-files/default/etc/firewall.user
new file mode 100755
index 0000000000..1781bd4ea0
--- /dev/null
+++ b/package/base-files/default/etc/firewall.user
@@ -0,0 +1,27 @@
+#!/bin/sh
+. /etc/functions.sh
+
+WAN=$(nvram get wan_ifname)
+LAN=$(nvram get lan_ifname)
+
+iptables -F input_rule
+iptables -F output_rule
+iptables -F forwarding_rule
+iptables -t nat -F prerouting_rule
+iptables -t nat -F postrouting_rule
+
+### BIG FAT DISCLAIMER
+### The "-i $WAN" literally means packets that came in over the $WAN interface;
+### this WILL NOT MATCH packets sent from the LAN to the WAN address.
+
+### Allow SSH from WAN
+# iptables -t nat -A prerouting_rule -i $WAN -p tcp --dport 22 -j ACCEPT
+# iptables -A input_rule -i $WAN -p tcp --dport 22 -j ACCEPT
+
+### Port forwarding
+# iptables -t nat -A prerouting_rule -i $WAN -p tcp --dport 22 -j DNAT --to 192.168.1.2
+# iptables -A forwarding_rule -i $WAN -p tcp --dport 22 -d 192.168.1.2 -j ACCEPT
+
+### DMZ (should be placed after port forwarding / accept rules)
+# iptables -t nat -A prerouting_rule -i $WAN -j DNAT --to 192.168.1.2
+# iptables -A forwarding_rule -i $WAN -d 192.168.1.2 -j ACCEPT
diff --git a/package/base-files/default/etc/functions.sh b/package/base-files/default/etc/functions.sh
new file mode 100755
index 0000000000..60d6231f8a
--- /dev/null
+++ b/package/base-files/default/etc/functions.sh
@@ -0,0 +1,57 @@
+#!/bin/ash
+
+alias debug=${DEBUG:-:}
+
+# allow env to override nvram
+nvram () {
+ case $1 in
+ get) eval "echo \${NVRAM_$2:-\$(command nvram get $2)}";;
+ *) command nvram $*;;
+ esac
+}
+. /etc/nvram.overrides
+
+# valid interface?
+if_valid () (
+ ifconfig "$1" >&- 2>&- ||
+ [ "${1%%[0-9]}" = "br" ] ||
+ {
+ [ "${1%%[0-9]}" = "vlan" ] && (
+ i=${1#vlan}
+ hwname=$(nvram get vlan${i}hwname)
+ hwaddr=$(nvram get ${hwname}macaddr)
+ [ -z "$hwaddr" ] && return 1
+
+ vif=$(ifconfig -a | awk '/^eth.*'$hwaddr'/ {print $1; exit}' IGNORECASE=1)
+ debug "# vlan$i => $vif"
+
+ $DEBUG ifconfig $vif up
+ $DEBUG vconfig add $vif $i 2>&-
+ )
+ } ||
+ { debug "# missing interface '$1' ignored"; false; }
+)
+
+bitcount () {
+ local c=$1
+ echo $((
+ c=((c>> 1)&0x55555555)+(c&0x55555555),
+ c=((c>> 2)&0x33333333)+(c&0x33333333),
+ c=((c>> 4)&0x0f0f0f0f)+(c&0x0f0f0f0f),
+ c=((c>> 8)&0x00ff00ff)+(c&0x00ff00ff),
+ c=((c>>16)&0x0000ffff)+(c&0x0000ffff)
+ ))
+}
+
+valid_netmask () {
+ return $((-($1)&~$1))
+}
+
+ip2int () (
+ set $(echo $1 | tr '\.' ' ')
+ echo $(($1<<24|$2<<16|$3<<8|$4))
+)
+
+int2ip () {
+ echo $(($1>>24&255)).$(($1>>16&255)).$(($1>>8&255)).$(($1&255))
+}
diff --git a/package/base-files/default/etc/group b/package/base-files/default/etc/group
new file mode 100644
index 0000000000..c4e77f316a
--- /dev/null
+++ b/package/base-files/default/etc/group
@@ -0,0 +1,2 @@
+root:x:0:
+nogroup:x:65534:
diff --git a/package/base-files/default/etc/hosts b/package/base-files/default/etc/hosts
new file mode 100644
index 0000000000..ce138ec1e6
--- /dev/null
+++ b/package/base-files/default/etc/hosts
@@ -0,0 +1 @@
+127.0.0.1 localhost OpenWrt
diff --git a/package/base-files/default/etc/init.d/S10boot b/package/base-files/default/etc/init.d/S10boot
new file mode 100755
index 0000000000..22096d5fbb
--- /dev/null
+++ b/package/base-files/default/etc/init.d/S10boot
@@ -0,0 +1,38 @@
+#!/bin/sh
+echo "S" > /proc/jffs2_bbc
+
+mkdir -p /var/run
+mkdir -p /var/log
+touch /var/log/wtmp
+touch /var/log/lastlog
+
+[ "$(nvram get il0macaddr)" = "00:90:4c:5f:00:2a" ] && {
+ # if default wifi mac, set two higher than the lan mac
+ nvram set il0macaddr=$(nvram get et0macaddr|
+ awk '{OFS=FS=":";for(x=7,y=2;--x;){$x=sprintf("%02x",(y+="0x"$x)%256);y/=256}print}')
+}
+
+# set up the vlan*ports variables for the asus wl-500g deluxe
+# if they don't already exist
+[ "$(nvram get boardtype)" = "bcm95365r" \
+-a "$(nvram get boardnum)" = "45" \
+-a -z "$(nvram get vlan0ports)$(nvram get vlan1ports)" ] && {
+ nvram set vlan0ports="1 2 3 4 5*"
+ nvram set vlan1ports="0 5"
+}
+
+sed 's/^[^#]/insmod &/' /etc/modules /etc/modules.d/* 2>&-|ash
+
+ifconfig lo 127.0.0.1 up
+ifconfig eth0 promisc
+
+HOSTNAME=$(nvram get wan_hostname)
+HOSTNAME=${HOSTNAME%%.*}
+echo ${HOSTNAME:=OpenWrt}>/proc/sys/kernel/hostname
+
+vconfig set_name_type VLAN_PLUS_VID_NO_PAD
+
+# automagically run firstboot
+[ -z "$FAILSAFE" ] && {
+ { mount|grep "on / type jffs2" 1>&-; } || firstboot
+}
diff --git a/package/base-files/default/etc/init.d/S40network b/package/base-files/default/etc/init.d/S40network
new file mode 100755
index 0000000000..d8b4e4125e
--- /dev/null
+++ b/package/base-files/default/etc/init.d/S40network
@@ -0,0 +1,14 @@
+#!/bin/sh
+case "$1" in
+ start|restart)
+ ifup lan
+ ifup wan
+ ifup wifi
+ wifi up
+
+ for route in $(nvram get static_route); do {
+ eval "set $(echo $route | sed 's/:/ /g')"
+ $DEBUG route add -net $1 netmask $2 gw $3 metric $4 dev $5
+ } done
+ ;;
+esac
diff --git a/package/base-files/default/etc/init.d/S45firewall b/package/base-files/default/etc/init.d/S45firewall
new file mode 100755
index 0000000000..8350ccbfef
--- /dev/null
+++ b/package/base-files/default/etc/init.d/S45firewall
@@ -0,0 +1,92 @@
+#!/bin/sh
+
+## Please make changes in /etc/firewall.user
+
+. /etc/functions.sh
+WAN=$(nvram get wan_ifname)
+LAN=$(nvram get lan_ifname)
+
+## CLEAR TABLES
+for T in filter nat mangle; do
+ iptables -t $T -F
+ iptables -t $T -X
+done
+
+iptables -N input_rule
+iptables -N output_rule
+iptables -N forwarding_rule
+
+iptables -t nat -N prerouting_rule
+iptables -t nat -N postrouting_rule
+
+### INPUT
+### (connections with the router as destination)
+
+ # base case
+ iptables -P INPUT DROP
+ iptables -A INPUT -m state --state INVALID -j DROP
+ iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
+ iptables -A INPUT -p tcp --tcp-flags SYN SYN --tcp-option \! 2 -j DROP
+
+ #
+ # insert accept rule or to jump to new accept-check table here
+ #
+ iptables -A INPUT -j input_rule
+
+ # allow
+ iptables -A INPUT -i \! $WAN -j ACCEPT # allow from lan/wifi interfaces
+ iptables -A INPUT -p icmp -j ACCEPT # allow ICMP
+ iptables -A INPUT -p gre -j ACCEPT # allow GRE
+
+ # reject (what to do with anything not allowed earlier)
+ iptables -A INPUT -p tcp -j REJECT --reject-with tcp-reset
+ iptables -A INPUT -j REJECT --reject-with icmp-port-unreachable
+
+### OUTPUT
+### (connections with the router as source)
+
+ # base case
+ iptables -P OUTPUT DROP
+ iptables -A OUTPUT -m state --state INVALID -j DROP
+ iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
+
+ #
+ # insert accept rule or to jump to new accept-check table here
+ #
+ iptables -A OUTPUT -j output_rule
+
+ # allow
+ iptables -A OUTPUT -j ACCEPT #allow everything out
+
+ # reject (what to do with anything not allowed earlier)
+ iptables -A OUTPUT -p tcp -j REJECT --reject-with tcp-reset
+ iptables -A OUTPUT -j REJECT --reject-with icmp-port-unreachable
+
+### FORWARDING
+### (connections routed through the router)
+
+ # base case
+ iptables -P FORWARD DROP
+ iptables -A FORWARD -m state --state INVALID -j DROP
+ iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
+ iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
+
+ #
+ # insert accept rule or to jump to new accept-check table here
+ #
+ iptables -A FORWARD -j forwarding_rule
+
+ # allow
+ iptables -A FORWARD -i br0 -o br0 -j ACCEPT
+ iptables -A FORWARD -i $LAN -o $WAN -j ACCEPT
+
+ # reject (what to do with anything not allowed earlier)
+ # uses the default -P DROP
+
+### MASQ
+ iptables -t nat -A PREROUTING -j prerouting_rule
+ iptables -t nat -A POSTROUTING -j postrouting_rule
+ iptables -t nat -A POSTROUTING -o $WAN -j MASQUERADE
+
+## USER RULES
+[ -f /etc/firewall.user ] && . /etc/firewall.user
diff --git a/package/base-files/default/etc/init.d/S50dnsmasq b/package/base-files/default/etc/init.d/S50dnsmasq
new file mode 100755
index 0000000000..6a5af0f05f
--- /dev/null
+++ b/package/base-files/default/etc/init.d/S50dnsmasq
@@ -0,0 +1,27 @@
+#!/bin/sh
+. /etc/functions.sh
+
+# interface to use for DHCP
+iface=lan
+
+ifname=$(nvram get ${iface}_ifname)
+ipaddr=$(nvram get ${iface}_ipaddr)
+netmask=$(nvram get ${iface}_netmask)
+
+(
+ # check for existing DHCP server
+ udhcpc -n -q -R -s /dev/zero -i $ifname >&- || {
+
+ ipaddr=$(ip2int $ipaddr)
+ netmask=$(ip2int ${netmask:-255.255.255.0})
+ network=$((ipaddr&netmask))
+
+ start=$(nvram get dhcp_start)
+ start=$((network+${start:-100}))
+ end=$(nvram get dhcp_num)
+ end=$((start+${end:-150}))
+
+ args="-l /tmp/dhcp.leases -K -F $(int2ip $start),$(int2ip $end),$(int2ip $netmask),12h"
+ }
+ dnsmasq ${args}
+) &
diff --git a/package/base-files/default/etc/init.d/S50httpd b/package/base-files/default/etc/init.d/S50httpd
new file mode 100755
index 0000000000..9cf551e5c6
--- /dev/null
+++ b/package/base-files/default/etc/init.d/S50httpd
@@ -0,0 +1,2 @@
+#!/bin/sh
+httpd -p 80 -h /www -r WRT54G Router
diff --git a/package/base-files/default/etc/init.d/S50telnet b/package/base-files/default/etc/init.d/S50telnet
new file mode 100755
index 0000000000..599c3540eb
--- /dev/null
+++ b/package/base-files/default/etc/init.d/S50telnet
@@ -0,0 +1,2 @@
+#!/bin/sh
+telnetd -l /bin/login
diff --git a/package/base-files/default/etc/init.d/S99done b/package/base-files/default/etc/init.d/S99done
new file mode 100755
index 0000000000..ce60337212
--- /dev/null
+++ b/package/base-files/default/etc/init.d/S99done
@@ -0,0 +1,4 @@
+#!/bin/sh
+# set leds to normal state
+echo "0x00" > /proc/sys/diag
+sysctl -p >&-
diff --git a/package/base-files/default/etc/init.d/rcS b/package/base-files/default/etc/init.d/rcS
new file mode 100755
index 0000000000..e6daddc593
--- /dev/null
+++ b/package/base-files/default/etc/init.d/rcS
@@ -0,0 +1,8 @@
+#!/bin/sh
+syslogd -C 16
+klogd
+${FAILSAFE:+telnetd -l /bin/login; ifup lan; exit}
+
+for i in /etc/init.d/S*; do
+ $i start 2>&1
+done | logger -s -p 6 -t '' &
diff --git a/package/base-files/default/etc/inittab b/package/base-files/default/etc/inittab
new file mode 100644
index 0000000000..aab2df9562
--- /dev/null
+++ b/package/base-files/default/etc/inittab
@@ -0,0 +1,3 @@
+::sysinit:/etc/init.d/rcS
+::shutdown:/sbin/halt
+tts/0::askfirst:/bin/ash --login
diff --git a/package/base-files/default/etc/ipkg.conf b/package/base-files/default/etc/ipkg.conf
new file mode 100644
index 0000000000..3867213313
--- /dev/null
+++ b/package/base-files/default/etc/ipkg.conf
@@ -0,0 +1,3 @@
+src experimental http://openwrt.org/downloads/experimental/bin/packages
+dest root /
+dest ram /tmp
diff --git a/package/base-files/default/etc/modules b/package/base-files/default/etc/modules
new file mode 100644
index 0000000000..e717eae577
--- /dev/null
+++ b/package/base-files/default/etc/modules
@@ -0,0 +1,2 @@
+et
+wl
diff --git a/package/base-files/default/etc/nvram.overrides b/package/base-files/default/etc/nvram.overrides
new file mode 100644
index 0000000000..d457af48ee
--- /dev/null
+++ b/package/base-files/default/etc/nvram.overrides
@@ -0,0 +1,96 @@
+# NVRAM overrides
+#
+# This file handles the NVRAM quirks of various hardware.
+# THIS FILE IS NOT A REPLACEMENT FOR NVRAM
+
+# Load sysconf defaults
+[ -f /etc/sysconf ] && . /etc/sysconf
+
+# linksys bug; remove when not using static configuration for lan
+NVRAM_lan_proto="static"
+
+remap () {
+ for type in lan wifi wan pppoe
+ do
+ for s in '' s
+ do
+ eval NVRAM_${type}_ifname$s=\"$(nvram get ${type}_ifname$s|sed s/$1/$2/g)\"
+ done
+ done
+}
+
+# hacks for wrt54g 1.x hardware
+[ "$(nvram get boardnum)" = "42" \
+-a "$(nvram get boardtype)" = "bcm94710dev" ] && {
+ debug "### wrt54g 1.x hack ###"
+ NVRAM_vlan1hwname="et0"
+ NVRAM_vlan2hwname="et0"
+ FAILSAFE_ifnames="vlan1 vlan2 eth2"
+ remap eth0 vlan2
+ remap eth1 vlan1
+}
+
+# hacks for asus wl-500g deluxe
+[ "$(nvram get boardtype)" = "bcm95365r" \
+-a "$(nvram get boardnum)" = "45" ] && {
+ debug "### wl-500g deluxe hacks ###"
+ NVRAM_vlan0hwname="et0"
+ NVRAM_vlan1hwname="et0"
+ FAILSAFE_ifnames="vlan0 eth1"
+ remap eth0.1 vlan0
+ remap eth0 vlan1
+}
+
+# hacks for asus wl-300g
+[ "$(nvram get productid)" = "WL300g" ] && {
+ debug "### wl-300g hacks ###"
+ NVRAM_lan_ifnames="eth0 eth2"
+ NVRAM_wan_ifname="none"
+}
+
+# hacks for wap54g hardware
+[ "$(nvram get boardnum)" = "2" \
+-o "$(nvram get boardnum)" = "1024" ] && {
+ debug "### wap54g hack ###"
+ NVRAM_wan_ifname="none"
+ FAILSAFE_ifnames="eth0 eth1"
+}
+
+# hacks for buffalo wla2-g54l
+[ "$(nvram get boardnum)" = "00" \
+-a "$(nvram get product_name)" = "Product_name" \
+-o "$(nvram get product_name)" = "WLA2-G54L" ] && {
+ debug "### wla2-g54l hacks ###"
+ NVRAM_wan_ifname="none"
+ NVRAM_lan_ifnames="vlan0"
+}
+
+# hack for asus wl-500g hardware
+[ "$(nvram get boardnum)" = "asusX" \
+-a "$(nvram get boardtype)" = "bcm94710dev" ] && {
+ FAILSAFE_ifnames="eth0 eth2"
+}
+
+# defaults if lan_ifname is missing
+[ -z "$(nvram get lan_ifname)" ] && {
+ NVRAM_lan_ifname="br0"
+ NVRAM_lan_ifnames=${FAILSAFE_ifnames:-"vlan0 vlan2 eth1 eth2 eth3"}
+}
+
+# defaults if wan_ifname is missing
+[ -z "$(nvram get wan_ifname)" ] && {
+ NVRAM_wan_ifname="vlan1"
+ NVRAM_wan_proto="dhcp"
+}
+
+# failsafe if reset is held
+[ "$FAILSAFE" = "true" ] && {
+ echo "### YOU ARE IN FAILSAFE MODE ####"
+ NVRAM_lan_ifname="br0"
+ NVRAM_lan_ifnames=${FAILSAFE_ifnames:-"vlan0 vlan1 eth1 eth2 eth3"}
+ NVRAM_lan_ipaddr=${BR2_SYSCONF_FAILSAFE_IP:-"192.168.1.1"}
+ NVRAM_lan_netmask=${BR2_SYSCONF_FAILSAFE_NETMASK:-"255.255.255.0"}
+ NVRAM_lan_hwaddr=${BR2_SYSCONF_FAILSAFE_MAC:-"00:0B:AD:0A:DD:00"}
+ NVRAM_wan_ifname="none"
+ NVRAM_wifi_ifname="none"
+}
diff --git a/package/base-files/default/etc/passwd b/package/base-files/default/etc/passwd
new file mode 100644
index 0000000000..3b660a0d4e
--- /dev/null
+++ b/package/base-files/default/etc/passwd
@@ -0,0 +1,2 @@
+root:!:0:0:root:/tmp:/bin/ash
+nobody:*:65534:65534:nobody:/var:/bin/false
diff --git a/package/base-files/default/etc/preinit b/package/base-files/default/etc/preinit
new file mode 100755
index 0000000000..0c59893f75
--- /dev/null
+++ b/package/base-files/default/etc/preinit
@@ -0,0 +1,17 @@
+#!/bin/sh
+mount none /proc -t proc
+insmod diag
+echo 0x01 > /proc/sys/diag
+sleep 1
+if [ $(cat /proc/sys/reset) = 1 ] || [ "$(/usr/sbin/nvram get failsafe)" = 1 ]; then
+ export FAILSAFE=true
+ [ "$(/usr/sbin/nvram get boot_wait)" != "on" ] && {
+ /usr/sbin/nvram set boot_wait=on
+ /usr/sbin/nvram commit
+ }
+ while :; do { echo $(((X=(X+1)%8)%2)) > /proc/sys/diag; sleep $((X==0)); } done &
+fi
+
+/sbin/mount_root ${FAILSAFE:+failsafe}
+
+exec /sbin/init
diff --git a/package/base-files/default/etc/profile b/package/base-files/default/etc/profile
new file mode 100644
index 0000000000..1d98ae3402
--- /dev/null
+++ b/package/base-files/default/etc/profile
@@ -0,0 +1,11 @@
+#!/bin/sh
+[ -f /etc/banner ] && cat /etc/banner
+
+export PATH=/bin:/sbin:/usr/bin:/usr/sbin
+export PS1='\u@\h:\w\$ '
+
+[ -x /usr/bin/less ] || alias less=more
+alias vim=vi
+
+arp() { cat /proc/net/arp; }
+ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; }
diff --git a/package/base-files/default/etc/protocols b/package/base-files/default/etc/protocols
new file mode 100644
index 0000000000..53fecb6d3c
--- /dev/null
+++ b/package/base-files/default/etc/protocols
@@ -0,0 +1,56 @@
+# Internet (IP) protocols
+#
+# Updated from http://www.iana.org/assignments/protocol-numbers and other
+# sources.
+# New protocols will be added on request if they have been officially
+# assigned by IANA and are not historical.
+# If you need a huge list of used numbers please install the nmap package.
+
+ip 0 IP # internet protocol, pseudo protocol number
+#hopopt 0 HOPOPT # IPv6 Hop-by-Hop Option [RFC1883]
+icmp 1 ICMP # internet control message protocol
+igmp 2 IGMP # Internet Group Management
+ggp 3 GGP # gateway-gateway protocol
+ipencap 4 IP-ENCAP # IP encapsulated in IP (officially ``IP'')
+st 5 ST # ST datagram mode
+tcp 6 TCP # transmission control protocol
+egp 8 EGP # exterior gateway protocol
+igp 9 IGP # any private interior gateway (Cisco)
+pup 12 PUP # PARC universal packet protocol
+udp 17 UDP # user datagram protocol
+hmp 20 HMP # host monitoring protocol
+xns-idp 22 XNS-IDP # Xerox NS IDP
+rdp 27 RDP # "reliable datagram" protocol
+iso-tp4 29 ISO-TP4 # ISO Transport Protocol class 4 [RFC905]
+xtp 36 XTP # Xpress Transfer Protocol
+ddp 37 DDP # Datagram Delivery Protocol
+idpr-cmtp 38 IDPR-CMTP # IDPR Control Message Transport
+ipv6 41 IPv6 # Internet Protocol, version 6
+ipv6-route 43 IPv6-Route # Routing Header for IPv6
+ipv6-frag 44 IPv6-Frag # Fragment Header for IPv6
+idrp 45 IDRP # Inter-Domain Routing Protocol
+rsvp 46 RSVP # Reservation Protocol
+gre 47 GRE # General Routing Encapsulation
+esp 50 IPSEC-ESP # Encap Security Payload [RFC2046]
+ah 51 IPSEC-AH # Authentication Header [RFC2402]
+skip 57 SKIP # SKIP
+ipv6-icmp 58 IPv6-ICMP # ICMP for IPv6
+ipv6-nonxt 59 IPv6-NoNxt # No Next Header for IPv6
+ipv6-opts 60 IPv6-Opts # Destination Options for IPv6
+rspf 73 RSPF CPHB # Radio Shortest Path First (officially CPHB)
+vmtp 81 VMTP # Versatile Message Transport
+eigrp 88 EIGRP # Enhanced Interior Routing Protocol (Cisco)
+ospf 89 OSPFIGP # Open Shortest Path First IGP
+ax.25 93 AX.25 # AX.25 frames
+ipip 94 IPIP # IP-within-IP Encapsulation Protocol
+etherip 97 ETHERIP # Ethernet-within-IP Encapsulation [RFC3378]
+encap 98 ENCAP # Yet Another IP encapsulation [RFC1241]
+# 99 # any private encryption scheme
+pim 103 PIM # Protocol Independent Multicast
+ipcomp 108 IPCOMP # IP Payload Compression Protocol
+vrrp 112 VRRP # Virtual Router Redundancy Protocol
+l2tp 115 L2TP # Layer Two Tunneling Protocol [RFC2661]
+isis 124 ISIS # IS-IS over IPv4
+sctp 132 SCTP # Stream Control Transmission Protocol
+fc 133 FC # Fibre Channel
+
diff --git a/package/base-files/default/etc/shells b/package/base-files/default/etc/shells
new file mode 100644
index 0000000000..006aa38ced
--- /dev/null
+++ b/package/base-files/default/etc/shells
@@ -0,0 +1 @@
+/bin/ash
diff --git a/package/base-files/default/etc/sysctl.conf b/package/base-files/default/etc/sysctl.conf
new file mode 100644
index 0000000000..2050b0c886
--- /dev/null
+++ b/package/base-files/default/etc/sysctl.conf
@@ -0,0 +1,7 @@
+kernel.panic=3
+net.ipv4.ip_forward=1
+net.ipv4.icmp_echo_ignore_broadcasts=1
+net.ipv4.icmp_ignore_bogus_error_responses=1
+net.ipv4.tcp_fin_timeout=30
+net.ipv4.tcp_keepalive_time=120
+net.ipv4.tcp_timestamps=0
diff --git a/package/base-files/default/rom/note b/package/base-files/default/rom/note
new file mode 100644
index 0000000000..1746eb0509
--- /dev/null
+++ b/package/base-files/default/rom/note
@@ -0,0 +1,3 @@
+SQUASHFS USERS:
+After firstboot has been run, / will be jffs2 and /rom will be squashfs
+(* except when in failsafe)
diff --git a/package/base-files/default/sbin/backup b/package/base-files/default/sbin/backup
new file mode 100755
index 0000000000..33bad53501
--- /dev/null
+++ b/package/base-files/default/sbin/backup
@@ -0,0 +1,32 @@
+#!/bin/sh
+for param in $*; do
+ case "$param" in
+ *)
+ OUTPUT_FILE="$param"
+ ;;
+ esac
+done
+
+if [ "$OUTPUT_FILE" = "-" ]; then
+ echo "Writing backup to stdout.." >&2
+elif [ "$OUTPUT_FILE" = "" ]; then
+ echo "No output file."
+ exit 1
+else
+ echo "Writing backup to $OUTPUT_FILE" >&2
+ exec > "$OUTPUT_FILE"
+fi
+
+echo __FILELIST__
+find /etc -type f > /tmp/.wlbackup_files
+cat /tmp/.wlbackup_files
+
+echo __IPKG__
+cat /etc/ipkg.conf
+
+echo __PACKAGES__
+grep '^Package:' /usr/lib/ipkg/status | cut -d' ' -f2
+
+echo __FILES__
+tar -T /tmp/.wlbackup_files -cz 2>/dev/null
+rm -f /tmp/.wlbackup_files
diff --git a/package/base-files/default/sbin/halt b/package/base-files/default/sbin/halt
new file mode 100755
index 0000000000..39eed2612e
--- /dev/null
+++ b/package/base-files/default/sbin/halt
@@ -0,0 +1,3 @@
+#!/bin/sh
+/usr/bin/killall5 -9
+#umount -ar
diff --git a/package/base-files/default/sbin/hotplug b/package/base-files/default/sbin/hotplug
new file mode 100755
index 0000000000..74134e848a
--- /dev/null
+++ b/package/base-files/default/sbin/hotplug
@@ -0,0 +1,6 @@
+#!/bin/ash
+# $Id$
+[ "${INTERFACE%%[0-9]*}" = "wds" ] && {
+ ifconfig $INTERFACE 0.0.0.0 up
+ /usr/sbin/brctl addif br0 $INTERFACE
+}
diff --git a/package/base-files/default/sbin/ifdown b/package/base-files/default/sbin/ifdown
new file mode 100755
index 0000000000..6b255cc1b8
--- /dev/null
+++ b/package/base-files/default/sbin/ifdown
@@ -0,0 +1,9 @@
+#!/bin/ash
+[ $# = 0 ] && { echo " $0 <group>"; exit; }
+. /etc/functions.sh
+type=$1
+debug "### ifdown $type ###"
+if=$(nvram get ${type}_ifname)
+if_valid $if || exit
+$DEBUG ifconfig $if down
+kill $(cat /var/run/${if}.pid 2>&-) 2>&-
diff --git a/package/base-files/default/sbin/ifup b/package/base-files/default/sbin/ifup
new file mode 100755
index 0000000000..3d81364d08
--- /dev/null
+++ b/package/base-files/default/sbin/ifup
@@ -0,0 +1,59 @@
+#!/bin/ash
+[ $# = 0 ] && { echo " $0 <group>"; exit; }
+. /etc/functions.sh
+type=$1
+debug "### ifup $type ###"
+
+if_proto=$(nvram get ${type}_proto)
+if=$(nvram get ${type}_ifname)
+[ "${if%%[0-9]}" = "ppp" ] && if=$(nvram get ${if_proto}_ifname)
+
+if_valid $if || exit
+mac=$(nvram get ${type}_hwaddr)
+$DEBUG ifconfig $if down 2>&-
+
+if [ "${if%%[0-9]}" = "br" ]; then
+ stp=$(nvram get ${type}_stp)
+ $DEBUG brctl delbr $if 2>&-
+ $DEBUG brctl addbr $if
+ $DEBUG brctl setfd $if 0
+ $DEBUG brctl stp $if ${stp:-0}
+
+ for sif in $(nvram get ${type}_ifnames); do
+ if_valid $sif || continue
+ ${mac:+$DEBUG ifconfig $sif down hw ether $mac}
+ $DEBUG ifconfig $sif 0.0.0.0 up
+ $DEBUG brctl addif $if $sif
+ done
+else
+ ${mac:+$DEBUG ifconfig $if down hw ether $mac}
+fi
+
+case "$if_proto" in
+ static)
+ ip=$(nvram get ${type}_ipaddr)
+ netmask=$(nvram get ${type}_netmask)
+ gateway=$(nvram get ${type}_gateway)
+
+ $DEBUG ifconfig $if $ip ${netmask:+netmask $netmask} broadcast + up
+ ${gateway:+$DEBUG route add default gw $gateway}
+
+ [ -f /etc/resolv.conf ] && return
+
+ debug "# --- creating /etc/resolv.conf ---"
+ for dns in $(nvram get ${type}_dns); do
+ echo "nameserver $dns" >> /etc/resolv.conf
+ done
+ ;;
+ dhcp)
+ ip=$(nvram get ${type}_ipaddr)
+ [ -f $pidfile ] && $DEBUG kill $(cat $pidfile)
+ ${DEBUG:-eval} "udhcpc -R -i $if ${ip:+-r $ip} -b -p $pidfile &"
+ ;;
+ none|"")
+ ;;
+ *)
+ [ -x "/sbin/ifup.${if_proto}" ] && { $DEBUG /sbin/ifup.${if_proto} $*; exit; }
+ echo "### ifup $type: ignored ${type}_proto=\"$if_proto\" (not supported)"
+ ;;
+esac
diff --git a/package/base-files/default/sbin/mount_root b/package/base-files/default/sbin/mount_root
new file mode 100755
index 0000000000..b4ec2ca563
--- /dev/null
+++ b/package/base-files/default/sbin/mount_root
@@ -0,0 +1,25 @@
+#!/bin/sh
+if [ "$1" != "failsafe" ]; then
+ mount | grep jffs2 >&-
+ if [ $? = 0 ] ; then
+ if [ $(cat /proc/mtd | wc -l) = 6 ]; then
+ echo 5 > /proc/sys/diag
+ mtd unlock linux
+ mtd erase OpenWrt
+ jffs2root --move
+ else
+ mtd unlock rootfs
+ mount -o remount,rw /dev/root /
+ fi
+ else
+ mtd unlock OpenWrt
+ mount -t jffs2 /dev/mtdblock/4 /jffs
+ pivot_root /jffs /jffs/rom
+ mount none /proc -t proc
+ mount none /dev -t devfs
+ umount /rom/proc rom/dev >&-
+ fi
+fi
+mount none /tmp -t tmpfs -o nosuid,nodev,mode=1777,size=50%
+mkdir -p /dev/pts
+mount none /dev/pts -t devpts
diff --git a/package/base-files/default/sbin/restore b/package/base-files/default/sbin/restore
new file mode 100755
index 0000000000..6b5876cc14
--- /dev/null
+++ b/package/base-files/default/sbin/restore
@@ -0,0 +1,71 @@
+#!/bin/sh
+for param in $*; do
+ case "$param" in
+ *)
+ INPUT_FILE="$param"
+ esac
+done
+
+if [ "$INPUT_FILE" = "-" ]; then
+ echo "Reading backup from stdin..." >&2
+elif [ "$INPUT_FILE" = "" ]; then
+ echo "No input file."
+else
+ echo "Reading backup from $INPUT_FILE" >&2
+ exec < "$INPUT_FILE"
+fi
+
+process_line () {
+ case "$SECTION" in
+ ipkg)
+ echo "$line" >> /etc/ipkg.conf
+ ;;
+ nvram)
+ echo nvram set "$line"
+ ;;
+ package)
+ if grep "^Package: $line" /usr/lib/ipkg/status 2>&1 > /dev/null; then
+ echo Package "$line" already installed.
+ else
+ ipkg install "$line"
+ fi
+ ;;
+ file)
+ rm -f "$line"
+ ;;
+ esac
+}
+
+while true; do
+ read line
+ case "$line" in
+ __IPKG__)
+ SECTION=ipkg
+ echo "Restoring /etc/ipkg.conf"
+ rm -f /etc/ipkg.conf
+ ;;
+ __NVRAM__)
+ SECTION=nvram
+ echo "Restoring nvram"
+ ;;
+ __PACKAGES__)
+ SECTION=package
+ echo "Restoring packages"
+ ipkg update
+ ;;
+ __FILELIST__)
+ SECTION=file
+ echo "Deleting old files"
+ ;;
+ __FILES__)
+ echo "Restoring /etc"
+ tar -C / -xvz
+ echo "Restore complete."
+ exit 0
+ ;;
+ *)
+ process_line;
+ ;;
+ esac
+done
+
diff --git a/package/base-files/default/usr/share/udhcpc/default.script b/package/base-files/default/usr/share/udhcpc/default.script
new file mode 100755
index 0000000000..6c64aa3d4a
--- /dev/null
+++ b/package/base-files/default/usr/share/udhcpc/default.script
@@ -0,0 +1,38 @@
+#!/bin/sh
+# udhcpc script edited by Tim Riker <Tim@Rikers.org>
+# (slightly modified for openwrt)
+
+[ -z "$1" ] && echo "Error: should be run by udhcpc" && exit 1
+
+RESOLV_CONF="/tmp/resolv.conf"
+
+case "$1" in
+ deconfig)
+ ifconfig $interface 0.0.0.0
+ ;;
+
+ renew|bound)
+ ifconfig $interface $ip \
+ netmask ${subnet:-255.255.255.0} \
+ broadcast ${broadcast:-+}
+
+ if [ -n "$router" ] ; then
+ echo "deleting routers"
+ while route del default gw 0.0.0.0 dev $interface ; do
+ :
+ done
+
+ for i in $router ; do
+ route add default gw $i dev $interface
+ done
+ fi
+
+ echo -n > $RESOLV_CONF
+ ${domain:+echo search $domain} >> $RESOLV_CONF
+ for i in $dns ; do
+ echo adding dns $i
+ echo nameserver $i >> $RESOLV_CONF
+ done
+ ;;
+esac
+exit 0
diff --git a/package/base-files/default/www/index.html b/package/base-files/default/www/index.html
new file mode 100644
index 0000000000..575d242551
--- /dev/null
+++ b/package/base-files/default/www/index.html
@@ -0,0 +1,7 @@
+<HTML>
+<HEAD><TITLE>OpenWrt</TITLE></HEAD>
+<BODY>
+No webpages currently available
+<br>- perhaps you need to install a package?
+</BODY>
+</HTML>