297 lines
8.6 KiB
Bash
Executable File
297 lines
8.6 KiB
Bash
Executable File
#!/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 <https://www.gnu.org/licenses/>.
|
|
|
|
# Preloading
|
|
/usr/bin/gscripts preload
|
|
export input
|
|
|
|
# Main Script
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
-h|--help)
|
|
printf "$blue [ * ] Glacier - A source based package manager written in POSIX sh [ * ] $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\n"
|
|
printf "# glacier {update -u} update a package\n"
|
|
printf "# glacier {remove -x} remove a package\n"
|
|
printf "$ glacier {query -q} query a package\n"
|
|
printf "# glacier {cache -c} cache a package\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 GNU General Public License version 3 or later.\n"
|
|
printf "You should have recieved a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.\n"
|
|
printf "======================================================================================================\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
|
|
$GLACIER_ERROR_NO_ROOT
|
|
exit 1
|
|
fi
|
|
|
|
$GLACIER_WHICH_PKG && read input
|
|
export input
|
|
$GLACIER_STATUS_INSTALLING
|
|
/usr/bin/gscripts download
|
|
if [ "$?" != "0" ]; then
|
|
$GLACIER_ERROR_DOES_NOT_EXIST
|
|
exit 1
|
|
fi
|
|
$GLACIER_STATUS_INTEGRITY_CHECK
|
|
mkdir $input && mv $input.tar.gz $input && cd $input
|
|
/usr/bin/gscripts integrity-check
|
|
if [ "$?" != "0" ]; then
|
|
exit 1
|
|
fi
|
|
$GLACIER_STATUS_UNPACKING
|
|
tar -xvf $input.tar.gz
|
|
if [ "$?" != "0" ]; then
|
|
$GLACIER_ERROR_CANNOT_UNPACK
|
|
exit 1
|
|
fi
|
|
chmod +x INSTALL.sh
|
|
chmod +x $input.ts.sh
|
|
$GLACIER_STATUS_EXECUTING
|
|
./INSTALL.sh
|
|
if [ "$?" != "0" ]; then
|
|
$GLACIER_ERROR_INSTRUCTIONS_CANNOT_EXECUTE
|
|
exit 1
|
|
fi
|
|
./$input.ts.sh
|
|
/usr/bin/gscripts post-install
|
|
$GLACIER_SUCCESS
|
|
exit 0
|
|
;;
|
|
update|-u)
|
|
# Require script to be run as root
|
|
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
|
|
$GLACIER_ERROR_NO_ROOT
|
|
exit 1
|
|
fi
|
|
|
|
$GLACIER_WHICH_PKG && read input
|
|
export input
|
|
$GLACIER_STATUS_UPDATING
|
|
/usr/bin/gscripts download
|
|
if [ "$?" != "0" ]; then
|
|
$GLACIER_ERROR_DOES_NOT_EXIST
|
|
exit 1
|
|
fi
|
|
$GLACIER_STATUS_INTEGRITY_CHECK
|
|
mkdir $input && mv $input.tar.gz $input && cd $input
|
|
/usr/bin/gscripts integrity-check
|
|
if [ "$?" != "0" ]; then
|
|
exit 1
|
|
fi
|
|
$GLACIER_STATUS_UNPACKING
|
|
tar -xvf $input.tar.gz
|
|
if [ "$?" != "0" ]; then
|
|
$GLACIER_ERROR_CANNOT_UNPACK
|
|
exit 1
|
|
fi
|
|
chmod +x UPDATE.sh
|
|
chmod +x $input.ts.sh
|
|
$GLACIER_STATUS_EXECUTING
|
|
./UPDATE.sh
|
|
if [ "$?" != "0" ]; then
|
|
$GLACIER_ERROR_INSTRUCTIONS_CANNOT_EXECUTE
|
|
exit 1
|
|
fi
|
|
./$input.ts.sh
|
|
/usr/bin/gscripts post-install
|
|
$GLACIER_SUCCESS
|
|
exit 0
|
|
;;
|
|
remove|-x)
|
|
# Require script to be run as root
|
|
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
|
|
$GLACIER_ERROR_NO_ROOT
|
|
exit 1
|
|
fi
|
|
|
|
$GLACIER_WHICH_PKG && read input
|
|
$GLACIER_STATUS_REMOVING
|
|
export input
|
|
/usr/bin/gscripts download
|
|
if [ "$?" != "0" ]; then
|
|
$GLACIER_ERROR_DOES_NOT_EXIST
|
|
exit 1
|
|
fi
|
|
$GLACIER_STATUS_INTEGRITY_CHECK
|
|
mkdir $input && mv $input.tar.gz $input && cd $input
|
|
/usr/bin/gscripts integrity-check
|
|
if [ "$?" != "0" ]; then
|
|
exit 1
|
|
fi
|
|
$GLACIER_STATUS_UNPACKING
|
|
tar -xvf $input.tar.gz
|
|
if [ "$?" != "0" ]; then
|
|
$GLACIER_ERROR_CANNOT_UNPACK
|
|
exit 1
|
|
fi
|
|
chmod +x REMOVE.sh
|
|
chmod +x $input.ts.sh
|
|
$GLACIER_STATUS_EXECUTING
|
|
./REMOVE.sh
|
|
if [ "$?" != "0" ]; then
|
|
$GLACIER_ERROR_INSTRUCTIONS_CANNOT_EXECUTE
|
|
exit 1
|
|
fi
|
|
./$input.ts.sh
|
|
/usr/bin/gscripts post-install
|
|
$GLACIER_SUCCESS
|
|
exit 0
|
|
;;
|
|
query|-q)
|
|
$GLACIER_WHICH_PKG && read input
|
|
cat /etc/glacier/pkginfo/$input-pkginfo.json
|
|
cat /var/log/glacier/$input.timestamp
|
|
if [ "$?" != "0" ]; then
|
|
$GLACIER_ERROR_NOT_INSTALLED
|
|
exit 1
|
|
fi
|
|
exit 0
|
|
;;
|
|
cache|-c)
|
|
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
|
|
$GLACIER_ERROR_NO_ROOT
|
|
exit 1
|
|
fi
|
|
|
|
$GLACIER_WHICH_PKG && read input
|
|
$GLACIER_STATUS_CACHING
|
|
export input
|
|
/usr/bin/gscripts download
|
|
if [ "$?" != "0" ]; then
|
|
$GLACIER_ERROR_DOES_NOT_EXIST
|
|
exit 1
|
|
fi
|
|
$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
|
|
$GLACIER_SUCCESS
|
|
exit 0
|
|
;;
|
|
cache-install|-ci)
|
|
if [[ $(usr/bin/id -u) -ne 0 ]]; then
|
|
$GLACIER_ERROR_NO_ROOT
|
|
exit 1
|
|
fi
|
|
|
|
$GLACIER_WHICH_PKG && read input
|
|
$GLACIER_STATUS_INSTALLING
|
|
export input
|
|
cd /var/cache/glacier && cp $input.tar.gz /tmp && cd /tmp
|
|
if [ "$?" != "0" ]; then
|
|
$GLACIER_ERROR_NOT_IN_CACHE
|
|
exit 1
|
|
fi
|
|
$GLACIER_STATUS_UNPACKING
|
|
mkdir $input && mv $input.tar.gz $input && cd $input
|
|
tar -xvf $input.tar.gz
|
|
if [ "$?" != "0" ]; then
|
|
$GLACIER_ERROR_CANNOT_UNPACK
|
|
exit 1
|
|
fi
|
|
$GLACIER_STATUS_EXECUTING
|
|
chmod +x INSTALL.sh
|
|
chmod +x $input.ts.sh
|
|
./INSTALL.sh
|
|
if [ "$!" != "0" ]; then
|
|
$GLACIER_ERROR_INSTRUCTIONS_CANNOT_EXECUTE
|
|
exit 1
|
|
fi
|
|
./$input.ts.sh
|
|
/usr/bin/gscripts post-install
|
|
$GLACIER_SUCCESS
|
|
exit 0
|
|
;;
|
|
cache-clear|-cc)
|
|
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
|
|
$GLACIER_ERROR_NO_ROOT
|
|
exit 1
|
|
fi
|
|
|
|
$GLACIER_STATUS_CLEARING
|
|
cd /var/cache/glacier && rm -rf *
|
|
$GLACIER_SUCCESS
|
|
exit 0
|
|
;;
|
|
--showDebugInfo)
|
|
printf "Glacier v$GLACIER_RELEASE"
|
|
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 "$check\n"
|
|
printf "$error\n"
|
|
printf "$warning\n"
|
|
printf "$question\n"
|
|
printf "$red This is a test.$reset\n"
|
|
printf "$green This is a test.$reset\n"
|
|
printf "$yellow This is a test.$reset\n"
|
|
printf "$blue This is a test.$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
|
|
;;
|
|
-*|--*)
|
|
$GLACIER_ERROR_NO_SUCH_OPTION
|
|
exit 1
|
|
;;
|
|
*)
|
|
$GLACIER_ERROR_NO_SUCH_OPTION
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
$GLACIER_ERROR_NO_SUCH_OPTION
|
|
exit 1
|