2019-05-09 00:46:50 -06:00
|
|
|
#!/bin/sh
|
2019-05-10 08:10:54 -06:00
|
|
|
# shellcheck disable=2094,2103,SC2181 source=/dev/null
|
2019-05-09 00:46:50 -06:00
|
|
|
#
|
2019-05-10 05:41:55 -06:00
|
|
|
# puke - package manager for kiss linux.
|
2019-05-09 00:46:50 -06:00
|
|
|
|
|
|
|
die() {
|
|
|
|
printf '\033[31mERROR>\033[m %s\n' "$@" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
log() {
|
|
|
|
printf '\033[32m=>\033[m %s\n' "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
clean() {
|
2019-05-09 08:34:17 -06:00
|
|
|
rm -rf -- "$mak_dir" "$pkg_dir"
|
|
|
|
|
2019-05-12 01:31:18 -06:00
|
|
|
[ -n "$name" ] && {
|
2019-05-10 12:41:20 -06:00
|
|
|
rm "$rep_dir/$name/.checksums" 2>/dev/null
|
2019-05-12 01:31:18 -06:00
|
|
|
rm "$rep_dir/$name/.manifest" 2>/dev/null
|
|
|
|
}
|
2019-05-09 00:46:50 -06:00
|
|
|
}
|
|
|
|
|
2019-05-12 09:05:06 -06:00
|
|
|
pkg_setup() {
|
2019-05-12 01:31:18 -06:00
|
|
|
[ -z "$1" ] && die "No package specified."
|
|
|
|
cd "$rep_dir/$1" || die "Package '$1' not in repository."
|
|
|
|
[ -f version ] || die "Version file not found."
|
|
|
|
[ -f sources ] || die "Sources file not found."
|
|
|
|
[ -f build ] || die "Build file not found."
|
2019-05-09 00:46:50 -06:00
|
|
|
|
2019-05-09 02:52:34 -06:00
|
|
|
read -r version release < version
|
2019-05-09 02:30:43 -06:00
|
|
|
name=$1
|
2019-05-10 09:16:22 -06:00
|
|
|
pkg=$name\#$version-$release
|
2019-05-12 09:05:06 -06: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 00:46:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pkg_depends() {
|
2019-05-09 08:41:55 -06:00
|
|
|
[ -f depends ] && while read -r dependency; do
|
2019-05-10 05:40:19 -06:00
|
|
|
pkg_list "$dependency" || missing="$missing $dependency"
|
2019-05-09 00:46:50 -06:00
|
|
|
done < depends
|
2019-05-10 05:40:19 -06:00
|
|
|
|
|
|
|
[ -n "$missing" ] && die "Missing dependencies:$missing"
|
2019-05-09 00:46:50 -06:00
|
|
|
}
|
|
|
|
|
2019-05-12 07:50:52 -06:00
|
|
|
source_type() {
|
|
|
|
[ -f "$1" ] && return 2
|
|
|
|
[ -f "$src_dir/${1##*/}" ] && return 3
|
|
|
|
[ -z "${1##git:*}" ] && return 4
|
|
|
|
[ -z "${1##*://*}" ] && return 5
|
|
|
|
}
|
|
|
|
|
2019-05-09 00:46:50 -06:00
|
|
|
pkg_sources() {
|
2019-05-09 06:42:57 -06:00
|
|
|
while read -r src; do
|
2019-05-12 07:50:52 -06:00
|
|
|
source_type "$src"
|
2019-05-09 00:46:50 -06:00
|
|
|
|
2019-05-12 07:50:52 -06:00
|
|
|
case $? in
|
|
|
|
2|3) log "Found local ${src##*/}." ;;
|
|
|
|
4) git clone "${src##git:}" "$mak_dir" ;;
|
2019-05-09 08:34:17 -06:00
|
|
|
|
2019-05-12 07:50:52 -06:00
|
|
|
5) log "Downloading '$src'."
|
|
|
|
wget -P "$src_dir" "$src" || die "Failed to download $src." ;;
|
2019-05-09 00:46:50 -06:00
|
|
|
|
2019-05-12 07:50:52 -06:00
|
|
|
*) die "Source file '$src' not found." ;;
|
|
|
|
esac
|
2019-05-09 00:46:50 -06:00
|
|
|
done < sources
|
|
|
|
}
|
|
|
|
|
2019-05-09 06:42:57 -06:00
|
|
|
pkg_checksum() {
|
|
|
|
while read -r src; do
|
2019-05-12 07:50:52 -06:00
|
|
|
source_type "$src"
|
2019-05-09 06:42:57 -06:00
|
|
|
|
2019-05-12 07:50:52 -06:00
|
|
|
case $? in
|
|
|
|
2) src_path=$src ;;
|
|
|
|
3) src_path=$src_dir/${src##*/} ;;
|
|
|
|
4) continue ;;
|
|
|
|
esac
|
2019-05-09 06:42:57 -06:00
|
|
|
|
2019-05-10 12:20:32 -06:00
|
|
|
cd "${src_path%/*}" >/dev/null
|
2019-05-12 07:50:52 -06:00
|
|
|
sha256sum -- "${src##*/}" || die "Failed to generate checksums."
|
2019-05-09 06:42:57 -06:00
|
|
|
cd - >/dev/null
|
|
|
|
done < sources > "${1-checksums}"
|
|
|
|
}
|
|
|
|
|
|
|
|
pkg_verify() {
|
|
|
|
pkg_checksum .checksums
|
|
|
|
|
|
|
|
diff .checksums checksums ||
|
|
|
|
die "checksum of sources does not match checksum of package" \
|
|
|
|
"run '$0 checksum $name' to update checksums"
|
|
|
|
|
|
|
|
log "Checksums verified."
|
2019-05-10 00:59:06 -06:00
|
|
|
rm .checksums
|
2019-05-09 06:42:57 -06:00
|
|
|
}
|
|
|
|
|
2019-05-09 00:46:50 -06:00
|
|
|
pkg_extract() {
|
2019-05-09 06:42:57 -06:00
|
|
|
while read -r src; do
|
2019-05-12 07:50:52 -06:00
|
|
|
source_type "$src"
|
|
|
|
|
|
|
|
case $? in
|
|
|
|
2) cp -f "$src" "$mak_dir" ;;
|
|
|
|
4) continue ;;
|
|
|
|
|
|
|
|
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 00:46:50 -06:00
|
|
|
done < sources
|
|
|
|
}
|
|
|
|
|
|
|
|
pkg_build() {
|
2019-05-09 06:42:57 -06:00
|
|
|
log "Building $pkg."
|
2019-05-09 00:46:50 -06:00
|
|
|
|
2019-05-09 06:42:57 -06:00
|
|
|
cd "$mak_dir"
|
2019-05-12 08:01:04 -06:00
|
|
|
set -e errexit
|
2019-05-09 00:46:50 -06:00
|
|
|
. "$OLDPWD/build"
|
2019-05-12 08:01:04 -06:00
|
|
|
set +e errexit
|
2019-05-10 12:41:20 -06:00
|
|
|
cd "$rep_dir/$name"
|
2019-05-09 02:30:43 -06:00
|
|
|
|
2019-05-10 12:41:20 -06:00
|
|
|
cp -R "$rep_dir/$name" "$pkg_dir/$dbs_dir"
|
2019-05-12 01:31:18 -06:00
|
|
|
touch "$pkg_dir/$dbs_dir/$name/manifest"
|
|
|
|
|
2019-05-09 06:42:57 -06:00
|
|
|
log "Sucessfully built $pkg."
|
2019-05-09 02:30:43 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pkg_manifest() {
|
|
|
|
cd "$pkg_dir"
|
|
|
|
|
|
|
|
_() { find . -mindepth 1 "$@" | sed 's/^\.//'; }
|
|
|
|
_ -not -type d > "$OLDPWD/manifest"
|
|
|
|
_ -type d | sort -r >> "$OLDPWD/manifest"
|
|
|
|
|
2019-05-12 01:31:18 -06:00
|
|
|
cp "$OLDPWD/manifest" "$pkg_dir/$dbs_dir/$name"
|
2019-05-09 08:34:17 -06:00
|
|
|
cd - >/dev/null
|
2019-05-09 00:46:50 -06:00
|
|
|
}
|
|
|
|
|
2019-05-10 00:59:06 -06:00
|
|
|
pkg_tar() {
|
|
|
|
cd "$bin_dir"
|
|
|
|
|
|
|
|
tar pcvf "$pkg.tar.gz" -C "$pkg_dir" . ||
|
|
|
|
die "Failed to create package."
|
|
|
|
|
|
|
|
log "Package is at $bin_dir/$pkg.tar.gz."
|
|
|
|
}
|
|
|
|
|
2019-05-10 08:10:54 -06:00
|
|
|
pkg_install() {
|
2019-05-10 09:23:30 -06:00
|
|
|
[ -f "$bin_dir/$pkg.tar.gz" ] || die "Package must be built first."
|
|
|
|
|
2019-05-10 09:16:22 -06:00
|
|
|
pkg_remove "$name"
|
2019-05-10 09:21:19 -06:00
|
|
|
tar pxvf "$bin_dir/$pkg.tar.gz" -k -C "$sys_dir/" 2>/dev/null
|
2019-05-10 12:41:20 -06:00
|
|
|
|
|
|
|
[ -f "$sys_dir/$dbs_dir/$name/post-install" ] &&
|
|
|
|
. "$sys_dir/$dbs_dir/$name/post-install"
|
|
|
|
|
2019-05-10 08:10:54 -06:00
|
|
|
log "Installed $pkg"
|
|
|
|
}
|
|
|
|
|
|
|
|
pkg_remove() {
|
2019-05-10 09:16:22 -06:00
|
|
|
pkg_list "$name" || return 1
|
2019-05-10 08:10:54 -06:00
|
|
|
|
2019-05-12 01:31:18 -06:00
|
|
|
cp "$sys_dir/$dbs_dir/$name/manifest" .manifest
|
|
|
|
|
2019-05-10 08:10:54 -06:00
|
|
|
while read -r file; do
|
|
|
|
[ "${file%/*}" = "/etc" ] && continue
|
|
|
|
|
|
|
|
path="${sys_dir}${file}"
|
|
|
|
|
|
|
|
if [ -d "$path" ]; then
|
|
|
|
rmdir "$path" 2>/dev/null
|
2019-05-10 09:16:22 -06:00
|
|
|
else
|
2019-05-10 08:10:54 -06:00
|
|
|
rm -- "$path" || log "Failed to remove $file."
|
|
|
|
fi
|
|
|
|
|
|
|
|
[ "$?" = 0 ] && log "Removed $file"
|
2019-05-12 01:31:18 -06:00
|
|
|
done < .manifest
|
2019-05-10 09:16:22 -06:00
|
|
|
|
|
|
|
return 0
|
2019-05-10 08:10:54 -06:00
|
|
|
}
|
|
|
|
|
2019-05-10 11:21:41 -06:00
|
|
|
pkg_updates() {
|
2019-05-10 11:38:50 -06:00
|
|
|
git pull
|
2019-05-10 12:41:20 -06:00
|
|
|
cd "$sys_dir/$dbs_dir"
|
2019-05-10 11:21:41 -06:00
|
|
|
|
|
|
|
for pkg in *; do
|
|
|
|
read -r db_version db_release < "$pkg/version"
|
2019-05-10 12:41:20 -06:00
|
|
|
read -r re_version re_release < "$rep_dir/$pkg/version"
|
2019-05-10 11:21:41 -06:00
|
|
|
|
|
|
|
[ "$db_version-$db_release" != "$re_version-$re_release" ] &&
|
|
|
|
log "NEW $pkg $re_version-$re_release"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2019-05-10 05:40:19 -06:00
|
|
|
pkg_list() {
|
|
|
|
[ "$1" ] && {
|
2019-05-10 12:41:20 -06:00
|
|
|
[ -d "$sys_dir/$dbs_dir/$1" ] || return 1 && return 0
|
2019-05-10 05:40:19 -06:00
|
|
|
}
|
|
|
|
|
2019-05-10 12:41:20 -06:00
|
|
|
for pkg in "$sys_dir/$dbs_dir/"*; do
|
2019-05-10 09:20:02 -06:00
|
|
|
[ -d "$pkg" ] || continue
|
2019-05-10 05:40:19 -06:00
|
|
|
read -r version release < "$pkg/version"
|
|
|
|
log "${pkg##*/} $version-$release"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2019-05-09 00:46:50 -06:00
|
|
|
args() {
|
2019-05-12 09:05:06 -06:00
|
|
|
case $1 in b*|c*|d*|i*|r*) pkg_setup "$2"; esac
|
2019-05-09 00:46:50 -06:00
|
|
|
case $1 in
|
|
|
|
b*)
|
2019-05-09 06:42:57 -06:00
|
|
|
[ -f checksums ] || die "Checksums missing, run '$0 checksum $name'"
|
|
|
|
|
2019-05-09 00:46:50 -06:00
|
|
|
pkg_depends
|
|
|
|
pkg_sources
|
2019-05-09 06:42:57 -06:00
|
|
|
pkg_verify
|
2019-05-09 00:46:50 -06:00
|
|
|
pkg_extract
|
2019-05-09 02:30:43 -06:00
|
|
|
pkg_build
|
|
|
|
pkg_manifest
|
2019-05-10 00:59:06 -06:00
|
|
|
pkg_tar
|
2019-05-09 00:46:50 -06:00
|
|
|
;;
|
2019-05-09 06:42:57 -06:00
|
|
|
|
|
|
|
c*)
|
|
|
|
pkg_sources
|
|
|
|
pkg_checksum
|
|
|
|
|
|
|
|
log "Generated checksums."
|
|
|
|
;;
|
2019-05-10 03:28:03 -06:00
|
|
|
|
2019-05-10 11:02:47 -06:00
|
|
|
d*) [ -f depends ] && cat depends ;;
|
2019-05-10 08:10:54 -06:00
|
|
|
i*) pkg_install ;;
|
|
|
|
l*) pkg_list "$2" ;;
|
2019-05-10 09:16:22 -06:00
|
|
|
r*) pkg_remove || die "Package '$name' not installed" ;;
|
2019-05-10 11:21:41 -06:00
|
|
|
u*) pkg_updates ;;
|
2019-05-10 03:58:24 -06:00
|
|
|
|
2019-05-12 09:05:06 -06: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 00:46:50 -06:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
2019-05-09 06:42:57 -06:00
|
|
|
trap clean EXIT INT
|
2019-05-09 00:46:50 -06:00
|
|
|
clean
|
|
|
|
|
2019-05-10 12:41:20 -06:00
|
|
|
src_dir=$PWD/sources
|
|
|
|
mak_dir=$PWD/build
|
|
|
|
pkg_dir=$PWD/pkg
|
|
|
|
sys_dir=$PWD/sys
|
|
|
|
bin_dir=$PWD/bin
|
|
|
|
rep_dir=$PWD/repo
|
|
|
|
dbs_dir=var/db/puke
|
2019-05-09 00:46:50 -06:00
|
|
|
|
|
|
|
args "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|