2019-05-09 00:46:50 -06:00
|
|
|
#!/bin/sh
|
2019-05-09 06:42:57 -06:00
|
|
|
# shellcheck disable=2094,2103 source=/dev/null
|
2019-05-09 00:46:50 -06:00
|
|
|
#
|
|
|
|
# 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() {
|
2019-05-09 06:42:57 -06:00
|
|
|
cd "$old_pwd/repo/$name"
|
|
|
|
rm -rf -- "$mak_dir" "$pkg_dir" .checksums
|
2019-05-09 00:46:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
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."
|
|
|
|
|
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-09 02:52:34 -06:00
|
|
|
pkg=$name-$version-$release
|
2019-05-09 00:46:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pkg_depends() {
|
|
|
|
while read -r dependency; do
|
|
|
|
# TODO: Handle dependencies.
|
|
|
|
log "Found dependency $dependency"
|
|
|
|
done < depends
|
|
|
|
}
|
|
|
|
|
|
|
|
pkg_sources() {
|
2019-05-09 06:42:57 -06:00
|
|
|
while read -r src; do
|
|
|
|
src_name=${src##*/}
|
2019-05-09 00:46:50 -06:00
|
|
|
|
2019-05-09 06:42:57 -06:00
|
|
|
if [ -f "$src" ]; then
|
2019-05-09 00:46:50 -06:00
|
|
|
continue
|
|
|
|
|
2019-05-09 06:42:57 -06:00
|
|
|
elif [ -f "$src_dir/$src_name" ]; then
|
|
|
|
log "Found cached $src_name."
|
2019-05-09 00:46:50 -06:00
|
|
|
continue
|
|
|
|
|
2019-05-09 06:42:57 -06:00
|
|
|
elif [ -z "${src##*://*}" ]; then
|
|
|
|
log "Downloading '$src'."
|
|
|
|
wget -P "$src_dir" "$src" || die "Failed to download $src."
|
2019-05-09 00:46:50 -06:00
|
|
|
|
|
|
|
else
|
2019-05-09 06:42:57 -06:00
|
|
|
die "Source file '$src' not found."
|
2019-05-09 00:46:50 -06:00
|
|
|
fi
|
|
|
|
done < sources
|
|
|
|
}
|
|
|
|
|
2019-05-09 06:42:57 -06:00
|
|
|
pkg_checksum() {
|
|
|
|
while read -r src; do
|
|
|
|
src_name=${src##*/}
|
|
|
|
|
|
|
|
if [ -f "$src" ]; then
|
|
|
|
src_path=$src
|
|
|
|
|
|
|
|
elif [ -f "$src_dir/$src_name" ]; then
|
|
|
|
src_path=$src_dir/$src_name
|
|
|
|
fi
|
|
|
|
|
|
|
|
cd "${src_path%/*}"
|
|
|
|
sha256sum -- "$src_name" || die "Failed to generate checksums."
|
|
|
|
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-09 00:46:50 -06:00
|
|
|
pkg_extract() {
|
2019-05-09 06:42:57 -06:00
|
|
|
while read -r src; do
|
|
|
|
src_name=${src##*/}
|
|
|
|
|
|
|
|
if [ -f "$src" ]; then
|
|
|
|
cp -f "$src" "$mak_dir"
|
2019-05-09 00:46:50 -06:00
|
|
|
|
2019-05-09 06:42:57 -06:00
|
|
|
elif [ ! -f "$src_dir/$src_name" ]; then
|
|
|
|
die "$src_name" not found.
|
2019-05-09 00:46:50 -06:00
|
|
|
|
2019-05-09 06:42:57 -06:00
|
|
|
else
|
|
|
|
case $src_dir/$src_name in
|
|
|
|
*.tar|*.tar.??|*.tar.???|*.tar.????|*.tgz)
|
|
|
|
tar xf "$src_dir/$src_name" -C "$mak_dir" \
|
|
|
|
--strip-components 1 ||
|
|
|
|
die "Couldn't extract $src_name"
|
|
|
|
;;
|
|
|
|
esac
|
2019-05-09 00:46:50 -06:00
|
|
|
fi
|
|
|
|
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-09 00:46:50 -06:00
|
|
|
set -e
|
|
|
|
. "$OLDPWD/build"
|
|
|
|
set +e
|
|
|
|
cd -
|
2019-05-09 02:30:43 -06:00
|
|
|
|
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"
|
|
|
|
|
|
|
|
cd -
|
2019-05-09 00:46:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
args() {
|
|
|
|
pkg_info "$2"
|
|
|
|
|
|
|
|
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-09 00:46:50 -06:00
|
|
|
;;
|
2019-05-09 06:42:57 -06:00
|
|
|
|
|
|
|
c*)
|
|
|
|
pkg_sources
|
|
|
|
pkg_checksum
|
|
|
|
|
|
|
|
log "Generated checksums."
|
|
|
|
;;
|
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-09 02:56:25 -06:00
|
|
|
mkdir -p sources build pkg sys bin ||
|
|
|
|
die "Couldn't create directories at '$PWD'".
|
2019-05-09 00:46:50 -06:00
|
|
|
|
2019-05-09 06:42:57 -06:00
|
|
|
old_pwd=$PWD
|
|
|
|
src_dir=$PWD/sources
|
|
|
|
mak_dir=$PWD/build
|
2019-05-09 00:46:50 -06:00
|
|
|
pkg_dir=$PWD/pkg
|
2019-05-09 02:30:43 -06:00
|
|
|
sys_dir=$PWD/sys
|
2019-05-09 02:56:25 -06:00
|
|
|
bin_dir=$PWD/bin
|
2019-05-09 00:46:50 -06:00
|
|
|
|
|
|
|
args "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|