From 0cda243d535f11e7c26b9182bc63e425deb5ba45 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 9 May 2019 09:46:50 +0300 Subject: [PATCH] new package manager experiment --- .gitignore | 3 ++ puke | 108 ++++++++++++++++++++++++++++++++++++++++++++ repo/zlib/.checksum | 0 repo/zlib/.manifest | 21 +++++++++ repo/zlib/build | 7 +++ repo/zlib/depends | 0 repo/zlib/sources | 1 + repo/zlib/version | 1 + 8 files changed, 141 insertions(+) create mode 100644 .gitignore create mode 100755 puke create mode 100755 repo/zlib/.checksum create mode 100755 repo/zlib/.manifest create mode 100755 repo/zlib/build create mode 100644 repo/zlib/depends create mode 100644 repo/zlib/sources create mode 100644 repo/zlib/version diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..66e52240 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +build/* +pkg/* +sources/* diff --git a/puke b/puke new file mode 100755 index 00000000..dd4863b9 --- /dev/null +++ b/puke @@ -0,0 +1,108 @@ +#!/bin/sh +# shellcheck source=/dev/null +# +# pkg - package manager for kiss linux. + +die() { + printf '\033[31mERROR>\033[m %s\n' "$@" >&2 + exit 1 +} + +log() { + printf '\033[32m=>\033[m %s\n' "$@" +} + +clean() { + rm -rf "$build_dir" "$pkg_dir" +} + +pkg_info() { + [ -z "$1" ] && die "No package specified." + cd "repo/$1" || die "Package '$1' not in repository." + [ -f version ] || die "Version file not found." + [ -f depends ] || die "Depends file not found." + [ -f sources ] || die "Sources file not found." + + while read -r line; do version=$line; done < version +} + +pkg_depends() { + while read -r dependency; do + # TODO: Handle dependencies. + log "Found dependency $dependency" + done < depends +} + +pkg_sources() { + while read -r source; do + source_name=${source##*/} + + if [ -f "$source" ]; then + continue + + elif [ -f "$source_dir/$source_name" ]; then + log "Found cached $source_name." + continue + + elif [ -z "${source##*://*}" ]; then + log "Downloading '$source'." + wget -P "$source_dir" "$source" || die "Failed to download $source." + + else + die "Source file '$source' not found." + fi + done < sources +} + +pkg_extract() { + while read -r source; do + source_name=${source##*/} + + if [ -f "$source" ]; then + cp -f "$source" "$build_dir" + + elif [ -f "$source_dir/$source_name" ]; then + # TODO: Handle extraction based on file type. + tar xf "$source_dir/$source_name" -C "$build_dir" \ + --strip-components 1 || die "couldn't extract $source_name" + fi + done < sources +} + +pkg_build() { + log "Building $1-$version" + + cd "$build_dir" + set -e + . "$OLDPWD/build" + set +e + cd - +} + +args() { + pkg_info "$2" + + case $1 in + b*) + pkg_depends + pkg_sources + pkg_extract + pkg_build "$2" + ;; + esac +} + +main() { + trap clean EXIT + clean + + mkdir -p sources build pkg || die "Couldn't create directories at '$PWD'". + + source_dir=$PWD/sources + build_dir=$PWD/build + pkg_dir=$PWD/pkg + + args "$@" +} + +main "$@" diff --git a/repo/zlib/.checksum b/repo/zlib/.checksum new file mode 100755 index 00000000..e69de29b diff --git a/repo/zlib/.manifest b/repo/zlib/.manifest new file mode 100755 index 00000000..f85387a9 --- /dev/null +++ b/repo/zlib/.manifest @@ -0,0 +1,21 @@ +/usr/share/man/man3/zlib.3 +/usr/include/zconf.h +/usr/include/zlib.h +/var/db/pkg/zlib/version +/lib/libz.so.1.2.11 +/lib/libz.so.1 +/lib/libz.so +/lib/libz.a +/lib/pkgconfig/zlib.pc +/var/db/pkg/zlib/manifest +/var/db/pkg/zlib +/var/db/pkg +/var/db +/var +/usr/share/man/man3 +/usr/share/man +/usr/share +/usr/include +/usr +/lib/pkgconfig +/lib diff --git a/repo/zlib/build b/repo/zlib/build new file mode 100755 index 00000000..92cc458a --- /dev/null +++ b/repo/zlib/build @@ -0,0 +1,7 @@ +./configure \ + --prefix=/usr \ + --libdir=/lib \ + --shared + +make +make DESTDIR="$pkg_dir" install diff --git a/repo/zlib/depends b/repo/zlib/depends new file mode 100644 index 00000000..e69de29b diff --git a/repo/zlib/sources b/repo/zlib/sources new file mode 100644 index 00000000..17f901f4 --- /dev/null +++ b/repo/zlib/sources @@ -0,0 +1 @@ +https://zlib.net/zlib-1.2.11.tar.gz diff --git a/repo/zlib/version b/repo/zlib/version new file mode 100644 index 00000000..c1147005 --- /dev/null +++ b/repo/zlib/version @@ -0,0 +1 @@ +1.2.11