#!@@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 . 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 []... 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 } # print_help print_help() { print_usage cat <. 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 []... 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 [] # get_src_list dist|dist/gz []... 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 [] 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 []... 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 ${@}