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

View File

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

View File

@ -15,3 +15,4 @@ elif LOCAL_SUM != PKG_SUM:
else: else:
print("an error occured\n") print("an error occured\n")
sys.exit(1) 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