summaryrefslogtreecommitdiff
path: root/setup
diff options
context:
space:
mode:
author0x221E <0x221E@0xinfinity.dev>2026-06-02 15:36:20 +0200
committer0x221E <0x221E@0xinfinity.dev>2026-06-02 15:38:37 +0200
commit51179eb02f2b2c4cf1c4ae31eee0a57dcbc78c03 (patch)
tree7c86b41f63cad2038d298ec4d7188f16dd8f5fe3 /setup
downloadbootstrap-master.tar.gz
initial commitHEADmaster
Diffstat (limited to 'setup')
-rwxr-xr-xsetup194
1 files changed, 194 insertions, 0 deletions
diff --git a/setup b/setup
new file mode 100755
index 0000000..1c60151
--- /dev/null
+++ b/setup
@@ -0,0 +1,194 @@
+#!/bin/bash
+
+TEMPLATE_DIR="templates"
+
+TMP_DIR_PREFIX="$(pwd)/tmp"
+rm -rf "${TMP_DIR_PREFIX}"/* # ?? Could be vulnerable
+
+if [ -z "${DISTRO_TC}" ]
+then
+ DISTRO_TC=x86_64-x221e-linux-gnu
+fi
+
+if [ -z "${CROSS_TC}" ]
+then
+ CROSS_TC=${HOME}/opt/cross
+fi
+
+if [ -z "${CC}" ]
+then
+ CC=x86_64-x221e-linux-gnu-gcc
+fi
+
+if [ -z "${MASTERDIR}" ]
+then
+ MASTERDIR="$(pwd)/bootstrap"
+fi
+
+mkdir -p "${MASTERDIR}"
+touch "${MASTERDIR}/packages"
+
+if [ -z "${CROSS_ENV_ROOT}" ]
+then
+ CROSS_ENV_ROOT="${HOME}/opt/cross/"
+fi
+
+MIRROR_GNU_FTP="https://ftp.gnu.org/gnu/"
+
+function download_source {
+ upstream="$1"
+ out_name="$2"
+
+ curl -L --output-dir=${TMP_DIR_PREFIX} "${upstream}" -o "${out_name}"
+
+ if [ $? -ne 0 ]
+ then
+ echo -e "error: failed to download '${out_name}' from '${upstream}'"
+ fi
+}
+
+function unpack_source {
+ file="$1"
+
+ currdir="$(pwd)"
+
+ cd "${TMP_DIR_PREFIX}"
+
+ if [[ ! -e "${file}" || ! -f "${file}" ]]
+ then
+ echo -e "error: unpack_source: file '${file}' does not exist."
+ exit 1
+ fi
+
+ tar -xf "${file}"
+
+ if [ $? -ne 0 ]
+ then
+ echo -e "error: unpack_source: tar failed with error code: ${?}"
+ fi
+
+ cd "${currdir}"
+}
+
+function handle_configure {
+ pkg_dir="$1"
+
+ if [[ "$(type -t 'do_configure')" == "function" ]]
+ then
+ if [[ ! -e "${pkg_dir}" || ! -d "${pkg_dir}" ]]
+ then
+ echo -e "error: pkg_install: could not find: '${pkg_dir}'"
+ exit 1
+ fi
+
+ cd "${pkg_dir}"
+
+ do_configure
+
+ cd "${currdir}"
+ fi
+
+}
+
+function handle_build {
+ pkg_dir="$1"
+
+ if [[ "$(type -t 'do_build')" == "function" ]]
+ then
+ if [[ ! -e "${pkg_dir}" || ! -d "${pkg_dir}" ]]
+ then
+ echo -e "error: pkg_install: could not find: '${pkg_dir}'"
+ exit 1
+ fi
+
+ cd "${pkg_dir}"
+
+ do_build
+
+ cd "${currdir}"
+ fi
+
+}
+
+function handle_install {
+ pkg_dir="$1"
+
+ if [[ "$(type -t 'do_install')" == "function" ]]
+ then
+ if [[ ! -e "${pkg_dir}" || ! -d "${pkg_dir}" ]]
+ then
+ echo -e "error: pkg_install: could not find: '${pkg_dir}'"
+ exit 1
+ fi
+
+ cd "${pkg_dir}"
+
+ do_install
+
+ cd "${currdir}"
+ fi
+}
+
+function pkg_install {
+ pkg="$1"
+
+ pkg_file="${TEMPLATE_DIR}/${pkg}/template"
+
+ if [[ ! -e "${pkg_file}" || ! -f "${pkg_file}" ]]
+ then
+ echo -e "error: template '${pkg_file}' does not exist!"
+ exit 1
+ fi
+
+ currdir=$(pwd)
+ source "${pkg_file}"
+
+ if [ "${#dependson[@]}" -gt 0 ]
+ then
+ for i in "${dependson[@]}"
+ do
+ if [[ "$(sed -n /${i}/p ${MASTERDIR}/packages)" != "$i" ]]
+ then
+ echo -e "'${i}' must be installed before you can install '${pkgname}'"
+ exit 1
+ fi
+ done
+ fi
+
+ pkg_dir_name="${pkgname}-${version}"
+ archive_name="${pkg_dir_name}.tar"
+
+ download_source "${upstream}" "${archive_name}"
+ unpack_source "${archive_name}"
+
+ handle_configure "${TMP_DIR_PREFIX}/${pkg_dir_name}"
+ handle_build "${TMP_DIR_PREFIX}/${pkg_dir_name}"
+ handle_install "${TMP_DIR_PREFIX}/${pkg_dir_name}"
+
+ echo "${pkgname}=${version}" >> "${MASTERDIR}/packages"
+}
+
+function bootstrap {
+ for i in $(ls templates/)
+ do
+ pkg_install "${i}"
+ done
+}
+
+function requirements {
+ ncurses_lib_loc="${CROSS_TC}/usr/lib/libncursesw_g.a"
+ echo -e "Checking the existence of ncursesw in the cross-toolchain environment."
+ if [[ ! -e "${ncurses_lib_loc}" || ! -f "${ncurses_lib_loc}" ]]
+ then
+ MASTERDIR="${CROSS_TC}"
+ pkg_install "ncurses"
+ fi
+ echo -e "requirement met: ncurses"
+}
+
+case "$1" in
+ "pkg") pkg_install "${@:2}" ;;
+ "bootstrap") bootstrap "${@:2}" ;;
+ "requirements") requirements "${@:2}" ;;
+ *) echo -e "error: invalid command" && exit 1 ;;
+esac