Glacier v3.2.0 - Changes to package removal

This commit is contained in:
lw-everestlinux 2022-11-21 20:11:04 -05:00
parent f09d6d45ea
commit 3b4c6f33cf
5 changed files with 96 additions and 41 deletions

View File

@ -1,9 +0,0 @@
#!/bin/sh
rm -rf /etc/glacier
rm -rf /var/log/glacier
rm -rf /var/cache/glacier
rm -rf /opt/glacier
rm /bin/glacier

View File

@ -18,35 +18,36 @@ printf "parsing install.conf\n"
case $1 in
install)
printf "installing executable\n"
mv $SRC_DIR/glacier $PREFIX/bin
mv -v $SRC_DIR/glacier $PREFIX/bin
if [ "$?" != 0 ]; then
mv $SRC_DIR/glacier $PREFIX
mv -v $SRC_DIR/glacier $PREFIX
printf "directory $PREFIX/bin does not exist, moving to $PREFIX instead\n"
fi
printf "installing configuration files\n"
mv $SRC_DIR/glacier.conf $CONFDIR
mv -v $SRC_DIR/glacier.conf $CONFDIR
if [ "$?" != 0 ]; then
printf "$CONFDIR does not exist\n"
printf "this can be corrected by running:\n"
printf "# mkdir -pv $CONFDIR\n"
printf "# mkdir -v -pv $CONFDIR\n"
exit 1
fi
mkdir /opt/glacier
mkdir /opt/glacier/workspace
mkdir /var/log/glacier
mkdir /var/cache/glacier
mkdir -v /opt/glacier
mkdir -v /opt/glacier/workspace
mkdir -v /var/log/glacier
mkdir -v /var/cache/glacier
mkdir /etc/glacier
mkdir /etc/glacier/pkginfo
mkdir -v /etc/glacier
mkdir -v /etc/glacier/pkginfo
mv $SRC_DIR/hooks $CONFDIR/glacier
mv $SRC_DIR/post-hooks $CONFDIR/glacier
mv $SRC_DIR/hooks.sh $CONFDIR/glacier
mv $SRC_DIR/make.conf $CONFDIR
mv $SRC_DIR/glacier-integrity-check $PREFIX/bin
mv -v $SRC_DIR/hooks $CONFDIR/glacier
mv -v $SRC_DIR/post-hooks $CONFDIR/glacier
mv -v $SRC_DIR/pre-hooks $CONFDIR/glacier
mv -v $SRC_DIR/hooks.sh $CONFDIR/glacier
mv -v $SRC_DIR/make.conf $CONFDIR
mv -v $SRC_DIR/glacier-integrity-check $PREFIX/bin
if [ "$?" != "0" ]; then
mv $SRC_DIR/glacier-integrity-check $PREFIX
mv -v $SRC_DIR/glacier-integrity-check $PREFIX
printf "directory $PREFIX/bin does not exist, moving to $PREFIX instead\n"
fi
@ -55,8 +56,10 @@ case $1 in
;;
update)
printf "updating executable\n"
rm $PREFIX/bin/glacier || rm $PREFIX/glacier
mv $SRC_DIR/glacier $PREFIX || mv $SRC_DIR/glacier $PREFIX/bin
rm -v $PREFIX/bin/glacier || rm -v $PREFIX/glacier
rm -v $PREFIX/bin/glacier-integrity-check || rm -v $PREFIX/glacier-integrity-check
mv -v $SRC_DIR/glacier $PREFIX || mv -v $SRC_DIR/glacier $PREFIX/bin
mv -v $SRC_DIR/glacier-integrity-check $PREFIX || mv -v $SRC_DIR/glacier-integrity-check $PREFIX/bin
printf "finished updating\n"
exit 0
esac

View File

@ -37,7 +37,7 @@ int_check() {
unpack_pkg() {
printf "$blue[ i ]$reset Unpacking $2.tar.gz...\n"
mkdir $2 && mv $2.tar.gz $2 && cd $2
tar -xvf $2.tar.gz
tar -xf $2.tar.gz
if [ "$?" != "0" ]; then
printf "$red[ $error ]$reset Could not unpack $2.tar.gz.\n"
cd .. && rm -rf $2
@ -76,7 +76,7 @@ removepkg() {
printf "$blue[ i ]$reset Removing $2...\n"
sleep 1
chmod +x *
./REMOVE.sh
/etc/glacier/pkginfo/$2.remove
if [ "$?" != "0" ]; then
printf "$red[ $error ]$reset Failed to remove $2.\n"
cd .. && rm -rf $2
@ -108,8 +108,12 @@ clear_cache() {
fi
}
#
# Show Glacier debugging info
#
debug_info() {
printf "$blue>> Glacier v3.1.1$reset\n"
printf "$blue>> Glacier v3.2.0$reset\n"
printf ">> Checking for valid download backend...\n"
whereis wget
whereis curl
@ -148,6 +152,10 @@ debug_info() {
printf ">> $ glacier --debuginfo > glacier.debug\n"
}
#
# Parses JSON from pkginfo files and outputs it
#
query() {
printf "$blue[ i ]$reset Showing information for package '$2'.\n"
printf "$blue>> Package name:$reset " && cat /etc/glacier/pkginfo/$2-pkginfo.json | jq .package_name
@ -159,15 +167,42 @@ query() {
printf "$blue>> Installation date:$reset " && cat /var/log/glacier/$2.timestamp
}
cleanup () {
#
# Will either keep removal script, update it with a new one, or delete it alltogether
#
cleanup_keep_rm () {
printf "$blue[ i ]$reset Cleaning up...\n"
mv REMOVE.sh /etc/glacier/pkginfo/$2.remove
cd .. && rm -rf *.checksum *.tar.* $2
}
cleanup_update_rm () {
printf "$blue[ i ]$reset Cleaning up...\n"
rm /etc/glacier/pkginfo/$2.remove
mv REMOVE.sh /etc/glacier/pkginfo/$2.remove
cd .. && rm -rf *.checksum *.tar.* $2
}
cleanup_del_rm () {
printf "$blue[ i ]$reset Cleaning up...\n"
rm /etc/glacier/pkginfo/$2.remove
cd .. && rm -rf *.checksum *.tar.* $2
}
#
# Execute pre and posr hooks from files
#
pre_hooks() {
source /etc/glacier/hooks
}
pre_op_hooks() {
printf "$blue[ i ]$reset Executing pre-operation hooks...\n"
/etc/glacier/pre-hooks
}
post_hooks () {
printf "$blue[ i ]$reset Executing post-operation hooks...\n"
/etc/glacier/post-hooks
@ -176,7 +211,7 @@ post_hooks () {
case $1 in
-h|--help)
printf "$blue[ * ] Glacier - Manage installed packages on the system$reset\n"
printf "usage: glacier {action} {package-name}\n"
printf "usage: glacier [-f] [-u] [-x] [-q] [-c] [-ci] [-cc] [--debuginfo]\n"
printf "\n"
printf "$blue=== Information ===$reset\n"
printf "glacier {-h/--help} - Show this message and exit\n"
@ -201,10 +236,10 @@ case $1 in
exit 0
;;
-v|--version)
printf "$blue Glacier v3.1.1$reset\n"
printf "${blue}Glacier v3.2.0${reset}\n"
exit 0
;;
-f|-install)
-f|install)
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
printf "$red[ $error ]$reset Please run Glacier as root.\n"
exit 1
@ -224,11 +259,16 @@ case $1 in
get_pkg "$@"
int_check "$@"
unpack_pkg "$@"
pre_op_hooks "$@"
installpkg "$@"
post_hooks "$@"
cleanup "$@"
cleanup_keep_rm "$@"
printf "$green[ $check ]$reset Operation completed.\n"
exit 0
elif [[ $REPLY =~ ^[Nn]$ ]]; then
printf "\n"
printf "${red}[ $error ]${reset} Aborting.\n"
exit 1
fi
;;
-u|update)
@ -251,11 +291,16 @@ case $1 in
get_pkg "$@"
int_check "$@"
unpack_pkg "$@"
pre_op_hooks "$@"
updatepkg "$@"
post_hooks "$@"
cleanup "$@"
cleanup_update_rm "$@"
printf "$green[ $check ]$reset Operation completed.\n"
exit 0
elif [[ $REPLY =~ ^[Nn]$ ]]; then
printf "\n"
printf "${red}[ $error ]${reset} Aborting.\n"
exit 1
fi
;;
-x|remove)
@ -275,14 +320,15 @@ case $1 in
cd /opt/glacier/workspace
printf "\n"
pre_hooks "$@"
get_pkg "$@"
int_check "$@"
unpack_pkg "$@"
removepkg "$@"
post_hooks "$@"
cleanup "$@"
cleanup_del_rm "$@"
printf "$green[ $check ]$reset Operation completed.\n"
exit 0
elif [[ $REPLY =~ ^[Nn]$ ]]; then
printf "\n"
printf "${red}[ $error ]${reset} Aborting.\n"
exit 1
fi
;;
-q|query)
@ -314,6 +360,10 @@ case $1 in
int_check "$@"
printf "$green[ $check ]$reset Operation completed.\n"
exit 0
elif [[ $REPLY =~ ^[Nn]$ ]]; then
printf "\n"
printf "${red}[ $error ]${reset} Aborting.\n"
exit 1
fi
;;
-ci|cache-install)
@ -336,11 +386,16 @@ case $1 in
printf "\n"
pre_hooks "$@"
unpack_pkg "$@"
pre_op_hooks "$@"
installpkg "$@"
post_hooks "$@"
cleanup "$@"
cleanup_keep_rm "$@"
printf "$green[ $check ]$reset Operation completed.\n"
exit 0
elif [[ $REPLY =~ ^[Nn]$ ]]; then
printf "\n"
printf "${red}[ $error ]${reset} Aborting.\n"
exit 1
fi
;;
-cc|cache-clear)

View File

@ -15,3 +15,4 @@ elif LOCAL_SUM != PKG_SUM:
else:
print("an error occured\n")
sys.exit(1)
print("=======================================")

5
src/pre-hooks Normal file
View File

@ -0,0 +1,5 @@
#!/bin/sh
# Hooks to be executed before performing an operation on a package
printf "No hooks to be executed.\n"
exit 0