diff options
author | davidovski <david@davidovski.xyz> | 2022-02-20 14:32:34 +0000 |
---|---|---|
committer | davidovski <david@davidovski.xyz> | 2022-02-20 14:32:34 +0000 |
commit | 5e64673025351660b27ad61e215ef38a8f033c85 (patch) | |
tree | 87f8f11c38a447835e546fc8c579308e88d4ebee | |
parent | 8f02115e50573be0a5c6653f2a4a2bb6d7459911 (diff) |
added bootstrapping
-rw-r--r-- | src/bootstrap.sh | 59 | ||||
-rwxr-xr-x | src/get.sh | 6 | ||||
-rw-r--r-- | src/install.sh | 20 | ||||
-rwxr-xr-x | src/sync.sh | 2 | ||||
-rw-r--r-- | src/validate.sh | 33 | ||||
-rwxr-xr-x | src/xi.sh | 10 |
6 files changed, 126 insertions, 4 deletions
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 +} @@ -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 +} @@ -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 $@ |