2019-05-09 06:46:50 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2019-05-10 11:41:55 +00:00
|
|
|
# puke - package manager for kiss linux.
|
2019-05-09 06:46:50 +00:00
|
|
|
|
|
|
|
die() {
|
|
|
|
printf '\033[31mERROR>\033[m %s\n' "$@" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
log() {
|
|
|
|
printf '\033[32m=>\033[m %s\n' "$@"
|
|
|
|
}
|
|
|
|
|
2019-05-13 08:42:11 +00:00
|
|
|
source_type() {
|
|
|
|
[ -f "$1" ] && return 2
|
|
|
|
[ -f "$src_dir/${1##*/}" ] && return 3
|
|
|
|
[ -z "${1##git:*}" ] && return 4
|
|
|
|
[ -z "${1##*://*}" ] && return 5
|
|
|
|
}
|
|
|
|
|
2019-05-12 15:05:06 +00:00
|
|
|
pkg_setup() {
|
2019-05-12 07:31:18 +00:00
|
|
|
cd "$rep_dir/$1" || die "Package '$1' not in repository."
|
|
|
|
[ -f sources ] || die "Sources file not found."
|
2019-05-13 12:37:14 +00:00
|
|
|
[ -x build ] || die "Build file not found or not executable."
|
2019-05-09 06:46:50 +00:00
|
|
|
|
2019-05-13 16:00:10 +00:00
|
|
|
read -r ver rel < version || die "Version file not found."
|
2019-05-15 08:43:23 +00:00
|
|
|
pkg=${name:=$1}\#$ver-$rel.tar.gz
|
2019-05-09 06:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pkg_depends() {
|
2019-05-13 15:34:28 +00:00
|
|
|
while read -r dep; do
|
|
|
|
pkg_list "$dep" || missing="$missing $dep"
|
2019-05-13 12:21:39 +00:00
|
|
|
done 2>/dev/null < depends
|
2019-05-10 11:40:19 +00:00
|
|
|
|
|
|
|
[ -n "$missing" ] && die "Missing dependencies:$missing"
|
2019-05-09 06:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pkg_sources() {
|
2019-06-12 18:04:33 +00:00
|
|
|
while read -r src _; do
|
2019-05-16 07:35:11 +00:00
|
|
|
case $(source_type "$src"; echo $?) in
|
2019-05-16 17:05:27 +00:00
|
|
|
4) git clone "${src##git:}" "$mak_dir" ;;
|
|
|
|
5) wget -P "$src_dir" "$src" || die "Failed to download $src." ;;
|
2019-05-16 17:10:20 +00:00
|
|
|
0|1) die "Source file '$src' not found." ;;
|
2019-05-12 13:50:52 +00:00
|
|
|
esac
|
2019-05-09 06:46:50 +00:00
|
|
|
done < sources
|
|
|
|
}
|
|
|
|
|
2019-05-09 12:42:57 +00:00
|
|
|
pkg_checksum() {
|
2019-06-12 18:04:33 +00:00
|
|
|
while read -r src _; do
|
2019-05-16 07:35:11 +00:00
|
|
|
case $(source_type "$src"; echo $?) in
|
2019-05-12 13:50:52 +00:00
|
|
|
2) src_path=$src ;;
|
|
|
|
3) src_path=$src_dir/${src##*/} ;;
|
2019-05-13 12:55:11 +00:00
|
|
|
4) continue
|
2019-05-12 13:50:52 +00:00
|
|
|
esac
|
2019-05-09 12:42:57 +00:00
|
|
|
|
2019-05-14 20:09:18 +00:00
|
|
|
(cd "${src_path%/*}" >/dev/null; sha256sum "${src##*/}") ||
|
|
|
|
die "Failed to generate checksums."
|
2019-05-09 12:42:57 +00:00
|
|
|
done < sources > "${1-checksums}"
|
|
|
|
}
|
|
|
|
|
|
|
|
pkg_verify() {
|
2019-05-13 12:21:39 +00:00
|
|
|
pkg_checksum /dev/stdout | diff checksums - ||
|
2019-05-16 13:48:06 +00:00
|
|
|
die "Checksum mismatch, run '$0 checksum $name' to update checksums."
|
2019-05-09 12:42:57 +00:00
|
|
|
}
|
|
|
|
|
2019-05-09 06:46:50 +00:00
|
|
|
pkg_extract() {
|
2019-06-12 18:04:33 +00:00
|
|
|
while read -r src dest; do
|
2019-05-16 07:35:11 +00:00
|
|
|
case $(source_type "$src"; echo $?)-$src in
|
2019-05-14 19:49:42 +00:00
|
|
|
2-*) cp -f "$src" "$mak_dir" ;;
|
|
|
|
|
|
|
|
3-*.tar*)
|
2019-06-12 18:04:33 +00:00
|
|
|
tar xf "$src_dir/${src##*/}" -C "$mak_dir/$dest" \
|
|
|
|
--strip-components 1 || die "Couldn't extract ${src##*/}" ;;
|
2019-05-12 13:50:52 +00:00
|
|
|
|
2019-05-14 19:59:25 +00:00
|
|
|
[01]-*) die "${src##*/} not found."
|
2019-05-12 13:50:52 +00:00
|
|
|
esac
|
2019-05-09 06:46:50 +00:00
|
|
|
done < sources
|
|
|
|
}
|
|
|
|
|
|
|
|
pkg_build() {
|
2019-05-14 20:05:50 +00:00
|
|
|
(cd "$mak_dir"; "$OLDPWD/build" "$pkg_dir") || die "Build failed."
|
2019-05-16 13:45:08 +00:00
|
|
|
cp -Rf "$rep_dir/$name" "$pkg_db"
|
2019-05-15 08:43:23 +00:00
|
|
|
log "Sucessfully built $pkg." 2> "$pkg_db/$name/manifest"
|
2019-05-09 08:30:43 +00:00
|
|
|
}
|
|
|
|
|
2019-06-10 04:43:55 +00:00
|
|
|
pkg_strip() {
|
2019-06-12 18:06:50 +00:00
|
|
|
log "Stripping unneeded symbols from binaries and libraries."
|
2019-06-10 14:31:13 +00:00
|
|
|
|
2019-06-10 04:43:55 +00:00
|
|
|
find "$pkg_dir" -type f | while read -r binary; do
|
2019-06-10 14:31:13 +00:00
|
|
|
case $(file -bi "$binary") in
|
2019-06-10 04:43:55 +00:00
|
|
|
application/x-sharedlib*|application/x-pie-executable*)
|
2019-06-10 14:31:13 +00:00
|
|
|
strip_opts=--strip-unneeded
|
2019-06-10 04:43:55 +00:00
|
|
|
;;
|
2019-06-11 09:11:14 +00:00
|
|
|
|
|
|
|
application/x-archive*) strip_opts=--strip-debug ;;
|
2019-06-10 14:31:13 +00:00
|
|
|
application/x-executable*) strip_opts=--strip-all ;;
|
2019-06-11 09:11:14 +00:00
|
|
|
|
2019-06-10 10:53:30 +00:00
|
|
|
*) continue ;;
|
2019-06-10 04:43:55 +00:00
|
|
|
esac
|
2019-06-11 09:11:14 +00:00
|
|
|
|
2019-06-10 10:53:30 +00:00
|
|
|
strip "$strip_opts" "$binary"
|
2019-06-10 04:43:55 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2019-05-16 13:45:08 +00:00
|
|
|
pkg_manifest() {
|
|
|
|
(cd "$pkg_dir" && find ./*) | sed ss.ss | tac |
|
2019-05-15 08:43:23 +00:00
|
|
|
tee manifest > "$pkg_db/$name/manifest"
|
2019-05-16 13:45:08 +00:00
|
|
|
}
|
2019-05-09 06:46:50 +00:00
|
|
|
|
2019-05-10 06:59:06 +00:00
|
|
|
pkg_tar() {
|
2019-06-09 13:06:16 +00:00
|
|
|
tar zpcf "$bin_dir/$pkg" -C "$pkg_dir" . || die "Failed to create package."
|
2019-05-16 17:10:20 +00:00
|
|
|
log "Use '$0 install $name' to install the package."
|
2019-05-10 06:59:06 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 14:10:54 +00:00
|
|
|
pkg_install() {
|
2019-05-30 07:07:40 +00:00
|
|
|
[ -f "$bin_dir/$pkg" ] || args b "$name"
|
2019-05-10 15:23:30 +00:00
|
|
|
|
2019-05-10 15:16:22 +00:00
|
|
|
pkg_remove "$name"
|
2019-05-15 08:43:23 +00:00
|
|
|
tar pxvf "$bin_dir/$pkg" -k -C "$sys_dir/" 2>/dev/null
|
2019-05-10 18:41:20 +00:00
|
|
|
|
2019-05-15 08:43:23 +00:00
|
|
|
"$sys_db/$name/post-install" 2>/dev/null
|
2019-05-10 18:41:20 +00:00
|
|
|
|
2019-05-15 08:43:23 +00:00
|
|
|
log "Installed ${pkg%.tar.gz}"
|
2019-05-10 14:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pkg_remove() {
|
2019-05-10 15:16:22 +00:00
|
|
|
pkg_list "$name" || return 1
|
2019-05-10 14:10:54 +00:00
|
|
|
|
|
|
|
while read -r file; do
|
2019-05-14 19:31:44 +00:00
|
|
|
[ "${file%/*}" = "/etc" ] && continue
|
|
|
|
|
|
|
|
if [ -d "$sys_dir$file" ]; then
|
2019-05-14 15:58:03 +00:00
|
|
|
rmdir "$sys_dir$file" 2>/dev/null || continue
|
2019-05-13 14:08:29 +00:00
|
|
|
else
|
2019-05-16 17:31:49 +00:00
|
|
|
rm -f -- "$sys_dir$file" || log "Failed to remove $file."
|
2019-05-14 15:58:03 +00:00
|
|
|
fi && log "Removed $file"
|
2019-05-15 08:43:23 +00:00
|
|
|
done < "$sys_db/$name/manifest"
|
2019-05-10 14:10:54 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 17:21:41 +00:00
|
|
|
pkg_updates() {
|
2019-05-15 08:43:23 +00:00
|
|
|
for item in "$sys_db/"*; do
|
2019-05-13 16:08:38 +00:00
|
|
|
read -r db_ver db_rel < "$item/version"
|
|
|
|
read -r re_ver re_rel < "$rep_dir/${item##*/}/version"
|
2019-05-10 17:21:41 +00:00
|
|
|
|
2019-05-13 13:49:47 +00:00
|
|
|
[ "$db_ver-$db_rel" != "$re_ver-$re_rel" ] &&
|
2019-05-13 16:08:38 +00:00
|
|
|
printf '%s\n' "${item##*/} $re_ver-$re_rel"
|
2019-05-10 17:21:41 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2019-05-10 11:40:19 +00:00
|
|
|
pkg_list() {
|
2019-05-15 08:43:23 +00:00
|
|
|
[ "$1" ] && { [ -d "$sys_db/$1" ]; return "$?"; }
|
2019-05-10 11:40:19 +00:00
|
|
|
|
2019-05-15 08:43:23 +00:00
|
|
|
for item in "$sys_db/"*; do
|
2019-05-14 20:27:19 +00:00
|
|
|
read -r version release 2>/dev/null < "$item/version" &&
|
|
|
|
printf '%s\n' "${item##*/} $version-$release"
|
2019-05-10 11:40:19 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2019-05-09 06:46:50 +00:00
|
|
|
args() {
|
2019-05-16 07:04:34 +00:00
|
|
|
case $1 in b*|c*|i*|r*) pkg_setup "${2-null}"; esac
|
2019-05-09 06:46:50 +00:00
|
|
|
case $1 in
|
2019-05-14 13:10:12 +00:00
|
|
|
b*) [ -f checksums ] || die "Checksums missing, run '$0 checksum $name'"
|
2019-05-09 12:42:57 +00:00
|
|
|
|
2019-05-09 06:46:50 +00:00
|
|
|
pkg_depends
|
|
|
|
pkg_sources
|
2019-05-09 12:42:57 +00:00
|
|
|
pkg_verify
|
2019-05-09 06:46:50 +00:00
|
|
|
pkg_extract
|
2019-05-09 08:30:43 +00:00
|
|
|
pkg_build
|
2019-06-10 14:31:13 +00:00
|
|
|
[ -f nostrip ] || pkg_strip
|
2019-05-09 08:30:43 +00:00
|
|
|
pkg_manifest
|
2019-05-14 13:10:12 +00:00
|
|
|
pkg_tar ;;
|
2019-05-09 12:42:57 +00:00
|
|
|
|
2019-05-14 13:10:12 +00:00
|
|
|
c*) pkg_sources
|
2019-05-09 12:42:57 +00:00
|
|
|
pkg_checksum
|
2019-05-14 13:10:12 +00:00
|
|
|
log "Generated checksums." ;;
|
2019-05-10 09:28:03 +00:00
|
|
|
|
2019-05-10 14:10:54 +00:00
|
|
|
i*) pkg_install ;;
|
|
|
|
l*) pkg_list "$2" ;;
|
2019-05-10 15:16:22 +00:00
|
|
|
r*) pkg_remove || die "Package '$name' not installed" ;;
|
2019-05-10 17:21:41 +00:00
|
|
|
u*) pkg_updates ;;
|
2019-05-10 09:58:24 +00:00
|
|
|
|
2019-05-14 20:34:51 +00:00
|
|
|
*) log "$0 [b|c|i|l|r|u] [pkg]" \
|
2019-05-12 15:05:06 +00:00
|
|
|
"build: Build a package." \
|
|
|
|
"checksum: Generate checksums." \
|
2019-05-30 07:07:40 +00:00
|
|
|
"install: Install a package (Runs build when needed)." \
|
2019-05-12 15:05:06 +00:00
|
|
|
"list: List packages." \
|
|
|
|
"remove: Remove a package." \
|
|
|
|
"update: Check for updates."
|
2019-05-09 06:46:50 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
2019-05-14 20:39:28 +00:00
|
|
|
trap 'rm -rf -- "$mak_dir" "$pkg_dir"' EXIT INT
|
2019-05-09 06:46:50 +00:00
|
|
|
|
2019-05-16 07:25:08 +00:00
|
|
|
mkdir -p "${src_dir:=$PWD/sources}" \
|
|
|
|
"${mak_dir:=$PWD/build}" \
|
|
|
|
"${pkg_db:=${pkg_dir:=$PWD/pkg}/var/db/puke}" \
|
|
|
|
"${sys_db:=${sys_dir:=$PUKE_ROOT}/var/db/puke}" \
|
|
|
|
"${bin_dir:=$PWD/bin}" \
|
|
|
|
"${rep_dir:=$PWD/repo}" ||
|
|
|
|
die "Couldn't create directories at $PWD."
|
2019-05-09 06:46:50 +00:00
|
|
|
|
|
|
|
args "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|