summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.in71
-rwxr-xr-xsrc/opkbootstrap.sh285
2 files changed, 356 insertions, 0 deletions
diff --git a/src/Makefile.in b/src/Makefile.in
new file mode 100644
index 0000000..0d22634
--- /dev/null
+++ b/src/Makefile.in
@@ -0,0 +1,71 @@
+# opkbootstrap
+# Makefile.in
+# Input Makefile for configure.
+#
+# Copyright (C) 2012 Patrick "P. J." McDermott
+#
+# 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 3 of the License, 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.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+SHELL = @shell@
+INSTALL = @install@
+MAKE = @make@
+
+SRCDIR = @srcdir@
+PREFIX = @prefix@
+BINDIR = @bindir@
+
+.SUFFIXES:
+.SUFFIXES: .sh
+
+SRCS = opkbootstrap.sh
+OBJS = $(SRCS:.sh=)
+
+PACKAGE = @package@
+VERSION = @version@
+
+distdir = ../$(PACKAGE)-$(VERSION)/src
+distfiles = Makefile.in $(SRCS)
+
+.PHONY: all
+all: $(OBJS)
+
+$(OBJS):
+ @printf ' SED %s\n' '$@'
+ @sed -f ../sedscript $(SRCDIR)/src/$@.sh > $@
+
+.PHONY: clean
+clean:
+ @for obj in $(OBJS); do \
+ printf ' RM src/%s\n' "$${obj}"; \
+ rm -f $${obj}; \
+ done
+
+.PHONY: install
+install: all
+ @for obj in $(OBJS); do \
+ printf ' INSTALL src/%s\n' "$${obj}"; \
+ $(INSTALL) -D $${obj} "$(DESTDIR)/$(BINDIR)/$${obj}"; \
+ done
+
+.PHONY: uninstall
+uninstall:
+ @for obj in $(OBJS); do \
+ printf ' RM %s\n' "$${obj}"; \
+ rm -f "$(DESTDIR)/$(BINDIR)/$${obj}"; \
+ done
+
+.PHONY: distdir
+distdir:
+ @[ -d '$(distdir)' ] || mkdir '$(distdir)'
+ @cp -pR $(distfiles) $(distdir)
diff --git a/src/opkbootstrap.sh b/src/opkbootstrap.sh
new file mode 100755
index 0000000..3ad3c27
--- /dev/null
+++ b/src/opkbootstrap.sh
@@ -0,0 +1,285 @@
+#!@@SHELL@@
+#
+# opkbootstrap
+# src/opkbootstrap.sh
+# Main program script.
+#
+# Copyright (C) 2012 Patrick "P. J." McDermott
+#
+# 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 3 of the License, 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.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+TARGET= # set in main
+LISTS_DIR=/var/lib/opkg/lists
+PKGS_DIR=/var/cache/opkg/archives
+
+ARCH_MACHINE= # set in main
+ARCH_SYSTEM= # set in main
+PLAT_SYSTEM= # set in main
+
+PKGS_ESSENTIAL= # set in find_essential
+PKGS_ALL= # set in find_essential and find_depends
+PKGS_INCLUDE= # set in main
+PKGS_EXCLUDE= # set in main
+
+# main <target> <arch> <src> [<src>]...
+main()
+{
+ SCRIPT_NAME="${0}"
+
+ while getopts 'hVi:x:' opt; do
+ case "${opt}" in
+ h)
+ print_help
+ exit
+ ;;
+ V)
+ print_version
+ exit
+ ;;
+ i)
+ PKGS_INCLUDE="${PKGS_INCLUDE},${OPTARG}"
+ ;;
+ x)
+ PKGS_EXCLUDE="${PKGS_EXCLUDE},${OPTARG}"
+ ;;
+ ?)
+ print_usage >&2
+ exit 1
+ ;;
+ esac
+ done
+ shift $(($OPTIND - 1))
+
+ if [ ${#} -lt 4 ]; then
+ print_usage >&2
+ exit 1
+ fi
+
+ TARGET="${1}"
+ ARCH_MACHINE="${2%:*}"
+ ARCH_SYSTEM="${2#*:}"
+ PLAT_SYSTEM="${3}"
+ shift 3
+
+ set_paths
+
+ # Find packages.
+ for src; do
+ get_src_list ${src}
+ done
+ find_essential
+ find_depends
+
+ # Download packages.
+ get_pkgs
+
+ # Unpack packages ("first stage" installation in debootstrap terms).
+ unpack_pkgs
+
+ # Configure packages ("second stage" installation in debootstrap terms).
+ if [ "${ARCH_MACHINE}" = "${ARCH_SYSTEM}" ]; then
+ setup_chroot
+ configure_pkgs
+ else
+ printf 'Cross installation currently not supported. Exiting...\n'
+ exit
+ fi
+}
+
+# print_usage
+print_usage()
+{
+ cat <<EOF
+Usage: ${SCRIPT_NAME} [OPTION]... <target> <arch> <plat> <src> [<src>]...
+EOF
+}
+
+# print_help
+print_help()
+{
+ print_usage
+
+ cat <<EOF
+Bootstrap the installation of a base system into a target directory.
+
+ -h display this help and exit
+ -V display version information and exit
+ -i A,B,C includes specified packages in the base system
+ -x A,B,C excludes specified packages from the base system
+EOF
+}
+
+# print_version
+print_version()
+{
+ cat <<EOF
+@@PACKAGE@@ @@VERSION@@
+Copyright (C) 2012 Patrick "P. J." McDermott
+License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
+This is free software: you are free to change and redistribute it.
+There is NO WARRANTY, to the extent permitted by law.
+
+Written by P. J. McDermott.
+EOF
+}
+
+# error <fmt> [<args>]...
+error()
+{
+ _msg="${1}"
+ shift
+ printf "Error: ${_msg}\n" ${@}
+ exit 2
+}
+
+# set_paths
+set_paths()
+{
+ TARGET=$(cd "${TARGET}" && pwd)
+ LISTS_DIR="${TARGET}/${LISTS_DIR}"
+ PKGS_DIR="${TARGET}/${PKGS_DIR}"
+}
+
+# get_src_list src|src/gz <name> <value> [<comp>]
+# get_src_list dist|dist/gz <name> <value> [<comp>]...
+get_src_list()
+{
+ case "${1}" in
+ src)
+ shift
+ get_pkg_src_list false ${@}
+ ;;
+ src/gz)
+ shift
+ get_pkg_src_list true ${@}
+ ;;
+ dist)
+ shift
+ get_dist_src_list false ${@}
+ ;;
+ dist/gz)
+ shift
+ get_dist_src_list true ${@}
+ ;;
+ *)
+ error 'Invalid source type "%s"' "${1}"
+ ;;
+ esac
+}
+
+# get_pkg_src_list <gzip> <name> <value> [<comp>]
+get_pkg_src_list()
+{
+ if [ ${#} -ne 3 -a ${#} -ne 4 ]; then
+ error 'Malformed src configuration'
+ fi
+
+ _gzip=${1}
+ _name="${2}"
+ _value="${3}"
+ _comp="${4}"
+
+ _url="${_value}/${_comp}/Packages"
+
+ if ${_gzip}; then
+ wget -q -O - "${_url}.gz" | gzcat > "${LISTS_DIR}/${_name}"
+ else
+ wget -q -O "${LISTS_DIR}/${_name}" "${_url}"
+ fi
+}
+
+# get_dist_src_list <gzip> <name> <value> [<comp>]...
+get_dist_src_list()
+{
+ :
+}
+
+# find_essential
+find_essential()
+{
+ for _list in "${LISTS_DIR}/"*; do
+ _pkg=
+ _essential=false
+ while read _line; do
+ if [ -z "${line}" ]; then
+ if ${_essential}; then
+ PKGS_ESSENTIAL="${PKGS_ESSENTIAL} ${_pkg}"
+ PKGS_ALL="${PKGS_ALL} ${_pkg}"
+ fi
+ _pkg=
+ _essential=false
+ continue
+ fi
+ if [ "${_line#Package: }" != "${_line}" ]; then
+ _pkg="${_line#Package: }"
+ continue
+ fi
+ if [ "${_line}" = 'Essential: yes' ]; then
+ _essential=true
+ continue
+ fi
+ # TODO: Make sure Architecture is one of:
+ # all, ${ARCH_SYSTEM}, or ${PLAT_SYSTEM}
+ done < "${_list}"
+ done
+}
+
+# find_depends
+find_depends()
+{
+ :
+}
+
+# get_pkgs
+get_pkgs()
+{
+ :
+}
+
+# unpack_pkgs
+unpack_pkgs()
+{
+ cd "${TARGET}"
+
+ for _opk in "${PKGS_DIR}"/*; do
+ _pkg="${opk##*/}"
+ _pkg="${pkg%%_*}"
+
+ tar -xzOf "${_opk}" data.tar.gz | tar -xz
+
+ mkdir -p tmp/control
+ (cd tmp/control; tar -xzf "${_opk}" control.tar.gz)
+ for _script in conffiles md5sums preinst postinst prerm postrm; do
+ if [ -e tmp/control/${_file} ]; then
+ mv tmp/control/${_script} "${INFO_DIR}/${_pkg}.${_file}"
+ fi
+ done
+ # TODO: Generate pkg.list
+ rm -Rf tmp/control
+ done
+}
+
+# setup_chroot
+setup_chroot()
+{
+ :
+}
+
+# configure_pkgs
+configure_pkgs()
+{
+ :
+}
+
+main ${@}