iglunix/lazy.sh

61 lines
1.1 KiB
Bash
Raw Normal View History

2021-01-02 18:24:06 +00:00
#!/bin/sh
usage() {
echo $(basename "$0"): ERROR: "$@" 1>&2
2021-01-03 13:54:48 +00:00
echo usage: $(basename "$0") '([-i]|[-u]|[-f]|[-l]) [-o root]
2021-01-02 18:24:06 +00:00
[pkg.tar]' 1>&2
exit 1
}
tar_fail() {
echo "Failed to extract tar"
exit 1
}
stat_fail() {
echo "Not a valid package"
echo "Missing package meta file"
2021-01-03 13:54:48 +00:00
exit 1
}
find_fail() {
echo "Package not installed"
exit 1
2021-01-02 18:24:06 +00:00
}
2021-01-03 13:54:48 +00:00
i= u= l= f= o=
2021-01-02 18:24:06 +00:00
case "$1" in
-i) i=1;;
-u) u=1;;
2021-01-03 13:54:48 +00:00
-l) l=1;;
-f) f=1;;
2021-01-02 18:24:06 +00:00
*) usage "bad argument $i";;
esac
shift
while :
do
case "$1" in
-o) shift; o="$1";;
--) shift; break;;
-*) usage "bad argument $1";;
*) break;;
esac
shift
done
if [ "$i" = "1" ]; then
echo "Installing $1"
mkdir -p /tmp/lazybox/$1 || exit 1
tar -xf $1 -C /tmp/lazybox/$1 || tar_fail
stat /tmp/lazybox/$1/usr/share/lazypkg/ >/dev/null || stat_fail
2021-01-02 18:24:06 +00:00
tar -xf $1 -C /
rm -r /tmp/lazybox/$1
2021-01-03 13:54:48 +00:00
elif [ "$f" = "1" ]; then
stat /usr/share/lazypkg/$1 > /dev/null || find_fail
sed -n '/\[fs\]/,$p' /usr/share/lazypkg/$1 | grep -v "\[fs\]"
2021-01-03 13:54:48 +00:00
elif [ "$l" = "1" ]; then
stat /usr/share/lazypkg/$1 > /dev/null || find_fail
sed -n '/\[license\]/,/\[fs\]/{/\[license\]\|\[fs\]/!p}' /usr/share/lazypkg/$1
2021-01-02 18:24:06 +00:00
fi