glacier-old/scripts/glacier

304 lines
13 KiB
Plaintext
Raw Normal View History

2022-05-31 09:20:51 -04:00
#!/bin/sh
# Glacier - A source based package manager written in POSIX sh
# (C) 2022 Everest Developers
# 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/>.
2022-05-31 09:20:51 -04:00
# Preloading
source /etc/glacier/hooks.sh
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
2022-07-26 14:03:14 -04:00
printf "$blue [ * ] Glacier - A source based package manager written in POSIX sh [ * ] $reset\n"
printf "$blue=== Information ====================================================================================$reset\n"
2022-07-26 14:03:14 -04:00
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"
2022-07-26 14:03:14 -04:00
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"
2022-07-26 14:03:14 -04:00
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"
2022-07-26 14:03:14 -04:00
exit 0
2022-05-31 09:20:51 -04:00
;;
--version)
2022-07-26 14:03:14 -04:00
printf "$blue Glacier v2.2.1 $reset\n"
exit 0
2022-05-31 09:20:51 -04:00
;;
install|-f)
2022-07-26 14:03:14 -04:00
# Require the script to be run as root
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
printf "\033[1;31m [ \xE2\x9C\x95 ] \033[m Please run Glacier as root.\n"
exit
fi
2022-05-31 09:20:51 -04:00
2022-07-26 14:03:14 -04:00
# Get package name and download package archive
printf "\033[1;34m [ ? ] \033[m Enter package name: " && read input
printf "\033[1;34m [ i ] \033[m Installing $input.tar.gz...\n"
printf "\033[1;34m [ i ] \033[m Checking databases... " && $GLACIER_DOWNLOAD_BACKEND $GREPO1/$input.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO2/$input.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO3/$input.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO4/$input.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO5/$input.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO6/$input.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO7/$input.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO8/$input.tar.gz
if [ "$?" != "0" ]; then
printf "\033[1;31m [ \xE2\x9C\x95 ] \033[m Package not found.\n" 1>&2
exit 1
fi
# Unpack Tarball
printf "\033[1;34m [ i ] \033[m Unpacking $input.tar.gz...\n"
mkdir $input && mv $input.tar.gz $input && cd $input
printf "$blue [ i ]$reset Verifying integrity of package...\n"
sha256sum $input.tar.gz
tar -xf $input.tar.gz
2022-05-31 09:20:51 -04:00
if [ "$?" != "0" ]; then
2022-06-07 10:43:25 -04:00
printf "\033[1;31m [ \xE2\x9C\x95 ] \033[m Could not unpack $input.tar.gz.\n" 1>&2
2022-07-26 14:03:14 -04:00
cd .. && rm -rf $input
exit 1
2022-05-31 09:20:51 -04:00
fi
2022-06-02 10:44:50 -04:00
# Run installation hooks
2022-05-31 09:20:51 -04:00
chmod +x INSTALL.sh
chmod +x $input.ts.sh
2022-06-01 11:34:41 -04:00
printf "$blue [ i ]$reset The following instruction set will be executed:\n"
2022-06-01 11:32:04 -04:00
cat INSTALL.sh
2022-05-31 09:20:51 -04:00
printf "\033[1;34m [ i ] \033[m Executing installation instructions...\n"
2022-06-02 10:44:50 -04:00
./INSTALL.sh
2022-06-16 10:51:15 -04:00
if [ "$?" != "0" ]; then
2022-06-16 10:52:38 -04:00
printf "$red [ $error ]$reset Instructions were either unable to execute, or encountered an error while executing.\n" 1>&2
2022-07-26 14:03:14 -04:00
cd .. && rm -rf $input
2022-06-16 10:51:15 -04:00
exit 1
fi
2022-05-31 09:20:51 -04:00
./$input.ts.sh
2022-06-02 10:44:50 -04:00
# Clean up
printf "\033[1;34m [ i ] \033[m Cleaning up...\n"
2022-05-31 09:20:51 -04:00
mv $input-pkginfo.json /etc/glacier/pkginfo
cd ..
rm -rf $input
printf "\033[1;32m [ \xE2\x9C\x93 ] \033[m Operation completed.\n"
exit 0
;;
update|-u)
# Require Glacier to be run as root
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
2022-06-07 10:43:25 -04:00
printf "\033[1;31m [ $error ] \033[m Please run Glacier as root.\n"
2022-05-31 09:20:51 -04:00
exit
fi
printf "\033[1;34m [ ? ] \033[m Enter package name: " && read input
printf "\033[1;34m [ i ] \033[m Installing $input.tar.gz...\n"
printf "\033[1;34m [ i ] \033[m Checking databases... " && $GLACIER_DOWNLOAD_BACKEND $GREPO1/$input.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO2/$input.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO3/$input.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO4/$input.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO5/$input.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO6/$input.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO7/$input.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO8/$input.tar.gz
2022-05-31 09:20:51 -04:00
if [ "$?" != "0" ]; then
2022-06-07 10:43:25 -04:00
printf "\033[1;31m [ $error ] \033[m Package not found.\n" 1>&2
2022-05-31 09:20:51 -04:00
exit 1
fi
printf "\033[1;34m [ i ] \033[m Unpacking $input.tar.gz...\n"
mkdir $input && mv $input.tar.gz $input && cd $input
2022-06-08 08:54:10 -04:00
printf "$blue [ i ]$reset Verifying integrity of package...\n"
2022-06-08 08:57:46 -04:00
sha256sum $input.tar.gz
2022-05-31 09:20:51 -04:00
tar -xf $input.tar.gz
if [ "$?" != "0" ]; then
2022-06-07 10:43:25 -04:00
printf "\033[1;31m [ $error ] \033[m Could not unpack $input.tar.gz.\n" 1>&2
2022-05-31 09:20:51 -04:00
exit 1
fi
rm /var/log/glacier/$input.timestamp
chmod +x UPDATE.sh
chmod +x $input.ts.sh
2022-06-01 11:32:04 -04:00
printf "$blue [ i ]$reset The following instruction set will be executed:\n"
cat UPDATE.sh
printf "\033[1;34m [ i ] \033[m Executing update instructions...\n"
2022-05-31 09:20:51 -04:00
./UPDATE.sh
2022-06-16 10:51:15 -04:00
if [ "$?" != "0" ]; then
2022-06-16 10:52:38 -04:00
printf "$red [ $error ]$reset Instructions were either unable to execute, or encountered an error while executing.\n" 1>&2
2022-06-16 10:51:15 -04:00
exit 1
fi
2022-05-31 09:20:51 -04:00
./$input.ts.sh
printf "\033[1;34m [ i ] \033[m Cleaning up...\n"
mv $input-pkginfo.json /etc/glacier/pkginfo
cd ..
rm -rf $input
printf "\033[1;32m [ $check ] \033[m Operation completed.\n"
exit 0
;;
remove|-x)
# Require the script to be run as root
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
2022-06-07 10:43:25 -04:00
printf "\033[1;31m [ $error ] \033[m Please run Glacier as root.\n"
2022-05-31 09:20:51 -04:00
exit
fi
printf "\033[1;34m [ ? ] \033[m Enter package name: " && read input
printf "\033[1;34m [ i ] \033[m Removing $input.tar.gz...\n"
printf "\033[1;34m [ i ] \033[m Checking databases... " && $GLACIER_DOWNLOAD_BACKEND $GREPO1/$input.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO2/$input.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO3/$input.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO4/$input.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO5/$input.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO6/$input.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO7/$input.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO8/$input.tar.gz
2022-05-31 09:20:51 -04:00
if [ "$?" != "0" ]; then
2022-06-07 10:43:25 -04:00
printf "\033[1;31m [ $error ] \033[m Package not found.\n" 1>&2
2022-05-31 09:20:51 -04:00
exit 1
fi
printf "\033[1;34m [ i ] \033[m Unpacking $input.tar.gz...\n"
mkdir $input && mv $input.tar.gz $input && cd $input
2022-06-08 08:54:10 -04:00
printf "$blue [ i ]$reset Verifying integrity of package...\n"
2022-06-08 08:57:46 -04:00
sha256sum $input.tar.gz
2022-05-31 09:20:51 -04:00
tar -xf $input.tar.gz
if [ "$?" != "0" ]; then
2022-06-07 10:43:25 -04:00
printf "\033[1;31m [ $error ] \033[m Could not unpack $input.tar.gz.\n" 1>&2
2022-05-31 09:20:51 -04:00
exit 1
fi
chmod +x REMOVE.sh
2022-06-01 11:34:41 -04:00
printf "$blue [ i ] $reset The following instruction set will be executed:\n"
2022-06-01 11:32:04 -04:00
cat REMOVE.sh
2022-06-01 11:34:41 -04:00
printf "$blue [ i ] $reset Executing removal instructions...\n"
2022-05-31 09:20:51 -04:00
./REMOVE.sh
2022-06-16 10:51:15 -04:00
if [ "$?" != "0" ]; then
2022-06-16 10:52:38 -04:00
printf "$red [ $error ]$reset Instructions were either unable to execute, or encountered an error while executing.\n" 1>&2
2022-06-16 10:51:15 -04:00
exit 1
fi
2022-05-31 09:20:51 -04:00
rm /var/log/glacier/$input.timestamp
printf "\033[1;34m [ i ] \033[m Cleaning up... \n" # Status message
cd ..
rm -rf $input
rm /etc/glacier/pkginfo/$input-pkginfo.json
printf "\033[1;32m [ $check ] \033[m Operation completed.\n"
exit 0
;;
query|-q)
printf "\033[1;34m [ ? ] \033[m Enter package name: " && read input
cat /etc/glacier/pkginfo/$input-pkginfo.json
cat /var/log/glacier/$input.timestamp
if [ "$?" != "0" ]; then
2022-06-07 10:43:25 -04:00
printf "\033[1;31m [ $error ] \033[m Package not found.\n" 1>&2
2022-05-31 09:20:51 -04:00
exit 1
fi
exit 0
;;
cache|-c)
# Require the script to be run as root
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
2022-06-07 10:43:25 -04:00
printf "\033[1;31m [ $error ] \033[m Please run Glacier as root.\n"
2022-05-31 09:20:51 -04:00
exit
fi
printf "\033[1;34m [ ? ] \033[m Enter package name: " && read input
printf "\033[1;34m [ i ] \033[m Caching $input.tar.gz...\n"
printf "\033[1;34m [ i ] \033[m Checking databases... " && $GLACIER_DOWNLOAD_BACKEND $GREPO1/$input.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO2/$input.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO3/$input.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO4/$input.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO5/$input.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO6/$input.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO7/$input.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO8/$input.tar.gz
if [ "$?" != "0" ]; then
printf "\033[1;31m [ $error ] \033[m Package not found.\n" 1>&2
exit 1
fi
2022-06-08 08:54:10 -04:00
printf "$blue [ i ]$reset Verifying integrity of package...\n"
2022-06-08 08:57:46 -04:00
sha256sum $input.tar.gz
2022-05-31 09:20:51 -04:00
mv $input.tar.gz /var/cache/glacier
2022-06-10 10:06:21 -04:00
printf "\033[1;32m [ $check ] \033[m Operation completed.\n"
2022-05-31 09:20:51 -04:00
exit 0
;;
cache-install|-ci)
# Require the script to be run as root
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
2022-06-07 10:43:25 -04:00
echo "$red[ $error ]$reset Please run Glacier as root.\n"
2022-05-31 09:20:51 -04:00
exit
fi
printf "\033[1;34m [ ? ] \033[m Enter package name: " && read input
2022-06-10 10:06:21 -04:00
printf "\033[1;34m [ i ] \033[m Checking cache for $input.tar.gz...\n"
2022-05-31 09:20:51 -04:00
cd /var/cache/glacier && cp $input.tar.gz /tmp && cd /tmp
if [ "$?" != "0" ]; then
2022-06-07 10:43:25 -04:00
printf "\033[1;31m [ $error ] \033[m Could not fetch package from cache.\n" 1>&2
2022-05-31 09:20:51 -04:00
exit 1
fi
2022-06-10 10:06:21 -04:00
printf "\033[1;34m [ i ] \033[m Unpacking $input.tar.gz...\n"
2022-05-31 09:20:51 -04:00
mkdir $input && mv $input.tar.gz $input && cd $input
tar -xf $input.tar.gz
if [ "$?" != "0" ]; then
2022-06-07 10:43:25 -04:00
printf "\033[1;31m [ $error ] \033[m Could not unpack $input.tar.gz.\n" 1>&2
2022-05-31 09:20:51 -04:00
exit 1
fi
chmod +x INSTALL.sh
chmod +x $input.ts.sh
./INSTALL.sh # Actually executes installation script
2022-06-16 10:51:15 -04:00
if [ "$?" != "0" ]; then
2022-06-16 10:52:38 -04:00
printf "$red [ $error ]$reset Instructions were either unable to execute, or encountered an error while executing.\n" 1>&2
2022-06-16 10:51:15 -04:00
exit 1
fi
2022-05-31 09:20:51 -04:00
./$input.ts.sh
2022-06-10 10:07:03 -04:00
printf "\033[1;34m [ i ] \033[m Cleaning up...\n" # Status message
2022-05-31 09:20:51 -04:00
mv -v $input-pkginfo.json /etc/glacier/pkginfo
cd ..
rm -rvf $input
2022-06-10 10:07:03 -04:00
printf "\033[1;32m [ $check ] \033[m Operation completed.\n"
2022-05-31 09:20:51 -04:00
exit 0
;;
cache-clear|-cc)
# Require the script to be run as root
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
2022-06-07 10:43:25 -04:00
printf "\033[1;31m [ $error ] \033[m Please run Glacier as root.\n"
2022-05-31 09:20:51 -04:00
exit
fi
2022-06-09 10:05:35 -04:00
printf "\033[1;34m [ i ] \033[m Clearing cache...\n"
2022-06-07 10:43:25 -04:00
cd /var/cache/glacier && rm -rf *
if [ "$?" != "0" ]; then
printf "\033[1;31m [ $error ] \033[m Some items could not be cleared.\n" 1>&2
exit 1
fi
2022-06-09 10:05:35 -04:00
printf "\033[1;32m [ $check ] \033[m Cache cleared.\n"
2022-05-31 09:20:51 -04:00
exit 0
;;
--showDebugInfo)
2022-07-23 16:46:54 -04:00
printf "Glacier v2.2.1\n"
2022-07-23 16:55:18 -04:00
printf ":: Checking for viable download backend...\n"
whereis wget
whereis curl
whereis aria2c
2022-07-23 16:55:18 -04:00
printf ":: Checking which download backend is in use...\n"
echo $GLACIER_DOWNLOAD_BACKEND
2022-07-23 16:55:18 -04:00
printf ":: Checking if all Glacier directories and files are present...\n"
ls /etc | grep glacier
ls /etc/glacier
whereis make.conf
2022-07-23 16:55:18 -04:00
printf ":: Any missing files above, especially make.conf, will cause Glavier to behave abnormally.\n"
printf ":: Checking that unicode symbols display properly...\n"
2022-07-23 16:52:21 -04:00
printf "$check\n"
printf "$error\n"
printf "$warning\n"
printf "$question\n"
2022-07-23 16:46:28 -04:00
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"
2022-07-23 16:55:18 -04:00
printf ":: Ensuring repositories are correct...\n"
echo $GREPO1
echo $GREPO2
echo $GREPO3
echo $GREPO4
echo $GREPO5
echo $GREPO6
echo $GREPO7
echo $GREPO8
2022-07-23 16:55:18 -04:00
printf ":: Debug info has been gathered.\n"
printf ":: If you wish to save this information to a file, run 'glacier --showDebugInfo > glacier.debug'.\n"
2022-07-23 16:46:28 -04:00
exit 0
;;
2022-05-31 09:20:51 -04:00
-*|--*)
2022-06-08 08:01:20 -04:00
printf "$red [ $error ]$reset Unknown option, use 'glacier -h' to see usage.\n"
2022-06-03 08:57:22 -04:00
exit 1
;;
*)
2022-06-08 08:01:20 -04:00
printf "$red [ $error ]$reset Unknown option, use 'glacier -h' to see usage.\n"
2022-05-31 09:20:51 -04:00
exit 1
;;
esac
done
2022-07-23 13:00:43 -04:00
printf "$red [ $error ]$reset Unknown option, use 'glacier -h' to see usage.\n"