#!/bin/sh
# Glacier - A simple package management system written in POSIX sh
# Copyright (C) 2022 Everest Linux Development Group
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
# Preloading
/usr/bin/gscripts preload
source $(pwd)/messages # this is here for the sole purpose of testing
source /etc/glacier/messages
export input
# Main Script
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
printf "$blue [ * ] Glacier - Manage packages on the system [ * ] $reset\n"
printf "$blue=== Information ====================================================================================$reset\n"
printf "$ glacier {-h --help} show this message and exit\n"
printf "$ glacier {--version} display the current Glacier version and exit\n"
printf "$blue=== Package Operations =============================================================================$reset\n"
printf "# glacier {install -f} install a package to the system\n"
printf "# glacier {update -u} update an installed package\n"
printf "# glacier {remove -x} remove an installed package\n"
printf "$ glacier {query -q} query the information of an installed package\n"
printf "# glacier {cache -c} cache a package from the repositories\n"
printf "# glacier {cache-install -ci} install a cached package\n"
printf "# glacier {cache-clear -cc} clear the package cache\n"
printf "$blue=== Debugging ======================================================================================$reset\n"
printf "$ glacier {--showDebugInfo} show debugging info\n"
printf "$blue=== Licensing ======================================================================================$reset\n"
printf "This program is freely distributable under the terms of the\n"
printf "GNU General Public License version 3 or later.\n"
printf "You should have recieved a copy of the GNU General Public License\n"
printf "along with this program. If not, see .\n"
printf "$blue======================================================================================================\n"
exit 0
;;
--version)
printf "$blue Glacier v$GLACIER_RELEASE $reset\n"
exit 0
;;
install|-f)
# Require script to be run as root
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
echo $GLACIER_ERROR_NO_ROOT
exit 1
fi
echo $GLACIER_WHICH_PKG && read input
export input
echo $GLACIER_STATUS_INSTALLING
/usr/bin/gscripts download
if [ "$?" != "0" ]; then
echo $GLACIER_ERROR_DOES_NOT_EXIST
exit 1
fi
echo $GLACIER_STATUS_INTEGRITY_CHECK
mkdir $input && mv $input.tar.gz $input && cd $input
/usr/bin/gscripts integrity-check
if [ "$?" != "0" ]; then
exit 1
fi
echo $GLACIER_STATUS_UNPACKING
tar -xvf $input.tar.gz
if [ "$?" != "0" ]; then
echo $GLACIER_ERROR_CANNOT_UNPACK
exit 1
fi
chmod +x INSTALL.sh
chmod +x $input.ts.sh
echo $GLACIER_STATUS_EXECUTING
./INSTALL.sh
if [ "$?" != "0" ]; then
echo $GLACIER_ERROR_INSTRUCTIONS_CANNOT_EXECUTE
exit 1
fi
./$input.ts.sh
/usr/bin/gscripts post-install
echo $GLACIER_SUCCESS
exit 0
;;
update|-u)
# Require script to be run as root
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
echo $GLACIER_ERROR_NO_ROOT
exit 1
fi
echo $GLACIER_WHICH_PKG && read input
export input
echo $GLACIER_STATUS_UPDATING
/usr/bin/gscripts download
if [ "$?" != "0" ]; then
echo $GLACIER_ERROR_DOES_NOT_EXIST
exit 1
fi
echo $GLACIER_STATUS_INTEGRITY_CHECK
mkdir $input && mv $input.tar.gz $input && cd $input
/usr/bin/gscripts integrity-check
if [ "$?" != "0" ]; then
exit 1
fi
echo $GLACIER_STATUS_UNPACKING
tar -xvf $input.tar.gz
if [ "$?" != "0" ]; then
echo $GLACIER_ERROR_CANNOT_UNPACK
exit 1
fi
chmod +x UPDATE.sh
chmod +x $input.ts.sh
echo $GLACIER_STATUS_EXECUTING
./UPDATE.sh
if [ "$?" != "0" ]; then
echo $GLACIER_ERROR_INSTRUCTIONS_CANNOT_EXECUTE
exit 1
fi
./$input.ts.sh
/usr/bin/gscripts post-install
echo $GLACIER_SUCCESS
exit 0
;;
remove|-x)
# Require script to be run as root
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
echo $GLACIER_ERROR_NO_ROOT
exit 1
fi
echo $GLACIER_WHICH_PKG && read input
echo $GLACIER_STATUS_REMOVING
export input
/usr/bin/gscripts download
if [ "$?" != "0" ]; then
echo $GLACIER_ERROR_DOES_NOT_EXIST
exit 1
fi
echo $GLACIER_STATUS_INTEGRITY_CHECK
mkdir $input && mv $input.tar.gz $input && cd $input
/usr/bin/gscripts integrity-check
if [ "$?" != "0" ]; then
exit 1
fi
echo $GLACIER_STATUS_UNPACKING
tar -xvf $input.tar.gz
if [ "$?" != "0" ]; then
echo $GLACIER_ERROR_CANNOT_UNPACK
exit 1
fi
chmod +x REMOVE.sh
chmod +x $input.ts.sh
echo $GLACIER_STATUS_EXECUTING
./REMOVE.sh
if [ "$?" != "0" ]; then
echo $GLACIER_ERROR_INSTRUCTIONS_CANNOT_EXECUTE
exit 1
fi
./$input.ts.sh
/usr/bin/gscripts post-install
echo $GLACIER_SUCCESS
exit 0
;;
query|-q)
echo $GLACIER_WHICH_PKG && read input
cat /etc/glacier/pkginfo/$input-pkginfo.json
cat /var/log/glacier/$input.timestamp
if [ "$?" != "0" ]; then
echo $GLACIER_ERROR_NOT_INSTALLED
exit 1
fi
exit 0
;;
cache|-c)
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
echo $GLACIER_ERROR_NO_ROOT
exit 1
fi
echo $GLACIER_WHICH_PKG && read input
echo $GLACIER_STATUS_CACHING
export input
/usr/bin/gscripts download
if [ "$?" != "0" ]; then
echo $GLACIER_ERROR_DOES_NOT_EXIST
exit 1
fi
echo $GLACIER_STATUS_INTEGRITY_CHECK
mv $input.tar.gz /var/cache/glacier && cd /var/cache/glacier
/usr/bin/gscripts integrity-check
if [ "$?" != "0" ]; then
exit 1
fi
echo $GLACIER_SUCCESS
exit 0
;;
cache-install|-ci)
if [[ $(usr/bin/id -u) -ne 0 ]]; then
echo $GLACIER_ERROR_NO_ROOT
exit 1
fi
echo $GLACIER_WHICH_PKG && read input
echo $GLACIER_STATUS_INSTALLING
export input
cd /var/cache/glacier && cp $input.tar.gz /tmp && cd /tmp
if [ "$?" != "0" ]; then
echo $GLACIER_ERROR_NOT_IN_CACHE
exit 1
fi
echo $GLACIER_STATUS_UNPACKING
mkdir $input && mv $input.tar.gz $input && cd $input
tar -xvf $input.tar.gz
if [ "$?" != "0" ]; then
echo $GLACIER_ERROR_CANNOT_UNPACK
exit 1
fi
echo $GLACIER_STATUS_EXECUTING
chmod +x INSTALL.sh
chmod +x $input.ts.sh
./INSTALL.sh
if [ "$!" != "0" ]; then
echo $GLACIER_ERROR_INSTRUCTIONS_CANNOT_EXECUTE
exit 1
fi
./$input.ts.sh
/usr/bin/gscripts post-install
echo $GLACIER_SUCCESS
exit 0
;;
cache-clear|-cc)
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
echo $GLACIER_ERROR_NO_ROOT
exit 1
fi
echo $GLACIER_STATUS_CLEARING
cd /var/cache/glacier && rm -rf *
echo $GLACIER_SUCCESS
exit 0
;;
--showDebugInfo)
printf "$blue Glacier v$GLACIER_RELEASE $reset\n"
printf ">> Checking for a viable download backend...\n"
whereis wget
whereis curl
whereis aria2c
printf ">> Checking which download backend is in use...\n"
echo $GLACIER_DOWNLOAD_BACKEND
printf ">> Checking if all Glacier directories and files are present...\n"
ls /etc | grep glacier
ls /etc/glacier
whereis make.conf
printf ">> If any files are missing, especially make.conf, Glacier will behave abnormally.\n"
printf ">> Checking if unicode symbols and colors display properly...\n"
printf "(NOTE): If you use a custom colorscheme, colors may vary.\n"
printf " For instance, the Dracula colorscheme turns blue into purple.\n"
printf "$check\n"
printf "$error\n"
printf "$warning\n"
printf "$question\n"
printf "$red Red.$reset\n"
printf "$green Green.$reset\n"
printf "$yellow Yellow.$reset\n"
printf "$blue Blue.$reset\n"
printf ">> Checking repositories...\n"
echo $GREPO1
echo $GREPO2
echo $GREPO3
echo $GREPO4
echo $GREPO5
echo $GREPO6
echo $GREPO7
echo $GREPO8
printf ">> Debug information has been gathered.\n"
printf ">> Run 'glacier --showDebugInfo > glacier.debug' to save this information to a file.\n"
exit 0
;;
-*|--*)
echo $GLACIER_ERROR_NO_SUCH_OPTION
exit 1
;;
*)
echo $GLACIER_ERROR_NO_SUCH_OPTION
exit 1
;;
esac
done
echo $GLACIER_ERROR_NO_SUCH_OPTION
exit 1