From 5e64673025351660b27ad61e215ef38a8f033c85 Mon Sep 17 00:00:00 2001 From: davidovski Date: Sun, 20 Feb 2022 14:32:34 +0000 Subject: added bootstrapping --- src/bootstrap.sh | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/get.sh | 6 +++--- src/install.sh | 20 +++++++++++++++++++ src/sync.sh | 2 +- src/validate.sh | 33 +++++++++++++++++++++++++++++++ src/xi.sh | 10 ++++++++++ 6 files changed, 126 insertions(+), 4 deletions(-) create mode 100644 src/bootstrap.sh diff --git a/src/bootstrap.sh b/src/bootstrap.sh new file mode 100644 index 0000000..846e8c3 --- /dev/null +++ b/src/bootstrap.sh @@ -0,0 +1,59 @@ +#!/bin/sh + +DEFAULT_KEYS="davidovski https://xi.davidovski.xyz/keychain/xi.pub" + +create_directories () { + mkdir -p ${SYSROOT} + mkdir -p ${SYSROOT}/dev + mkdir -p ${SYSROOT}/tmp + mkdir -p ${SYSROOT}/sys + mkdir -p ${SYSROOT}/run + mkdir -p ${SYSROOT}/proc + mkdir -p ${SYSROOT}/usr + mkdir -p ${SYSROOT}/root + mkdir -p ${SYSROOT}/usr/bin + mkdir -p ${SYSROOT}/usr/lib + + ln -s usr/bin ${SYSROOT}/bin + ln -s usr/bin ${SYSROOT}/sbin + ln -s bin ${SYSROOT}/usr/sbin + + ln -s usr/lib ${SYSROOT}/lib + ln -s usr/lib ${SYSROOT}/lib64 + ln -s usr/lib ${SYSROOT}/usr/lib64 + + ln -s usr ${SYSROOT}/usr/local +} + +import_keys () { + # import all keys + set -o noglob + if [ -d ${KEYCHAIN_DIR} ] && [ "$(ls ${KEYCHAIN_DIR} | wc -w)" != "0" ]; then + keyimport * + else + keyimport $DEFAULT_KEYS + fi +} + +bootstrap () { + if [ "${SYSROOT}" = "/" ]; then + printf "${RED}Error! Cannot bootstrap on existing system! Use ${LIGHT_RED}--root${RED} to specify new root filesystem\n" + return 1 + fi + + if [ -e ${SYSROOT} ] && [ "$(ls -1 ${SYSROOT})" != "0" ]; then + if prompt_question "${WHITE}System already exists on ${SYSROOT}, clear?"; then + rm -rf ${SYSROOT}/* + fi + fi + + printf "${BLUE}Creating directories..." + create_directories + printf "${GREEN}${CHECKMARK}\n" + + sync + + install base linux xipkg $@ + + import_keys +} diff --git a/src/get.sh b/src/get.sh index 3e23f78..05b2860 100755 --- a/src/get.sh +++ b/src/get.sh @@ -28,7 +28,7 @@ resolve_deps () { for dep in $(list_deps $package); do # if not already checked - if echo ${deps} | grep -qv "\b$dep\b"; then + if echo $@ | grep -qv "\b$dep\b"; then set -- $@ $dep fi done @@ -78,7 +78,7 @@ download_packages () { local output="${out_dir}/${checksum}.${package}.xipkg" local output_info="${output}.info" - if ${UNSAFE} || validate_checksum $output $checksum; then + if validate_checksum $output $checksum; then ${VERBOSE} && printf "${LIGHT_BLACK}skipping download for %s already exists with checksum %s${RESET}\n" $package $checksum else ${VERBOSE} && printf "${LIGHT_BLACK}downloading $package from $url\n" $package $checksum @@ -94,9 +94,9 @@ download_packages () { wait_for_download $total_download ${outputs} echo + set -- $outputs if ! ${UNSAFE}; then local i=0 - set -- $outputs for pkg_file in ${outputs}; do ${QUIET} || hbar -T "${LARGE_CIRCLE} validating downloads..." $i $# diff --git a/src/install.sh b/src/install.sh index 6c02fab..c73a202 100644 --- a/src/install.sh +++ b/src/install.sh @@ -45,6 +45,25 @@ total_filecount() { echo $count } +run_postinstall () { + postinstall="${SYSROOT}/var/lib/xipkg/postinstall" + if [ -d $postinstall ]; then + for file in $(ls $postinstall/*.sh); do + f=$(basename $file) + + # run the postinstall file + # + chmod 755 $file + [ "${SYSROOT}" = "/" ] && + sh "/var/lib/xipkg/postinstall/$f" && + rm $file && + printf "${GREEN}run postinstall for $f!\n" + done + rmdir $postinstall + fi +} + + install () { local packages=$@ @@ -70,5 +89,6 @@ install () { files_files="$files_files $filelist" done wait_for_extract $total ${files_files} + run_postinstall fi } diff --git a/src/sync.sh b/src/sync.sh index 3d1c7d1..265c374 100755 --- a/src/sync.sh +++ b/src/sync.sh @@ -33,7 +33,7 @@ list_source () { ${VERBOSE} && printf "${LIGHT_BLACK}Indexing $repo from $full_url\n" local status=$(download_file $tmp_file $full_url) - if [ "$status" = "200" ] || [ "$status" = "000" ]; then + if [ "$status" = "200" ] || [ "$status" = "000" ] && [ -f $tmp_file ]; then while IFS= read -r line; do parse_line $repo $repo_url $line done < "$tmp_file" diff --git a/src/validate.sh b/src/validate.sh index b2c0b21..42530bb 100644 --- a/src/validate.sh +++ b/src/validate.sh @@ -23,3 +23,36 @@ validate_sig () { done return 1 } + + +keyimport () { + local keychain=${SYSROOT}${KEYCHAIN_DIR} + mkdir -p $keychain + case "$#" in + "2") + local name=$1 + local url=$2 + + local keyfile=$keychain/$name.pub + printf "${BLUE}Importing $name...${GREEN}" + download_file $keyfile $url && + printf "${CHECKMARK}\n" || + printf "${RED}Error occured!\n" + ;; + "1") + local keyname=$1 + + # account for a glob input + set +o noglob + for key in ${KEYCHAIN_DIR}/$keyname.pub; do + name=$(basename -s .pub $key) + cp $key $keychain + printf "${GREEN}Imported ${LIGHT_GREEN}$name ${GREEN}to ${SYSROOT}\n" + done + ;; + *) + ls $keychain + ;; + esac + set +o noglob +} diff --git a/src/xi.sh b/src/xi.sh index afff70f..e00e68d 100755 --- a/src/xi.sh +++ b/src/xi.sh @@ -47,6 +47,7 @@ done . ${LIBDIR}/query.sh . ${LIBDIR}/sync.sh . ${LIBDIR}/install.sh +. ${LIBDIR}/bootstrap.sh . ${LIBDIR}/get.sh shift $((OPTIND-1)) @@ -70,10 +71,19 @@ else shift files $@ ;; + "keyimport") + shift + set -o noglob + keyimport $@ + ;; "file") shift file $@ ;; + "bootstrap") + shift + bootstrap $@ + ;; *) $DO_SYNC && sync fetch $@ -- cgit v1.2.1