2021-01-02 18:24:06 +00:00
|
|
|
#!/bin/sh
|
2021-02-17 19:04:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HELP="
|
|
|
|
-h This help window
|
|
|
|
--help alias to \`-h\`
|
|
|
|
|
|
|
|
-i install
|
|
|
|
-u uninstall
|
|
|
|
-l outputs the license
|
|
|
|
-f lists installed files
|
|
|
|
-d list dependencies
|
|
|
|
-iu install update or install upgrade
|
|
|
|
-ui alias to \`-iu\`
|
2021-04-13 13:02:13 +00:00
|
|
|
|
2021-04-12 17:22:25 +00:00
|
|
|
|
|
|
|
These needs iglunix-dev (iglupkg) installed
|
2021-04-13 13:02:13 +00:00
|
|
|
-b build
|
|
|
|
-bi build and install the current package
|
2021-04-12 17:22:25 +00:00
|
|
|
-biu build and install update the current package
|
|
|
|
-bui alias to \`-iu\`
|
2021-02-17 19:04:49 +00:00
|
|
|
|
|
|
|
NOT IMPLEMENTED:
|
|
|
|
-o root"
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-01-02 18:24:06 +00:00
|
|
|
usage() {
|
2021-05-21 08:27:37 +00:00
|
|
|
echo usage: $(basename "$0") '[-biu|-l|-f|-d|-h]' '[target]' "${HELP}" 1>&2
|
2021-01-02 18:24:06 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2021-02-17 19:04:49 +00:00
|
|
|
error_usage() {
|
|
|
|
echo $(basename "$0"): ERROR: "$@" 1>&2
|
|
|
|
usage
|
|
|
|
}
|
|
|
|
|
2021-01-02 18:24:06 +00:00
|
|
|
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-31 01:49:02 +00:00
|
|
|
continue_interactive() {
|
2021-02-03 13:03:52 +00:00
|
|
|
printf '%s' "Do you wish to proceed?: "
|
|
|
|
read yn
|
2021-01-31 01:49:02 +00:00
|
|
|
case $yn in
|
2021-02-03 13:03:52 +00:00
|
|
|
[Yy]* ) echo "Proceeding";;
|
2021-01-31 01:49:02 +00:00
|
|
|
[Nn]* ) exit;;
|
|
|
|
* ) exit;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
already_exists() {
|
|
|
|
echo "Package already installed"
|
|
|
|
echo "pass -u and -i to upgrade"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
dep_not_found() {
|
|
|
|
echo "Missing dep: $1"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2021-04-12 17:22:25 +00:00
|
|
|
iglupkg_check() {
|
|
|
|
if ! command -v iglupkg > /dev/null 2>&1; then
|
|
|
|
echo "iglupkg from iglunix-dev needs to be installed"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
b= bi= i= u= l= f= o= d= iu=
|
2021-01-02 18:24:06 +00:00
|
|
|
|
2021-02-17 19:04:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Handle commandline arguments.
|
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-31 01:49:02 +00:00
|
|
|
-d) d=1;;
|
|
|
|
-iu) iu=1;;
|
|
|
|
-ui) iu=1;;
|
2021-04-12 17:22:25 +00:00
|
|
|
-b) b=1;;
|
|
|
|
-bi) bi=1;;
|
|
|
|
-biu) biu=1;;
|
|
|
|
-bui) biu=1;;
|
|
|
|
|
2021-02-17 19:04:49 +00:00
|
|
|
-h) usage;;
|
|
|
|
--help) usage;;
|
|
|
|
|
|
|
|
*) error_usage "bad argument $i";;
|
2021-01-02 18:24:06 +00:00
|
|
|
esac
|
|
|
|
shift
|
|
|
|
|
|
|
|
while :
|
|
|
|
do
|
|
|
|
case "$1" in
|
|
|
|
-o) shift; o="$1";;
|
|
|
|
--) shift; break;;
|
|
|
|
-*) usage "bad argument $1";;
|
|
|
|
*) break;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2021-01-31 01:49:02 +00:00
|
|
|
if [ "$d" = "1" ]; then
|
2021-04-12 17:22:25 +00:00
|
|
|
#LIST DEPS
|
2021-02-10 19:00:20 +00:00
|
|
|
stat /usr/share/iglupkg/$1 > /dev/null 2> /dev/null || find_fail
|
|
|
|
grep deps /usr/share/iglupkg/$1 | tr '=' '\n' | grep -v deps | tr ':' '\n'
|
2021-01-31 01:49:02 +00:00
|
|
|
|
|
|
|
elif [ "$iu" = "1" ]; then
|
2021-04-12 17:22:25 +00:00
|
|
|
#INSTALL & UPDATE
|
2021-01-31 01:49:02 +00:00
|
|
|
# Setup names
|
|
|
|
bname_we=$(basename "$1")
|
|
|
|
bname=$(echo "$bname_we" | cut -f 1 -d '.')
|
|
|
|
|
|
|
|
# locate installed package
|
2021-02-10 19:00:20 +00:00
|
|
|
stat /usr/share/iglupkg/$bname > /dev/null 2> /dev/null || find_fail
|
2021-01-31 01:49:02 +00:00
|
|
|
|
|
|
|
echo "Upgrading $bname_we"
|
|
|
|
continue_interactive
|
|
|
|
|
|
|
|
# Extract new package and verify
|
2021-02-10 19:00:20 +00:00
|
|
|
mkdir -p /tmp/iglunix/$bname_we || exit 1
|
2021-05-21 08:27:37 +00:00
|
|
|
tar -I zstd -xf $1 -C /tmp/iglunix/$bname_we || tar_fail
|
2021-02-10 19:00:20 +00:00
|
|
|
stat /tmp/iglunix/$bname_we/usr/share/iglupkg/$bname >/dev/null || stat_fail
|
2021-01-31 01:49:02 +00:00
|
|
|
|
|
|
|
# Check deps
|
2021-02-10 19:00:20 +00:00
|
|
|
deps=$(grep deps /tmp/iglunix/$bname_we/usr/share/iglupkg/$bname | tr '=' '\n' | grep -v deps | tr ':' '\n')
|
2021-01-31 01:49:02 +00:00
|
|
|
for dep in $deps; do
|
2021-02-10 19:00:20 +00:00
|
|
|
stat /usr/share/iglupkg/$dep > /dev/null 2> /dev/null || dep_not_found $dep
|
2021-01-31 01:49:02 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# Grab a list of old files and new files to install
|
2021-02-10 19:00:20 +00:00
|
|
|
OFILES=$(sed -n '/\[fs\]/,$p' /usr/share/iglupkg/$bname |
|
2021-01-31 01:49:02 +00:00
|
|
|
grep -v "\[fs\]" | awk '{print length, $0}' | sort -rn | cut -d " " -f2-)
|
2021-02-10 19:00:20 +00:00
|
|
|
NFILES=$(sed -n '/\[fs\]/,$p' /tmp/iglunix/$bname_we/usr/share/iglupkg/$bname |
|
2021-01-31 01:49:02 +00:00
|
|
|
grep -v "\[fs\]" | awk '{print length, $0}' | sort -rn | cut -d " " -f2-)
|
|
|
|
|
|
|
|
# Extract tar
|
2021-05-21 08:27:37 +00:00
|
|
|
tar -I zstd -xf $1 -C /
|
2021-02-10 19:00:20 +00:00
|
|
|
rm -r /tmp/iglunix/$bname_we
|
2021-01-31 01:49:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Remove old files (don't know if this works yet)
|
|
|
|
for file in $OFILES; do
|
|
|
|
if echo $NFILES | grep -q $file; then
|
|
|
|
echo "not removing $file"
|
|
|
|
else
|
|
|
|
echo "attempting to remove $file"
|
|
|
|
case $(stat -c "%F" /$file) in
|
|
|
|
directory) rmdir 2>/dev/null /$file;;
|
|
|
|
"regular file") rm /$file;;
|
2021-05-29 09:04:00 +00:00
|
|
|
"regular empty file") rm /$file;;
|
2021-02-03 13:03:52 +00:00
|
|
|
"symbolic link") rm /$file;;
|
2021-01-31 01:49:02 +00:00
|
|
|
*) break;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
echo $OFILES
|
2021-01-31 11:09:14 +00:00
|
|
|
echo $NFILES
|
2021-01-31 01:49:02 +00:00
|
|
|
|
|
|
|
elif [ "$i" = "1" ]; then
|
2021-04-12 17:22:25 +00:00
|
|
|
#INSTALL
|
2021-01-31 01:49:02 +00:00
|
|
|
bname_we=$(basename "$1")
|
|
|
|
bname=$(echo "$bname_we" | cut -f 1 -d '.')
|
2021-02-10 19:00:20 +00:00
|
|
|
stat /usr/share/iglupkg/$bname > /dev/null 2> /dev/null && already_exists
|
2021-01-31 01:49:02 +00:00
|
|
|
echo "Installing $bname_we"
|
|
|
|
continue_interactive
|
2021-02-10 19:00:20 +00:00
|
|
|
mkdir -p /tmp/iglunix/$bname_we || exit 1
|
2021-05-21 08:27:37 +00:00
|
|
|
tar -I zstd -xf $1 -C /tmp/iglunix/$bname_we || tar_fail
|
2021-02-10 19:00:20 +00:00
|
|
|
stat /tmp/iglunix/$bname_we/usr/share/iglupkg/$bname >/dev/null || stat_fail
|
|
|
|
deps=$(grep deps /tmp/iglunix/$bname_we/usr/share/iglupkg/$bname | tr '=' '\n' | grep -v deps | tr ':' '\n')
|
2021-01-31 01:49:02 +00:00
|
|
|
for dep in $deps; do
|
2021-02-10 19:00:20 +00:00
|
|
|
stat /usr/share/iglupkg/$dep > /dev/null 2> /dev/null || dep_not_found $dep
|
2021-01-31 01:49:02 +00:00
|
|
|
done
|
2021-05-21 08:27:37 +00:00
|
|
|
tar -I zstd -xf $1 -C /
|
2021-02-10 19:00:20 +00:00
|
|
|
rm -r /tmp/iglunix/$bname_we
|
2021-01-03 13:54:48 +00:00
|
|
|
elif [ "$f" = "1" ]; then
|
2021-04-12 17:22:25 +00:00
|
|
|
#LIST INSTALLED FILES
|
2021-02-10 19:00:20 +00:00
|
|
|
stat /usr/share/iglupkg/$1 > /dev/null 2> /dev/null || find_fail
|
|
|
|
sed -n '/\[fs\]/,$p' /usr/share/iglupkg/$1 | grep -v "\[fs\]"
|
2021-04-12 17:22:25 +00:00
|
|
|
|
2021-01-03 13:54:48 +00:00
|
|
|
elif [ "$l" = "1" ]; then
|
2021-04-12 17:22:25 +00:00
|
|
|
#LICENSE
|
2021-02-10 19:00:20 +00:00
|
|
|
stat /usr/share/iglupkg/$1 > /dev/null 2> /dev/null || find_fail
|
|
|
|
sed -n '/\[license\]/,/\[fs\]/{/\[license\]\|\[fs\]/!p}' /usr/share/iglupkg/$1
|
2021-04-12 17:22:25 +00:00
|
|
|
|
2021-01-31 01:49:02 +00:00
|
|
|
elif [ "$u" = "1" ]; then
|
2021-04-12 17:22:25 +00:00
|
|
|
#UNINSTALL
|
2021-02-10 19:00:20 +00:00
|
|
|
stat /usr/share/iglupkg/$1 > /dev/null 2> /dev/null || find_fail
|
|
|
|
FILES=$(sed -n '/\[fs\]/,$p' /usr/share/iglupkg/$1 | grep -v "\[fs\]" | awk '{print length, $0}' | sort -rn | cut -d " " -f2-)
|
2021-01-31 01:49:02 +00:00
|
|
|
|
|
|
|
echo "Uninstalling $1"
|
|
|
|
continue_interactive
|
|
|
|
|
|
|
|
for file in $FILES; do
|
|
|
|
case $(stat -c "%F" /$file) in
|
|
|
|
directory) rmdir 2>/dev/null /$file;;
|
|
|
|
"regular file") rm /$file;;
|
2021-05-29 09:04:00 +00:00
|
|
|
"regular empty file") rm /$file;;
|
2021-02-03 13:03:52 +00:00
|
|
|
"symbolic link") rm /$file;;
|
2021-05-29 09:04:00 +00:00
|
|
|
*) echo "can't remove /$file";;
|
2021-01-31 01:49:02 +00:00
|
|
|
esac
|
|
|
|
done
|
2021-04-12 17:22:25 +00:00
|
|
|
elif [ "$b" = "1" ]; then
|
|
|
|
#BUILD
|
|
|
|
iglupkg_check
|
|
|
|
iglupkg || exit 1
|
|
|
|
|
|
|
|
elif [ "$bi" = "1" ]; then
|
|
|
|
#BUILD INSTALL
|
|
|
|
iglupkg_check
|
|
|
|
iglupkg || exit 1
|
|
|
|
cd out/
|
|
|
|
for pkg in *.tar.xz; do
|
|
|
|
iglu -i "$pkg"
|
|
|
|
done
|
|
|
|
|
|
|
|
elif [ "$biu" = "1" ]; then
|
|
|
|
#BUILD INSTALL UPDATE
|
|
|
|
iglupkg_check
|
|
|
|
iglupkg || exit 1
|
|
|
|
cd out/
|
|
|
|
for pkg in *.tar.xz; do
|
|
|
|
iglu -iu "$pkg"
|
|
|
|
done
|
2021-01-02 18:24:06 +00:00
|
|
|
fi
|