# ProteanOS architecture detection and feeds lists. # # Copyright (C) 2013-2016 Patrick McDermott # # This file is part of the ProteanOS Development Kit. # # The ProteanOS Development Kit 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. # # The ProteanOS Development Kit 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 the ProteanOS Development Kit. If not, see # . prof_proteanos_fstab_linux="\ proc /proc proc defaults sys /sys sysfs defaults /dev /dev none bind devpts /dev/pts devpts noexec,nosuid,gid=5,mode=0620 " prof_proteanos_install_service=\ '#!/bin/sh /etc/rc.common start() { log "Configuring packages" printf "disabled\n" >/etc/rc.policy opkg install $(opkg list-installed | cut -d " " -f 1) printf "enabled\n" >/etc/rc.policy rm -f "${SCRIPT}" } ' prof_proteanos_detect_root() { local root="${1}" shift 1 if grep "^ID='proteanos'\$" "${root}/etc/os-release" >/dev/null 2>&1 then return 0 else return 1 fi } prof_proteanos_normalize_suite() { local suite="${1}" shift 1 case "${suite}" in */*) printf '%s\n' "${suite}";; *) printf 'dev/%s\n' "${suite}";; esac return 0 } prof_proteanos_detect_arch() { local uname_m= local uname_s= local arch= uname_m="$( (uname -m) 2>/dev/null)" || uname_m='unknown' uname_s="$( (uname -s) 2>/dev/null)" || uname_s='unknown' case "${uname_m}:${uname_s}" in 'x86_64:Linux') arch='amd64-linux-glibc' ;; 'i686:Linux') arch='i686-linux-glibc' ;; *) arch='' esac printf '%s\n' "${arch}" } prof_proteanos_default_plat() { printf 'dev\n' } prof_proteanos_select_mirror() { local mirrors= local mirrors_count= local mirror_num= mirrors="$(${WGET} -q -O - \ 'http://files.proteanos.com/pub/proteanos-mirrors-http')" mirrors_count=$(printf '%s\n' "${mirrors}" | wc -l) rand mirror_num=$((${rand_x} % ${mirrors_count} + 1)) printf '%s\n' "${mirrors}" | sed -n "${mirror_num}p" } prof_proteanos_validate_archplat() { local mirror="${1}" local arch="${2}" local plat="${3}" local suite="${4}" shift 4 while read -r archplat; do case "${archplat}" in "${arch}/${plat}") return 0 ;; esac done <<-EOF $(${WGET} -q -O - "${mirror}/feeds/${suite}/Manifest" | sed \ 's|/[^/]*$||; /^all\//d; /\/all$/d;') EOF return 1 } prof_proteanos_opkg_state_dir() { printf '/var/lib/opkg' return 0 } prof_proteanos_opkg_conf_file() { printf '/etc/opkg/opkg.conf' return 0 } prof_proteanos_feeds() { local mirror="${1}" local arch="${2}" local plat="${3}" local suite="${4}" shift 4 local a= local p= local s= for a in "${arch}" 'all'; do for p in "${plat}" 'all'; do for s in 'base'; do printf 'src/gz proteanos_%s_%s_%s_%s_%s.gz ' \ "${suite%/*}" "${suite#*/}" \ "${a}" "${p}" "${s}" printf '%s/feeds/%s/%s/%s/%s\n' \ "${mirror}" "${suite}" \ "${a}" "${p}" "${s}" done done done for s in 'base'; do printf 'src/gz proteanos_%s_%s_%s_%s_%s.gz ' \ "${suite%/*}" "${suite#*/}" \ 'src' 'all' "${s}" printf '%s/feeds/%s/%s/%s/%s\n' \ "${mirror}" "${suite}" \ 'src' 'all' "${s}" done } prof_proteanos_get_cert_url() { local mirror="${1}" shift 1 printf '%s/archive.cert' "${mirror}" return 0 } prof_proteanos_get_root_key() { cat <<-EOF untrusted comment: ProteanOS archive root key RWSG2r6ZwINj8pcScRd4nc9HVZ9zjP5oajMPfTm+dIk67btIsCZaf3SN EOF } prof_proteanos_dep_fields() { printf 'Depends Pre-Depends' } prof_proteanos_include_pkg() { local name="${1}" local value="${2}" shift 2 if [ "x${name}" = 'xessential' ]; then if [ "x${value}" = 'xyes' ]; then return 0 fi fi return 1 } prof_proteanos_get_fstab() { local arch="${1}" local plat="${2}" shift 2 case "${arch}" in *-linux-*) printf '%s\n' "${prof_proteanos_fstab_linux}" ;; esac } prof_proteanos_file_systems_mounted() { local root="${1}" local arch="${2}" local plat="${3}" shift 3 [ -e "${root}/dev/null" ] } prof_proteanos_bind_mount() { local arch="${1}" local plat="${2}" local olddir="${3}" local newdir="${4}" shift 4 case "${arch}" in *-linux-*) mount -o bind "${olddir}" "${newdir}" ;; esac } prof_proteanos_bind_umount() { local arch="${1}" local plat="${2}" local olddir="${3}" local newdir="${4}" shift 4 case "${arch}" in *-linux-*) umount "${newdir}" ;; esac } prof_proteanos_configure_system_native() { local root="${1}" local arch="${2}" local plat="${3}" shift 3 printf 'disabled\n' >"${root}/etc/rc.policy" opkg_install_all "${root}" if [ "x${plat}" = 'xdev' ]; then [ -r /etc/resolv.conf ] && cp /etc/resolv.conf "${root}/etc" [ -r /etc/hostname ] && cp /etc/hostname "${root}/etc" else printf 'enabled\n' >"${root}/etc/rc.policy" printf 'proteanos\n' >"${root}/etc/hostname" fi [ -e "${root}/etc/passwd" ] || printf \ 'root::0:0:root:/root:/bin/sh\n' >"${root}/etc/passwd" [ -e "${root}/etc/group" ] || printf \ 'root:x:0:\n' >"${root}/etc/group" } prof_proteanos_configure_system_foreign() { local root="${1}" local arch="${2}" local plat="${3}" shift 3 printf '%s' "${prof_proteanos_install_service}" \ >"${root}/etc/rc.d/S10install" chmod 0755 "${root}/etc/rc.d/S10install" printf 'proteanos\n' >"${root}/etc/hostname" [ -e "${root}/etc/passwd" ] || printf \ 'root::0:0:root:/root:/bin/sh\n' >"${root}/etc/passwd" [ -e "${root}/etc/group" ] || printf \ 'root:x:0:\n' >"${root}/etc/group" } prof_proteanos_find_kernel() { local root="${1}" local arch="${2}" local plat="${3}" shift 3 local kernel= case "${arch}" in *-linux-*) for kernel in vmlinuz; do if [ -e "${root}/boot/${kernel}" ]; then printf '%s' "/boot/${kernel}" return 0 fi done ;; esac return 1 } prof_proteanos_make_initramfs() { local arch="${1}" local plat="${2}" shift 2 local init_created= case "${arch}" in *-linux-*) if ! [ -e init ]; then ln -s /sbin/init init init_created=true else init_created=false fi find . -xdev -a \! -path './boot/*' -a \ \! -path './prokit/*' | \ ${CPIO} -o -H newc | \ ${XZ} -c --check=crc32 --x86 --lzma2 if ${init_created}; then rm -f init fi ;; esac return 1 } prof_proteanos_register() { register_profile 'proteanos' } __init prof_proteanos_register