2019-05-09 06:46:50 +00:00
|
|
|
#!/bin/sh
|
2019-05-13 13:29:20 +00:00
|
|
|
# shellcheck disable=2094,2103,2181,2188 source=/dev/null
|
2019-05-09 06:46:50 +00:00
|
|
|
#
|
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' "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
clean() {
|
2019-05-13 12:27:02 +00:00
|
|
|
rm -rf -- "$mak_dir" "$pkg_dir"
|
2019-05-09 06:46:50 +00:00
|
|
|
}
|
|
|
|
|
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 12:58:33 +00:00
|
|
|
read -r version release < version || die "Version file not found."
|
2019-05-13 07:32:16 +00:00
|
|
|
pkg=${name:=$1}\#$version-$release
|
2019-05-12 15:05:06 +00:00
|
|
|
|
2019-05-13 12:56:55 +00:00
|
|
|
mkdir -p "$src_dir" "$mak_dir" "$pkg_dir/$dbs_dir" "$sys_dir" "$bin_dir" ||
|
|
|
|
die "Couldn't create directories at $PWD."
|
2019-05-09 06:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pkg_depends() {
|
2019-05-13 12:21:39 +00:00
|
|
|
while read -r dependency; do
|
2019-05-10 11:40:19 +00:00
|
|
|
pkg_list "$dependency" || missing="$missing $dependency"
|
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-05-09 12:42:57 +00:00
|
|
|
while read -r src; do
|
2019-05-12 13:50:52 +00:00
|
|
|
source_type "$src"
|
2019-05-09 06:46:50 +00:00
|
|
|
|
2019-05-12 13:50:52 +00:00
|
|
|
case $? in
|
|
|
|
2|3) log "Found local ${src##*/}." ;;
|
|
|
|
4) git clone "${src##git:}" "$mak_dir" ;;
|
2019-05-09 14:34:17 +00:00
|
|
|
|
2019-05-12 13:50:52 +00:00
|
|
|
5) log "Downloading '$src'."
|
|
|
|
wget -P "$src_dir" "$src" || die "Failed to download $src." ;;
|
2019-05-09 06:46:50 +00:00
|
|
|
|
2019-05-12 13:50:52 +00:00
|
|
|
*) die "Source file '$src' not found." ;;
|
|
|
|
esac
|
2019-05-09 06:46:50 +00:00
|
|
|
done < sources
|
|
|
|
}
|
|
|
|
|
2019-05-09 12:42:57 +00:00
|
|
|
pkg_checksum() {
|
|
|
|
while read -r src; do
|
2019-05-12 13:50:52 +00:00
|
|
|
source_type "$src"
|
2019-05-09 12:42:57 +00:00
|
|
|
|
2019-05-12 13:50:52 +00:00
|
|
|
case $? in
|
|
|
|
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-13 07:43:49 +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-13 07:48:58 +00:00
|
|
|
die "Checksums of sources do not match checksums of package." \
|
|
|
|
"Run '$0 checksum $name' to update checksums"
|
2019-05-09 12:42:57 +00:00
|
|
|
|
|
|
|
log "Checksums verified."
|
|
|
|
}
|
|
|
|
|
2019-05-09 06:46:50 +00:00
|
|
|
pkg_extract() {
|
2019-05-09 12:42:57 +00:00
|
|
|
while read -r src; do
|
2019-05-12 13:50:52 +00:00
|
|
|
source_type "$src"
|
|
|
|
|
|
|
|
case $? in
|
|
|
|
2) cp -f "$src" "$mak_dir" ;;
|
2019-05-13 07:48:58 +00:00
|
|
|
4) ;;
|
2019-05-12 13:50:52 +00:00
|
|
|
|
|
|
|
3) case $src in
|
|
|
|
*.tar|*.tar.??|*.tar.???|*.tar.????|*.tgz)
|
|
|
|
tar xf "$src_dir/${src##*/}" -C "$mak_dir" \
|
|
|
|
--strip-components 1 ||
|
|
|
|
die "Couldn't extract ${src##*/}"
|
|
|
|
esac ;;
|
|
|
|
|
|
|
|
*) die "${src##*/} not found."
|
|
|
|
esac
|
2019-05-09 06:46:50 +00:00
|
|
|
done < sources
|
|
|
|
}
|
|
|
|
|
|
|
|
pkg_build() {
|
2019-05-09 12:42:57 +00:00
|
|
|
log "Building $pkg."
|
2019-05-09 06:46:50 +00:00
|
|
|
|
2019-05-13 12:37:14 +00:00
|
|
|
(set -e errexit; cd "$mak_dir"; "$OLDPWD/build" "$pkg_dir" ) ||
|
2019-05-12 15:13:02 +00:00
|
|
|
die "Build failed."
|
2019-05-09 08:30:43 +00:00
|
|
|
|
2019-05-10 18:41:20 +00:00
|
|
|
cp -R "$rep_dir/$name" "$pkg_dir/$dbs_dir"
|
2019-05-12 07:31:18 +00:00
|
|
|
|
2019-05-13 14:28:07 +00:00
|
|
|
log "Sucessfully built $pkg." 2> "$pkg_dir/$dbs_dir/$name/manifest"
|
2019-05-09 08:30:43 +00:00
|
|
|
}
|
|
|
|
|
2019-05-13 13:42:19 +00:00
|
|
|
pkg_manifest() {
|
|
|
|
find "$pkg_dir" -mindepth 1 | sed "s|^$pkg_dir||" | sort -r > manifest
|
|
|
|
cp manifest "$pkg_dir/$dbs_dir/$name"
|
|
|
|
}
|
2019-05-09 06:46:50 +00:00
|
|
|
|
2019-05-10 06:59:06 +00:00
|
|
|
pkg_tar() {
|
2019-05-13 13:46:19 +00:00
|
|
|
tar pcvf "$bin_dir/$pkg.tar.gz" -C "$pkg_dir" . ||
|
2019-05-10 06:59:06 +00:00
|
|
|
die "Failed to create package."
|
|
|
|
|
|
|
|
log "Package is at $bin_dir/$pkg.tar.gz."
|
|
|
|
}
|
|
|
|
|
2019-05-10 14:10:54 +00:00
|
|
|
pkg_install() {
|
2019-05-10 15:23:30 +00:00
|
|
|
[ -f "$bin_dir/$pkg.tar.gz" ] || die "Package must be built first."
|
|
|
|
|
2019-05-10 15:16:22 +00:00
|
|
|
pkg_remove "$name"
|
2019-05-10 15:21:19 +00:00
|
|
|
tar pxvf "$bin_dir/$pkg.tar.gz" -k -C "$sys_dir/" 2>/dev/null
|
2019-05-10 18:41:20 +00:00
|
|
|
|
|
|
|
[ -f "$sys_dir/$dbs_dir/$name/post-install" ] &&
|
2019-05-13 14:32:56 +00:00
|
|
|
"$sys_dir/$dbs_dir/$name/post-install"
|
2019-05-10 18:41:20 +00:00
|
|
|
|
2019-05-10 14:10:54 +00:00
|
|
|
log "Installed $pkg"
|
|
|
|
}
|
|
|
|
|
|
|
|
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-13 14:08:29 +00:00
|
|
|
if [ "${file%/*}" = "/etc" ]; then
|
|
|
|
continue
|
|
|
|
elif [ -d "$sys_dir$file" ]; then
|
2019-05-13 14:10:33 +00:00
|
|
|
rmdir "$sys_dir$file" 2>/dev/null ||:
|
2019-05-13 14:08:29 +00:00
|
|
|
else
|
|
|
|
rm -- "$sys_dir$file" || log "Failed to remove $file."
|
|
|
|
fi && log "Removed $file"
|
2019-05-13 12:26:21 +00:00
|
|
|
done < "$sys_dir/$dbs_dir/$name/manifest"
|
2019-05-10 14:10:54 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 17:21:41 +00:00
|
|
|
pkg_updates() {
|
2019-05-13 13:49:47 +00:00
|
|
|
for pkg in "$sys_dir/$dbs_dir/"*; do
|
|
|
|
read -r db_ver db_rel < "$pkg/version"
|
|
|
|
read -r re_ver re_rel < "$rep_dir/${pkg##*/}/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" ] &&
|
|
|
|
printf '%s\n' "${pkg##*/} $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-13 14:14:34 +00:00
|
|
|
[ "$1" ] && { [ -d "$sys_dir/$dbs_dir/$1" ]; return "$?"; }
|
2019-05-10 11:40:19 +00:00
|
|
|
|
2019-05-10 18:41:20 +00:00
|
|
|
for pkg in "$sys_dir/$dbs_dir/"*; do
|
2019-05-10 11:40:19 +00:00
|
|
|
read -r version release < "$pkg/version"
|
2019-05-13 07:35:39 +00:00
|
|
|
printf '%s\n' "${pkg##*/} $version-$release"
|
2019-05-10 11:40:19 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2019-05-09 06:46:50 +00:00
|
|
|
args() {
|
2019-05-13 12:31:38 +00:00
|
|
|
case $1 in b*|c*|d*|i*|r*) pkg_setup "${2-null}"; esac
|
2019-05-09 06:46:50 +00:00
|
|
|
case $1 in
|
|
|
|
b*)
|
2019-05-09 12:42:57 +00:00
|
|
|
[ -f checksums ] || die "Checksums missing, run '$0 checksum $name'"
|
|
|
|
|
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
|
|
|
|
pkg_manifest
|
2019-05-10 06:59:06 +00:00
|
|
|
pkg_tar
|
2019-05-09 06:46:50 +00:00
|
|
|
;;
|
2019-05-09 12:42:57 +00:00
|
|
|
|
|
|
|
c*)
|
|
|
|
pkg_sources
|
|
|
|
pkg_checksum
|
2019-05-13 14:36:15 +00:00
|
|
|
|
|
|
|
log "Generated checksums."
|
2019-05-09 12:42:57 +00:00
|
|
|
;;
|
2019-05-10 09:28:03 +00:00
|
|
|
|
2019-05-10 17:02:47 +00:00
|
|
|
d*) [ -f depends ] && cat depends ;;
|
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-12 15:05:06 +00:00
|
|
|
*) log "$0 [b|c|d|i|l|r|u] [pkg]" \
|
|
|
|
"build: Build a package." \
|
|
|
|
"checksum: Generate checksums." \
|
|
|
|
"depends: See package dependencies." \
|
|
|
|
"install: Install a package." \
|
|
|
|
"list: List packages." \
|
|
|
|
"remove: Remove a package." \
|
|
|
|
"update: Check for updates."
|
2019-05-09 06:46:50 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
2019-05-09 12:42:57 +00:00
|
|
|
trap clean EXIT INT
|
2019-05-09 06:46:50 +00:00
|
|
|
|
2019-05-10 18:41:20 +00:00
|
|
|
src_dir=$PWD/sources
|
|
|
|
mak_dir=$PWD/build
|
|
|
|
pkg_dir=$PWD/pkg
|
2019-05-13 13:57:08 +00:00
|
|
|
sys_dir=$PUKE_ROOT
|
2019-05-10 18:41:20 +00:00
|
|
|
bin_dir=$PWD/bin
|
|
|
|
rep_dir=$PWD/repo
|
|
|
|
dbs_dir=var/db/puke
|
2019-05-09 06:46:50 +00:00
|
|
|
|
|
|
|
args "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|