From 06bba6f68f3977e2bd934cb7a5092c48d6c8fe07 Mon Sep 17 00:00:00 2001 From: Ohio2 Date: Wed, 29 Sep 2021 15:48:11 +0200 Subject: [PATCH] 0.1.0 BETA 0.1.0 is a complete rewrite @hippoz, @hippoz it is supposed to clean up aps. :trol: --- README.md | 4 +- altools/README.md | 1 + altools/alinitsys | 32 ++++++ altools/c/Makefile | 5 + altools/c/pow | Bin 0 -> 16232 bytes altools/c/pow.c | 28 +++++ altools/dae | 18 +++ altools/mkinitramfs | 13 +++ altools/pow | Bin 0 -> 16232 bytes aps | 269 ++++++++++++-------------------------------- aps.old | 208 ++++++++++++++++++++++++++++++++++ 11 files changed, 378 insertions(+), 200 deletions(-) create mode 100644 altools/README.md create mode 100755 altools/alinitsys create mode 100644 altools/c/Makefile create mode 100755 altools/c/pow create mode 100644 altools/c/pow.c create mode 100755 altools/dae create mode 100755 altools/mkinitramfs create mode 100755 altools/pow create mode 100755 aps.old diff --git a/README.md b/README.md index fcc58e5..563de96 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ -# aps +# APS -the alnux package manager -(the code is completely and utterly horrible and i cant believe i actually wrote this lol) \ No newline at end of file diff --git a/altools/README.md b/altools/README.md new file mode 100644 index 0000000..835ba29 --- /dev/null +++ b/altools/README.md @@ -0,0 +1 @@ +# This follows the UNIX philosophy diff --git a/altools/alinitsys b/altools/alinitsys new file mode 100755 index 0000000..d7a3409 --- /dev/null +++ b/altools/alinitsys @@ -0,0 +1,32 @@ +#!/bin/sh + +############# +# ALINITSYS # +############# + +# ALINITSYS is a passthrough to RUNIT OR OPENRC, if RUNIT OR OPENRC exists, if not, then ALINITSYS will wrap it up and init the system. + +function init(){ + exec runit && echo ":: Running Runit..." || echo ":: Runit not found..." ; + exec openrc && echo ":: Running OpenRC..." || echo ":: OpenRC not found..." ; + echo ":: Running alinitsys" +} +function rescue(){ + echo "[E] Something might've went wrong..." + echo ":: Dropping into the SH" + exec sh +} +function daemon(){ + /var/service/*/start +} +function getty(){ + echo ":: Getting TTY" + exec getty || exec stty +} +function start(){ + init || + daemon && + getty || + rescue +} +start diff --git a/altools/c/Makefile b/altools/c/Makefile new file mode 100644 index 0000000..461d230 --- /dev/null +++ b/altools/c/Makefile @@ -0,0 +1,5 @@ +ccflags = -O3 +compile: + gcc $(ccflags) pow.c -o pow +clean: + rm pow diff --git a/altools/c/pow b/altools/c/pow new file mode 100755 index 0000000000000000000000000000000000000000..a78fb198a94ec92e28fcc7451493892c6801e3b1 GIT binary patch literal 16232 zcmeHOYit}>6~4QUYqv>uombf;w3(!dl(hB6&cnDQCbPEJ9-~d-I!@ZkaVBf;*j{O0 z?9LLq1Y*e)SQ0}KsO^tX!7qLlfsmjopgJ-Xl^>84RE1Jht4hSCl-8sVr47k)&Yg4C zvy*kjLn?pfL_6O--#zEvGiUCM?_};h6^?XyJs!bQBR(Tgn`^Kbl`4v#q5^;_TE%iW z-YxDDw}HMya#p=+0n}P@(OZf2#Mc0#UjPeL@RJrT7&$^j^jl13Fdz^{LFa*fwOB#A z6Ag-!k?YI-Dd-HM$YU9gqX7t`-48=4Hp*&IY^%iM)ZZ8(`=N?{*U0Z0`7zE>e~g?@ z%nANlDW6VMp$%yf4$__smNx86L(p(VC4QD1V6g8 zWbx6!m${GnTkJXnDF2Lt9A8OgPJrQe6#8dh4#_`sc#+F^dTspWzc8qZ~!4Jn& z_kqL0J1J(6V}FnEROnvP!9)t$u7)3`9sO^7@zm0_^G`F@kb4jn@9}<2UmDl&zaGzsVAfH zlt3LXaEs`U^t5;AJAylcyM^AAArCB=M?h)iclf#eEi! z`NV6?GH2uM$TIhf7&jD_SlT+EuGh=!dkz zJH_8X;jx)~Q}K6D&`x*MW4C_)PsQG>8QhyQTlZ$nUD|ZpDL=eGe;sU|#r6kgf$Bx- z!~*sFX!ssa@d+TBX9i}UfA!|Zj^fuy!+7!hn*ZKYxNuA>ysk}Mn(yt8OxGTP_O$8c zuR*KO<`~$Q*1QxH;@!tVZH9og>Dqe{9=K+%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~h@c#8qp5r_lTBxgtT|z$hVpUP@&j8&EUQp^Pa}@UAexUwb7LYHn@B+y z7MfYB=JQ527f+`u6dmfaMk0z1RLUew5tO+In#MSkaRfqLT3)K4F-BuvdXZAfHt>n+BqLEE_{>4-a6zu-v&5S%x1`{dRhFv}f z3eHK{pXZ^B{5^)_XFJ9(fj`c1S?75!qe7iI<0o27LjiNj{yfiSoFPN*-+BH|l7Bnd z@w~l^Hh-9n+>*cV1BW@`_VG`z6heNVAy&r9WyG`av->OL$JlE(hO(o1@dJlH|D9#L z?6_d;&&@vL@aOk3Mt)yod*}H53HfvWg+i8u9i%dF{#pMy6fi{g?^LWBM*KEs7ia%3 zLZ#h*T(PVfi*{!yJNy3wa6b6aZC{=*^S(}}J?o4(ul3vfd44|M2qXyGS=xfm{NJDg z#}4<;^JdYCT3gF$tLX2_yN?}{e?=#O%}G2%D{e% zUU0Vi^Zd1y{5ejie_01-Y>VUP`JhJr+z;DhUv^ne{gZjQiv68)M)tQOkG--p6pmAa w3Jo}X4&%Eb$HUK0e1GTIp;(ql8n_1?jdQ +#include +#include +#include + +int main (int argc, char *argv[]) { + if (geteuid() != 0) { + printf("[E] pow must be run as root\n"); + return 1; + } + + sync(); + + switch (argv[1] ? argv[1][0]: 0) { + case 's': + case 'p': + reboot(RB_POWER_OFF); + return 0; + + case 'r': + reboot(RB_AUTOBOOT); + return 0; + + default: + printf("pow r[eboot]|p[oweroff]|s[hutdown]\n"); + return 1; + } +} diff --git a/altools/dae b/altools/dae new file mode 100755 index 0000000..7ea2962 --- /dev/null +++ b/altools/dae @@ -0,0 +1,18 @@ +#!/bin/sh + +########################### +# DAE, the deamon manager # +########################### + +function daemonctl(){ + case $1 in + stop) . /etc/al/serivces/$2.alsysd + stop ;; + start) . /etc/al/services/$2.alsysd + start ;; + esac + case $2 in + --verbose) set -x ;; + *) ;; + esac +} diff --git a/altools/mkinitramfs b/altools/mkinitramfs new file mode 100755 index 0000000..a87b925 --- /dev/null +++ b/altools/mkinitramfs @@ -0,0 +1,13 @@ +#!/bin/sh + +############### +# MKINITRAMFS # +############### + +if [ ! -d /usr/src/initramfs ]; then + mkdir -p /usr/src/initramfs/{bin,dev,etc,lib,lib64,mnt/root,proc,root,sbin,sys} + cp --archive /dev/{null,console,tty,sd*} /usr/src/initramfs/dev/ + cp --archive /bin/busybox /usr/src/initramfs/bin/busybox +fi +cd /usr/src/initramfs +find . -print0 | cpio --null --create --verbose --format=newc | gzip --best > /boot/initramfs.cpio.gz diff --git a/altools/pow b/altools/pow new file mode 100755 index 0000000000000000000000000000000000000000..262d61bdf4b0df57db6718d614c1af8530eee732 GIT binary patch literal 16232 zcmeHOZ)_CD6`wof-~?D30_g=OVId$H5+61J*C}z?vwiluI=}%#5*f3ceQW#L``5d@ zVn?*KwB~B zo%fb=)IU=CWuJBToA;adX5PM?UC-Xmd_5fL@%wy&rAB;Spf=xNGa6MCKT8DwO|*+u z@O_uKQ``jlGRfKXnhj8E%Xxn#))8L=h<*VqRKYuJS}<~ii0HSJ%wj+wjDn5>{c5p- zbT^t5CnMLF`%}>wM3vuVJcb4!j7~ocrPwU1MX{q2k5PZ)gzSeZ`duNvE9A#GPyI1+ zJ~1cwX{UU;QG+@ZO@0gE_M0F-H+GXfBldxE@S+v_Z~E&eziw4FBiy*trUfJS_aOMu zsU?d~20qOPsK2GoLxA$nNa+>Z6Y=4;o!b+!=0rS|pJ<+FZ)Yoi7CH9!315ZoCml?rpzT`tVA|0?wP^Ta(`Yd}Dv$=|j&whc#we$^8E)+P8P@G5-VvKfeK?VkW%bsK|@=e(Nz zI^Z`|u@{-Vl@nQWIGwh{m}!~$cuW|^$VAi_ji;iC_@k!CO{PYGgEKs0xJ~p%`Z~Le9l;&JUBc)a*lWbhtT`6XS!Q-%Z&xCnG6$l=2@~2FOQuuQhGCml zHN-&u@(Wq{ zHtFDfc^U9B;AOzefR_O;16~Ha4E#qKc(4AhkM-%d>-1B#f7&jDesb3Gm(J?bzp9&) z?UZ)C33O@81^BMtpg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WNWM|)2LgiyJ`!HDJ3#&|Rp!_5zU`@t#}PZ{}~ z8IzkTTn&}O$Miv4!?_%_EB9L%25hF_4B{?}s#_=QtsJhFo!dDoszfk1nY5zAfL7MV zaW2JEuzw>Xf^xKtrSic{Hk~oE)}(_P&c|WP4{RB+twNoB%{U%|Xg(gzjf-GxG6h}O zXl3o1ubA0fJe{gg45-VRi6}ZyDU+~7Q05|NnG;aP5eRi@d8&fuIE}gS82GYgd)R}| z_TVx!98JbYpjY^v9>0RJ1G_QEwFtsBkc6RKzSjPS0?zl~Rsi>OTLSd|nUUvvR4r|} zjEMiwoO?jp$)8a}BZu((i>Wp!IQ=KcpAp{=IEC-0%=JOR>Cf{EMwJZ--Tn^&{~^rT z`1pAq%gD#idsf`>N5LQGu%_(98F`)zCQ`5sr+gU{ zoRhLY&qEpceGJFXc8p&Gf1Km8&huPGl{$0BPqdhU0_K$cd7jNUONQLP`}m(E|4y>w zd3zZh{xBQ4A%8yr4s*io^jFD`vEOM7Wmog!hc18qKg)R0 zb;8)6n|;>h&(CFy{Jh5Y?(zE*^5^^ul`ILnNM+#sv;GSxV2JGBt=ct=_-@WA?*3nf zN~iyXYFjfFoz75p_x}gr6!_3(U!E`XzD~D2>x?+Bt#|nI{CuGqND#KOwMCuzzd;3# z9qym!&Ad-{p3WbRe-!rP^Y}h+Xu|%yAMZR(%$m^2A?(li5!5;Tg+|6LHnx+>z\e[39m $1" +} +function wrn(){ + echo -e "\e[34m==>\e[33m WARNING:\e[39m $1" +} +function err(){ + echo -e "\e[34m==>\e[31m ERROR:\e[39m $1" && + rm ${lock} 2>&1 > /dev/null && exit 2 } -confirm(){ - echo -ne "Are you sure? [Y/n] " - read prompt - if [[ ${prompt} = [nN] ]]; then - die "User said no. Exiting..." - elif [[ ${prompt} != [yY] ]]; then - die "User gave invalid input. Exiting..." - fi +function notf(){ + echo -e "\e[34m==>\e[36m NOTIFICATION:\e[39m $1" } -run_package_script() { - { - if [ -x "${2}/${1}" ]; then - echo ":: Running ${1}" - #cd "${2}" || die "Could not enter package working directory. Exiting..." - "${2}/${1}" "${2}/payload" "${2}" - fi - } +function dbg(){ + wrn "THIS IS A DEBUG TEST BUILD, IT MAY NOT WORK, IT'S GLITCHY AS FUCK!" } -install_local_package() { - [ ! -e "${1}" ] && die "File ${1} does not exist. Exiting..." - # Extract the package - confirm - echo ":: Installing package ${1}" - cp -prv "${1}" "${temp_location}" - pkg_name="${1%/}" - pkg_name="${pkg_name##*/}" - pkg_name=$(echo "${pkg_name}" | cut -f 1 -d '.') - pkg_path="${temp_location}/${pkg_name}" - cd "${pkg_path}" || die "Could not enter package path." - # Set default values for package - pkg_config_deploy=true - pkg_config_ver="0" - pkg_config_makedepends="" - pkg_config_depends="" - # Download sources. - if [ -f sources ]; then - pkg_config_sources=$(cat sources) - pkg_config_sources_to=$(echo ${pkg_config_sources} | sed 's:.*/::') - curl -# ${pkg_config_sources} -o ${pkg_config_sources_to} - mkdir pkg_bd - tar -xf 1 ${pkg_config_sources_to} -C ${pkg_path} - fi - # Install package - mkdir -p "${pkg_path}/payload" - . "${pkg_path}/package" - cd pkg_bd/ - run_package_script "build" "${pkg_path}" - cd ../.. - run_package_script "predeploy" "${pkg_path}" - # Deploy package - if [ "${pkg_config_deploy}" = true ]; then - echo ":: Deploying target ${pkg_name}..." - cp -rpv "${pkg_path}/payload"/* "${install_root}" > "${temp_location}/${pkg_name}-payloaddeploylog" - sed 's/^.*-> //' "${temp_location}/${pkg_name}-payloaddeploylog" | tr -d \'\" > "${temp_location}/${pkg_name}-payloadfiles" - rm "${temp_location}/${pkg_name}-payloaddeploylog" - fi - run_package_script "postdeploy" "${pkg_path}" - # Add package to database - if [ -x "${pkg_path}/package" ]; then - echo ":: Adding target ${pkg_name} to installed package database..." - [ ! -d "${installed_pkg_database}/${pkg_name}" ] && mkdir "${installed_pkg_database}/${pkg_name}" - cp -pv "${pkg_path}/package" "${installed_pkg_database}/${pkg_name}/package" - [ -e "${temp_location}/${pkg_name}-payloadfiles" ] && cp -pv "${temp_location}/${pkg_name}-payloadfiles" "${installed_pkg_database}/${pkg_name}/payloadfiles" - else - die "Target ${pkg_name} does not have a package script (it's an invalid package!). Exiting..." - fi - # Cleanup - rm -r "${pkg_path}" - rm "${temp_location}/${pkg_name}-payloadfiles" - cd "${install_root}" || die "Could not return to main directory. Exiting..." - unset pkg_path - unset pkg_name - unset pkg_config_deploy - unset pkg_config_ver - unset pkg_config_makedepends - unset pkg_config_depends - echo "[*] Install complete for package ${pkg_name}" -} -sync_deps(){ - confirm - echo ":: Syncing dependencies for ${1}" - install_package_from_repo "${pkg_makedepends}" - install_package_from_repo "${pkg_deps}" - echo "[*] Install dependencies for ${1}" +function pkg_find(){ + # i could not even bother, i had to copy kiss in some sense + set -- "$1" "$2" "$3" "${4:-"$AL_REPO"}" + IFS=: -} -remove_local_package() { - confirm - echo ":: Removing target ${1}..." - pkg_path="${installed_pkg_database}/${1}" - [ ! -d "${pkg_path}" ] && die "Package could not be found in local installed package database. Exiting..." - payloadfiles_path="${pkg_path}/payloadfiles" - [ ! -e "${payloadfiles_path}" ] && die "[E] Package ${1} does not have a payloadfiles file. Exiting..." - rm -rv "$(cat ${payloadfiles_path})" - rm -rv "${pkg_path}" - echo "[*] Removal complete for target ${pkg_name}" -} -sync_local_repo_database() { - echo ":: Syncing local database for repo ${1}" - if [ ! -d "${locpkg_database}/${1}" ]; then - # Local database for repo doesnt exists - clone it - git clone "${2}" "${locpkg_database}/${1}" - else - # Local database for repo already exists - sync it - cd "${locpkg_database}/${1}" || die "Could not enter local database directory. Exiting..." - git pull - fi -} -install_package_from_repo() { # NOTE(hippoz): This can get a tad confusing... ${1} is the repo and ${2} is the package - echo ":: Installing package ${2} from ${1} repo" - [ ! -d "${locpkg_database}/${1}/${2}" ] && die "Target not found." - install_local_package "${locpkg_database}/${1}/${2}" -} -upgrade() { - confirm - echo ":: Upgrading installed packages" - cd "${installed_pkg_database}" || die "Could not enter local installed package database directory. Exiting..." - for pkg in */; do - installed_pkg_path="${installed_pkg_database}/${pkg}" - . "${installed_pkg_path}/package" - pkg_name="${installed_pkg_path%/}" - pkg_name="${pkg_name##*/}" - already_installed_version=${pkg_config_ver} - [ ! -d "${locpkg_database}/${1}/${pkg_name}" ] && die "Package ${pkg_name} was not found in ${1}. Exiting..." - . "${locpkg_database}/${1}/${pkg_name}/package" - if [ ! "${already_installed_version}" = "${pkg_config_ver}" ]; then - echo ":: Updating package ${pkg_name} (out of date)" - install_package_from_repo "${1}" "${pkg_name}" - fi - unset pkg_config_deploy - unset pkg_config_ver - unset pkg_config_makedepends - unset pkg_config_depends + for _find_path in $4 "${3:-$sys_db}"; do set +f + for _find_pkg in "$_find_path/"$1; do + test "${3:--d}" "$_find_pkg" && set -f -- "$@" "$_find_pkg" + done done + + unset IFS + # alnux search i guess + #case $2-$# in + # *-4) return 1 ;; + # -*) repo_dir=$5; repo_name=${5##*/} ;; + # *) shift 4; printf '%s\n' "$@" + #esac } -version(){ - echo "Alnux APS v0.0.8.1" -} -help(){ - echo "Alnux APS, the packaging system for Alnux." - echo "" - echo "sync - Synchronizes from package repository." - echo "install - Installs from local package information file and build file." - echo "upgrade - Upgrades from package repository." - echo "remove - Removes a package from /var/aps/installed and it's install files (payloadfiles)." - echo "list - Lists currently installed packages." - echo "help - Display this message." - echo "version - Display the version." -} -list(){ - ls ${installed_pkg_database} | sed 's/^README.md//g' -} -main() { - if [ -f "${lock}" ]; then - echo "A lock file already exists (another instance of the package manager could be running). If you're sure no package manager is running, remove the file ${lock}." - exit 1 +function pkg_local(){ + if [ -z "$AL_REPO" ]; then + wrn "Alnux Repo variable is not set, Setting to /var/db/repo/core!" + prn "To set the Alnux Repo var, either:" + prn " edit /etc/profile or your shell's profile to include your repo and sub-repos, " + prn " much like this: export AL_REPO=/var/db/repo/core:/var/db/repo/extra OR" + prn " export Alnux Repo var like this: export AL_REPO=/var/db/repo/core:/var/db/repo/extra" + export AL_REPO=/var/db/repo/core + notf "AL_REPO set to /var/db/repo/core" + fi - touch "${lock}" - case ${1} in - install) install_local_package "${2}" ;; - remove) remove_local_package "${2}" ;; - #sync-dep) - # sync_local_repo_database "official" ${official} - # [ -z "${2}" ] && exit 0 - # install_package_from_repo "official" "${2}" ;; - sync) - sync_local_repo_database "official" ${official} - [ -z "${2}" ] && exit 0 - install_package_from_repo "official" "${2}" ;; - upgrade) upgrade "official" ;; - help) help ;; - version) version ;; - list) list ;; - *) die "Invalid option ${1}, exiting..." ;; - esac - rm "${lock}" + pkg_find $@ } -main "${1}" "${2}" +function help(){ + prn "APS Version 0.1.0" + prn "h|help) prints this message" + prn "v|version) version" + prn "s|sync) install package(s)" + prn "u|update) update" + prn "i|install) install LOCAL package(s)" +} +function version(){ + prn "APS Version 0.1.0" +} +function main(){ + dbg + case $1 in + s|sync) pkg_local $@ ;; + v|version) version ;; + h|help) help ;; + *) err "Invalid option" + esac +} +main $1 \ No newline at end of file diff --git a/aps.old b/aps.old new file mode 100755 index 0000000..2601f09 --- /dev/null +++ b/aps.old @@ -0,0 +1,208 @@ +#!/bin/sh + +################################# +# Alnux Packaging System, # +# the package manager for Alnux # +################################# + +if [ -f "$XDG_CONFIG_HOME/al/config" ]; then + . $XDG_CONFIG_HOME/al/config +elif [ -f "$HOME/.config/al/config" ]; then + . $HOME/.config/al/config +elif [ -f "/etc/al/config" ]; then + . /etc/al/config +else + temp_location="/var/tmp" + install_root="/var/tmp/alroot" + installed_pkg_database="${install_root}/var/aps/installed" + locpkg_database="${install_root}/var/aps/repos" + lock="${install_root}/var/aps/lock" + official="https://git.hippoz.xyz/alnux/repo" + debug=off +fi +if [ ${debug} = on ]; then + set -x +fi +die() { + echo "aps: fatal: ${1}" + rm "${lock}" + exit 2 +} +confirm(){ + echo -ne "Are you sure? [Y/n] " + read prompt + if [[ ${prompt} = [nN] ]]; then + die "User said no. Exiting..." + elif [[ ${prompt} != [yY] ]]; then + die "User gave invalid input. Exiting..." + fi +} +run_package_script() { + { + if [ -x "${2}/${1}" ]; then + echo ":: Running ${1}" + #cd "${2}" || die "Could not enter package working directory. Exiting..." + "${2}/${1}" "${2}/payload" "${2}" + fi + } +} +install_local_package() { + [ ! -e "${1}" ] && die "File ${1} does not exist. Exiting..." + # Extract the package + confirm + echo ":: Installing package ${1}" + cp -prv "${1}" "${temp_location}" + pkg_name="${1%/}" + pkg_name="${pkg_name##*/}" + pkg_name=$(echo "${pkg_name}" | cut -f 1 -d '.') + pkg_path="${temp_location}/${pkg_name}" + cd "${pkg_path}" || die "Could not enter package path." + # Set default values for package + pkg_config_deploy=true + pkg_config_ver="0" + pkg_config_makedepends="" + pkg_config_depends="" + # Download sources. + if [ -f sources ]; then + pkg_config_sources=$(cat sources) + pkg_config_sources_to=$(echo ${pkg_config_sources} | sed 's:.*/::') + curl -# ${pkg_config_sources} + mkdir pkg_bd + tar -xf 1 ${pkg_config_sources_to} -C ${pkg_path} + fi + # Install package + mkdir -p "${pkg_path}/payload" + . "${pkg_path}/package" + cd pkg_bd/ + run_package_script "build" "${pkg_path}" + cd ../.. + run_package_script "predeploy" "${pkg_path}" + # Deploy package + if [ "${pkg_config_deploy}" = true ]; then + echo ":: Deploying target ${pkg_name}..." + cp -rpv "${pkg_path}/payload"/* "${install_root}" > "${temp_location}/${pkg_name}-payloaddeploylog" + sed 's/^.*-> //' "${temp_location}/${pkg_name}-payloaddeploylog" | tr -d \'\" > "${temp_location}/${pkg_name}-payloadfiles" + rm "${temp_location}/${pkg_name}-payloaddeploylog" + fi + run_package_script "postdeploy" "${pkg_path}" + # Add package to database + if [ -x "${pkg_path}/package" ]; then + echo ":: Adding target ${pkg_name} to installed package database..." + [ ! -d "${installed_pkg_database}/${pkg_name}" ] && mkdir "${installed_pkg_database}/${pkg_name}" + cp -pv "${pkg_path}/package" "${installed_pkg_database}/${pkg_name}/package" + [ -e "${temp_location}/${pkg_name}-payloadfiles" ] && cp -pv "${temp_location}/${pkg_name}-payloadfiles" "${installed_pkg_database}/${pkg_name}/payloadfiles" + else + die "Target ${pkg_name} does not have a package script (it's an invalid package!). Exiting..." + fi + # Cleanup + rm -r "${pkg_path}" + rm "${temp_location}/${pkg_name}-payloadfiles" + cd "${install_root}" || die "Could not return to main directory. Exiting..." + unset pkg_path + unset pkg_name + unset pkg_config_deploy + unset pkg_config_ver + unset pkg_config_makedepends + unset pkg_config_depends + echo "[*] Install complete for package ${pkg_name}" +} +sync_deps(){ + confirm + echo ":: Syncing dependencies for ${1}" + install_package_from_repo "${pkg_makedepends}" + install_package_from_repo "${pkg_deps}" + echo "[*] Install dependencies for ${1}" + +} +remove_local_package() { + confirm + echo ":: Removing target ${1}..." + pkg_path="${installed_pkg_database}/${1}" + [ ! -d "${pkg_path}" ] && die "Package could not be found in local installed package database. Exiting..." + payloadfiles_path="${pkg_path}/payloadfiles" + [ ! -e "${payloadfiles_path}" ] && die "[E] Package ${1} does not have a payloadfiles file. Exiting..." + rm -rv "$(cat ${payloadfiles_path})" + rm -rv "${pkg_path}" + echo "[*] Removal complete for target ${pkg_name}" +} +sync_local_repo_database() { + echo ":: Syncing local database for repo ${1}" + if [ ! -d "${locpkg_database}/${1}" ]; then + # Local database for repo doesnt exists - clone it + git clone "${2}" "${locpkg_database}/${1}" + else + # Local database for repo already exists - sync it + cd "${locpkg_database}/${1}" || die "Could not enter local database directory. Exiting..." + git pull + fi +} +install_package_from_repo() { # NOTE(hippoz): This can get a tad confusing... ${1} is the repo and ${2} is the package + echo ":: Installing package ${2} from ${1} repo" + [ ! -d "${locpkg_database}/${1}/${2}" ] && die "Target not found." + install_local_package "${locpkg_database}/${1}/${2}" +} +upgrade() { + confirm + echo ":: Upgrading installed packages" + cd "${installed_pkg_database}" || die "Could not enter local installed package database directory. Exiting..." + for pkg in */; do + installed_pkg_path="${installed_pkg_database}/${pkg}" + . "${installed_pkg_path}/package" + pkg_name="${installed_pkg_path%/}" + pkg_name="${pkg_name##*/}" + already_installed_version=${pkg_config_ver} + [ ! -d "${locpkg_database}/${1}/${pkg_name}" ] && die "Package ${pkg_name} was not found in ${1}. Exiting..." + . "${locpkg_database}/${1}/${pkg_name}/package" + if [ ! "${already_installed_version}" = "${pkg_config_ver}" ]; then + echo ":: Updating package ${pkg_name} (out of date)" + install_package_from_repo "${1}" "${pkg_name}" + fi + unset pkg_config_deploy + unset pkg_config_ver + unset pkg_config_makedepends + unset pkg_config_depends + done +} +version(){ + echo "Alnux APS v0.0.8.1" +} +help(){ + echo "Alnux APS, the packaging system for Alnux." + echo "" + echo "sync - Synchronizes from package repository." + echo "install - Installs from local package information file and build file." + echo "upgrade - Upgrades from package repository." + echo "remove - Removes a package from /var/aps/installed and it's install files (payloadfiles)." + echo "list - Lists currently installed packages." + echo "help - Display this message." + echo "version - Display the version." +} +list(){ + ls ${installed_pkg_database} | sed 's/^README.md//g' +} +main() { + if [ -f "${lock}" ]; then + echo "A lock file already exists (another instance of the package manager could be running). If you're sure no package manager is running, remove the file ${lock}." + exit 1 + fi + touch "${lock}" + case ${1} in + install) install_local_package "${2}" ;; + remove) remove_local_package "${2}" ;; + #sync-dep) + # sync_local_repo_database "official" ${official} + # [ -z "${2}" ] && exit 0 + # install_package_from_repo "official" "${2}" ;; + sync) + sync_local_repo_database "official" ${official} + [ -z "${2}" ] && exit 0 + install_package_from_repo "official" "${2}" ;; + upgrade) upgrade "official" ;; + help) help ;; + version) version ;; + list) list ;; + *) die "Invalid option ${1}, exiting..." ;; + esac + rm "${lock}" +} +main "${1}" "${2}"