commit e1ee5022cac246a7bfeb2c0006c24696d3433a4a Author: Liam Waldron Date: Thu Feb 16 10:36:15 2023 -0500 2/16/23 diff --git a/install/build.sh b/install/build.sh new file mode 100644 index 0000000..dd02601 --- /dev/null +++ b/install/build.sh @@ -0,0 +1,40 @@ +#!/bin/sh + +if [ $(/usr/bin/id -u) != "0" ]; then + printf "[x] Must be run as root.\n" + exit 1 +fi + +WORKING_DIR=$(pwd) +SRC_DIR=$(pwd)/../src + +parse_install_conf() { + source ${WORKING_DIR}/install.conf + if [ "$?" != "0" ]; then + printf "[x] install.conf not found.\n" + exit 1 + fi +} + +installpkg() { + install ${SRC_DIR}/gpkg /bin + install ${SRC_DIR}/syspkg /bin + install ${SRC_DIR}/gquery /bin + install ${SRC_DIR}/glist /bin +} + +case $1 in + install) + parse_install_conf "$@" + installpkg "$@" + ;; + update) + parse_install_conf "$@" + installpkg "$@" + ;; + *) + printf "[x] Unknown option.\n" + exit 1 +esac + + diff --git a/src/glist b/src/glist new file mode 100755 index 0000000..aef5a85 --- /dev/null +++ b/src/glist @@ -0,0 +1,58 @@ +#!/usr/bin/env /bin/sh + +source /etc/glacier.conf + +usage() { + printf "${0} - list all packages in the local package index\n" + printf "usage: ${0} [-h] [-v] [-a] [-f] PACKAGE_NAME\n" + printf "\n" + printf "${0} {-h} Show this message\n" + printf "${0} {-v} Show the version\n" + printf "${0} {-a} Show all packages\n" + printf "${0} {-f} Filter packages by name\n" + printf "\n" + printf "This program is free software.\n" + printf "See the GNU GPL version 3 for details.\n" +} + +usage_small() { + printf "usage: ${0} [-h] [-v] [-a] [-f] PACKAGE_NAME\n" +} + +version() { + printf "${GLACIER_RELEASE}\n" +} + +list_all() { + ls /etc/glacier/pkginfo +} + +filter() { + cd /etc/glacier/pkginfo + find ${@} +} + +case $1 in + -h) + usage "$@" + exit 0 + ;; + -v) + version "$@" + exit 0 + ;; + -a) + list_all "$@" + exit 0 + ;; + -f) + filter "$@" + exit 0 + ;; + *) + usage_small "$@" + exit 1 +esac + +usage_small "$@" +exit 1 diff --git a/src/gpkg b/src/gpkg new file mode 100755 index 0000000..fcb40e2 --- /dev/null +++ b/src/gpkg @@ -0,0 +1,181 @@ +#!/usr/bin/env sh + +source /etc/glacier.conf +if [ "$?" != "0" ]; then + printf "error while parsing Glacier's configuration file\n" + printf "ensure it exists and is accessible\n" + printf "exitting..." + exit 1 +fi + +usage() { + printf "${0} - Merge a package into the local package index\n" + printf "usage: ${0} [-h] [-v] [-f] [-u] [-x] [-fl] [-ul] [-d] \n" + printf "\n" + printf "${0} {-h --help} Show this message\n" + printf "${0} {-v --version} Show the current version\n" + printf "${0} {-f --install} Install a package from a global repository\n" + printf "${0} {-u --update} Update an installed package\n" + printf "${0} {-x --remove} Remove a package\n" + printf "${0} {-fl --localin} Same as -f, but takes a local directory\n" + printf "${0} {-ul --localup} Same as -u, but takes a local directory\n" + printf "${0} {-d --dload} ONLY download a package\n" + printf "\n" + printf "This program is free software.\n" + printf "See the GNU GPL version 3 for details.\n" +} + +usage_small() { + printf "${red}[${error}]${reset} Unknown option.\n" + printf "${red}[${error}]${reset} usage:${reset} ${0} [-h] [-v] [-f] [-u] [-x] [-fl] [-ul] [-d] PACKAGE_NAME\n" +} + +am_i_root() { + if [ $(/usr/bin/id -u) != "0" ]; then + printf "${red}[${error}]${reset} Cannot open /usr/glacier/index: permission denied. Are you root?\n" + exit 1 + fi +} + +dload_pkg() { + cd /opt/glacier/workspace + # Store all positional parameters ["${@}"] in an array [pkgs=()] + pkgs=("${@}") + # if no packages are specified, exit + if [[ $pkgs == "" ]]; then + printf "${red}[${error}]${reset} No package(s) were specified.\n" + exit 1 + fi + printf "${blue}[i]${reset} Downloading package(s)...\n" + for i in ${pkgs[@]}; do + ${GLACIER_DOWNLOAD_BACKEND} ${GREPO}/${i} + if [ "$?" != "0" ]; then + printf "${red}[${error}]${reset} Could not find package.\n" + exit 1 + fi + done +} + +checkdeps() { + pkgs=("${@}") + for i in /opt/glacier/workspace/*; do + source ${i} + printf "%s\n" "${DEPENDS[@]}" + done +} + +checkconflicts() { + pkgs=("${@}") + for i in /opt/glacier/workspace/*; do + find /etc/glacier/pkginfo -wholename "${i}" + if [ "$?" != "0" ]; then + printf "${red}[${error}]${reset} Package conflicts with an installed package.\n" + exit 1 + fi + done +} + +get_pkg_sources() { + pkgs=("${@}") + for i in /opt/glacier/workspace/*; do + source ${i} + ${i} getsource + done +} + +install_pkg() { + pkgs=("${@}") + for i in /opt/glacier/workspace/*; do + source ${i} + ${i} buildpkg + ${i} installpkg + done +} + +update_pkg() { + pkgs=("${@}") + for i in /opt/glacier/workspace/*; do + source ${i} + ${i} updatepkg + done +} + +remove_pkg() { + pkgs=("${@}") + for i in /opt/glacier/workspace/*; do + source ${i} + ${i} removepkg + done +} + +clean_after_failed() { + printf "${blue}[i]${reset} Operation failed, removing packages...\n" + rm /opt/glacier/workspace/* +} + +index_pkg() { + printf "${blue}[i]${reset} Adding packages to index...\n" + mv /opt/glacier/workspace/* /usr/glacier/index + if [ "$?" != "0" ]; then + printf "${yellow}[!]${reset} Packages did not index. To do this manually:\n" + printf "${yellow}[!]${reset} (root)# mv /opt/glacier/workspace/* /usr/glacier/index\n" + printf "${yellow}[!]${reset} To avoid this warning in the future, ensure the package index exists and is accessible.\n" + fi +} + +case $1 in + -h|--help) + usage "$@" + exit 0 + ;; + -v|--version) + printf "gpkg v4.0.0-rc1\n" + printf "Glacier v4.0.0\n" + exit 0 + ;; + -f|--install) + shift + am_i_root "$@" + dload_pkg "$@" + checkdeps "$@" + checkconflicts "$@" + get_pkg_sources "$@" + install_pkg "$@" + exit 0 + ;; + -u|--update) + shift + am_i_root "$@" + dload_pkg "$@" + checkdeps "$@" + checkconflicts "$@" + get_pkg_sources "$@" + update_pkg "$@" + exit 0 + ;; + -x|--remove) + shift + am_i_root "$@" + remove_pkg "$@" + exit 0 + ;; + -fl|--localin) + printf "not implemented\n" + exit 0 + ;; + -ul|--localup) + printf "not implemented\n" + exit 0 + ;; + -d|--dload) + shift + dload_pkg "$@" + exit 0 + ;; + *) + usage_small "$@" + exit 1 +esac + +usage_small "$@" +exit 1 diff --git a/src/gquery b/src/gquery new file mode 100755 index 0000000..65e2b54 --- /dev/null +++ b/src/gquery @@ -0,0 +1,74 @@ +#!/usr/bin/env sh + +source /etc/glacier.conf + +usage() { + printf "${0} - Query a package in the local package index\n" + printf "usage: ${0} [-h] [-v] [-f] [-i] PACKAGE_NAME\n" + printf "\n" + printf "${0} {-h} Show this message\n" + printf "${0} {-v} Show the version\n" + printf "${0} {-f} Query a package's files\n" + printf "${0} {-i} Query a package's info file\n" + printf "\n" + printf "This program is free software.\n" + printf "See the GNU GPL version 3 for details.\n" +} + +usage_small() { + printf "usage: ${0} [-h] [-v] [-f] [-i] PACKAGE_NAME\n" +} + +query_info() { + source /etc/glacier/pkginfo/${2} + if [ "$?" != "0" ]; then + printf "${red}[ ${error} ]${reset} No package found.\n" + exit 1 + fi + printf "${blue}[ i ]${reset} Showing information for package ${2}:\n" + printf "${blue}* Package name:${reset} ${PACKAGE_NAME}\n" + printf "${blue}* Package version:${reset} ${PACKAGE_VER}\n" + printf "${blue}* Package description:${reset} ${PACKAGE_DESC}\n" + printf "${blue}* Maintainer:${reset} ${MAINTAINER}\n" + printf "${blue}* License:${reset} ${LICENSE}\n" + printf "${blue}* Architecture:${reset} ${ARCH}\n" +} + +query_files() { + if [ "${2}" = "" ]; then + printf "${red}[ ${error} ]${reset} You must specify a package.\n" + exit 1 + fi + source /etc/glacier/pkginfo ${2} + if [ "$?" != "0" ]; then + printf "${red}[ ${error} ]${reset} No package found.\n" + exit 1 + fi + printf "${blue}[ i ]${reset} Showing installed files for package: ${2}:\n" + printf "${INCLUDED_FILES[@]}" +} + +case $1 in + -h) + usage "$@" + exit 0 + ;; + -v) + printf "${blue}${GLACIER_VERSION}${reset}\n" + exit 0 + ;; + -f) + query_files "$@" + exit 0 + ;; + -i) + query_info "$@" + exit 0 + ;; + *) + usage_small "$@" + exit 1 +esac + +usage_small "$@" +exit 1 diff --git a/src/syspkg b/src/syspkg new file mode 100755 index 0000000..0132969 --- /dev/null +++ b/src/syspkg @@ -0,0 +1,116 @@ +#!/usr/bin/env /bin/sh + +source /etc/glacier.conf +if [ "$?" != "0" ]; then + printf "error while parsing Glacier's configuration file\n" + printf "ensure it exists and is accessible\n" + printf "exitting...\n" + exit 1 +fi + +usage() { + printf "${0} - Merge a package into the system package index\n" + printf "usage: ${0} [-h] [-v] [-f] [-u] [-x] [-l] [-d] PACKAGE_NAME\n" + printf "\n" + printf "${0} {-h} Show this message\n" + printf "${0} {-v} Show the current version\n" + printf "${0} {-f} Install a package from the global repository\n" + printf "${0} {-u} Update an installed package\n" + printf "${0} {-x} Remove a package\n" + printf "${0} {-l} Same as -f, but takes a local directory\n" + printf "${0} {-d} ONLY download a package\n" + printf "\n" + printf "NOTE: This program should only be used for building\n" + printf "system images. Regular users should use 'glacier-mergepkg' instead.\n" + printf "\n" + printf "This program is free software.\n" + printf "See the GNU GPL version 3 for details.\n" +} + +usage_small() { + printf "usage: ${0} [-h] [-v] [-f] [-u] [-x] [-l] [-d] PACKAGE_NAME\n" +} + +dload_pkg() { + pkgs=("${@}") + if [ $pkgs == "" ]; then + printf "${red}[ $error ]${reset} No package(s) were specified.\n" + exit 1 + fi + printf "${blue}[ i ]${reset} Downloading package(s)...\n" + for i in ${pkgs[@]}; do + ${GLACIER_DOWNLOAD_BACKEND} ${GREPO}/${i} + if [ "$?" != "0" ]; then + printf "${red}[ ${error} ]${reset} Could not find package.\n" + exit 1 + fi + done +} + +checkdeps() { + pkgs=("${@}") + for i in ${pkgs[@]}; do + source ${i} + printf "%s\n" "${DEPENDS[@]}" + done +} + +get_pkg_sources() { + pkgs=("${@}") + for i in ${pkgs[@]}; do + source ${i} + ${i} getsource + done +} + +install_pkg() { + pkgs=("${@}") + for i in ${pkgs[@]}; do + source ${i} + ${i} buildpkg + ${i} installpkg_system + done +} + +update_pkg() { + pkgs=("${@}") + for i in ${pkgs[@]}; do + source ${i} + ${i} updatepkg_system + done +} + +remove_pkg() { + pkgs=("${0}") + for i in ${pkgs[@]}; do + source ${i} + ${i} removepkg_system + done +} + +case $1 in + -h|--help) + usage "$@" + exit 0 + ;; + -v|--version) + printf "syspkg v4.0.0-rc1\n" + printf "Glacier v4.0.0\n" + exit 0 + ;; + -f|--install) + shift + cd /opt/glacier/workspace + dload_pkg "$@" + checkdeps "$@" + checkconflicts "$@" + get_pkg_sources "$@" + install_pkg "$@" + exit 0 + ;; + -u|--update) + shift + cd /opt/glacier/workspace + dload_pkg "$@" + checkdeps "$@" + checkconflicts "$@"