Glacier v3.0.0
This commit is contained in:
322
src/glacier
Executable file
322
src/glacier
Executable file
@@ -0,0 +1,322 @@
|
||||
#!/bin/sh
|
||||
# Glacier - manage installed packages on a Linux system
|
||||
# This program is free software - you can distribute it
|
||||
# under the terms of the GNU General Public License v3.0,
|
||||
# or at your option, any later version.
|
||||
|
||||
# A copy of the GNU General Public License should have been
|
||||
# recieved along with this program. If not, see
|
||||
# <https://www.gnu.org/licenses>
|
||||
|
||||
source /etc/glacier/hooks
|
||||
|
||||
get_pkg() {
|
||||
printf "$blue[ i ]$reset Downloading archive for package '$2'...\n"
|
||||
$GLACIER_DOWNLOAD_BACKEND $GREPO1/$2.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO2/$2.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO3/$2.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO4/$2.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO5/$2.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO6/$2.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO7/$2.tar.gz || $GLACIER_DOWNLOAD_BACKEND $GREPO8/$2.tar.gz
|
||||
if [ "$?" != "0" ]; then
|
||||
printf "$red[ $error ]$reset Package '$2' not found.\n"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# implementing this later because this whole section is a clusterfuck
|
||||
#int_check () {
|
||||
# printf "$blue[ i ]$reset Checking package integrity...\n"
|
||||
# LOCAL_CHECKSUM=$(cat $2.checksum)
|
||||
# hsh $2.tar.gz $LOCAL_CHECKSUM
|
||||
# if [ "$?" != "0" ]; then
|
||||
# printf "$red[ $error ]$reset Integrity check failed.\n"
|
||||
# exit 1
|
||||
# else
|
||||
# printf "$green[ $check ]$reset Integrity check passed.\n"
|
||||
# exit 0
|
||||
# fi
|
||||
#}
|
||||
|
||||
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
|
||||
if [ "$?" != "0" ]; then
|
||||
printf "$red[ $error ]$reset Could not unpack $2.tar.gz.\n"
|
||||
cd .. && rm -rf $2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
installpkg() {
|
||||
printf "$blue[ i ]$reset Installing $2...\n"
|
||||
sleep 1
|
||||
chmod +x *
|
||||
./INSTALL.sh
|
||||
if [ "$?" != "0" ]; then
|
||||
printf "$red[ $error ]$reset Failed to update $2.\n"
|
||||
cd .. && rm -rf $2
|
||||
exit 1
|
||||
fi
|
||||
./$2.ts.sh
|
||||
mv $2-pkginfo.json /etc/glacier/pkginfo
|
||||
}
|
||||
|
||||
updatepkg() {
|
||||
printf "$blue[ i ]$reset Updating $2...\n"
|
||||
sleep 1
|
||||
chmod +x *
|
||||
./UPDATE.sh
|
||||
if [ "$?" != "0" ]; then
|
||||
printf "$red[ $error ]$reset Failed to update $2.\n"
|
||||
cd .. && rm -rf $2
|
||||
exit 1
|
||||
fi
|
||||
./$2.ts.sh
|
||||
}
|
||||
|
||||
removepkg() {
|
||||
printf "$blue[ i ]$reset Removing $2...\n"
|
||||
sleep 1
|
||||
chmod +x *
|
||||
./REMOVE.sh
|
||||
if [ "$?" != "0" ]; then
|
||||
printf "$red[ $error ]$reset Failed to remove $2.\n"
|
||||
cd .. && rm -rf $2
|
||||
exit 1
|
||||
fi
|
||||
rm /var/log/glacier/$2.timestamp
|
||||
rm /etc/glacier/pkginfo/$2-pkginfo.json
|
||||
}
|
||||
|
||||
installpkg_from_cache() {
|
||||
printf "$blue[ i ]$reset Installing $2 from cache...\n"
|
||||
sleep 1
|
||||
cd /var/cache/glacier && cp $2.tar.gz /tmp && cd /tmp
|
||||
if [ "$?" != "0" ]; then
|
||||
printf "$red[ $error ]$reset Package does not exist in cache.\n"
|
||||
exit 1
|
||||
fi
|
||||
unpack_pkg
|
||||
install_pkg
|
||||
}
|
||||
|
||||
clear_cache() {
|
||||
printf "$blue[ i ]$reset Clearing cache...\n"
|
||||
sleep 1
|
||||
cd /var/cache/glacier && rm -rf *
|
||||
if [ "$?" != "0" ]; then
|
||||
printf "$red[ $error ]$reset Some items could not be cleared.\n"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
debug_info() {
|
||||
printf "$blue>> Glacier v3.0.0$reset\n"
|
||||
printf ">> Checking for valid 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 files are present...\n"
|
||||
whereis glacier glacier.conf make.conf
|
||||
ls /var/log | grep glacier
|
||||
ls /var/cache | grep glacier
|
||||
printf ">> If any files are missing, Glacier will not behave properly.\n"
|
||||
printf ">> Checking if terminal can output unicode symbols...\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 "NOTE: If you use a custom colorscheme, colors will not match.\n"
|
||||
printf ">> Checking if repositories are valid...\n"
|
||||
echo $GREPO1
|
||||
echo $GREPO2
|
||||
echo $GREPO3
|
||||
echo $GREPO4
|
||||
echo $GREPO5
|
||||
echo $GREPO6
|
||||
echo $GREPO7
|
||||
echo $GREPO8
|
||||
printf ">> Checking which shell is in use...\n"
|
||||
which $SHELL
|
||||
printf "NOTE: If you use zsh, a percentage symbol may appear after some lines.\n"
|
||||
printf ">> Gathered debug information.\n"
|
||||
printf ">> To save this information to a file, run:\n"
|
||||
printf ">> $ glacier --debuginfo > glacier.debug\n"
|
||||
}
|
||||
|
||||
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
|
||||
printf "$blue>> Package version:$reset " && cat /etc/glacier/pkginfo/$2-pkginfo.json | jq .package_version
|
||||
printf "$blue>> Package description:$reset " && cat /etc/glacier/pkginfo/$2-pkginfo.json | jq .package_description
|
||||
printf "$blue>> Source tree size:$reset " && cat /etc/glacier/pkginfo/$2-pkginfo.json | jq .src_tree_size
|
||||
printf "$blue>> Size of installed files:$reset " && cat /etc/glacier/pkginfo/$2-pkginfo.json | jq .exec_size
|
||||
printf "$blue>> License:$reset " && cat /etc/glacier/pkginfo/$2-pkginfo.json | jq .license
|
||||
printf "$blue>> Installation date:$reset " && cat /var/log/glacier/$2.timestamp
|
||||
}
|
||||
|
||||
cleanup () {
|
||||
printf "$blue[ i ]$reset Cleaning up...\n"
|
||||
cd .. && rm -rf $2
|
||||
}
|
||||
|
||||
case $1 in
|
||||
-h|--help)
|
||||
printf "Glacier - Manage installed packages on the system\n"
|
||||
printf "usage: glacier {action} {package-name}\n"
|
||||
printf "\n"
|
||||
printf "=== Information ===\n"
|
||||
printf "glacier {-h/--help} - Show this message and exit\n"
|
||||
printf "glacier {-v/--version} - Show the version and exit\n"
|
||||
printf "\n"
|
||||
printf "=== Operations ===\n"
|
||||
printf "glacier {-f/install} - Install a new package\n"
|
||||
printf "glacier {-u/update} - Update an installed package\n"
|
||||
printf "glacier {-x/remove} - Remove an installed package\n"
|
||||
printf "glacier {-q/query} - Query an installed package\n"
|
||||
printf "glacier {-c/cache} - Download a package to the cache\n"
|
||||
printf "glacier {-ci/cache-install} - Install a package from the cache\n"
|
||||
printf "glacier {-cc/cache-clear} - Clear the cache\n"
|
||||
printf "\n"
|
||||
printf "=== Debugging ===\n"
|
||||
printf "glacier {--debuginfo} - Show debugging information\n"
|
||||
printf "\n"
|
||||
printf "=== Licensing ===\n"
|
||||
printf "This program is free software: you can redistribute it and/or modify it\n"
|
||||
printf "under the terms of the GNU General Public License as published by the\n"
|
||||
printf "Free Software Foundation, either version 3 of the License, or (at your option) any later version.\n"
|
||||
exit 0
|
||||
;;
|
||||
-v|--version)
|
||||
printf "$blue Glacier v3.0.0$reset\n"
|
||||
exit 0
|
||||
;;
|
||||
-f|-install)
|
||||
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
|
||||
printf "$red[ $error ]$reset Please run Glacier as root.\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf "$blue[ i ]$reset Installing package '$2'.\n"
|
||||
read -p "$(printf "$blue[ ? ]$reset Proceed with this operation? (y/n) ")" -n 1 -r
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
cd /opt/glacier/workspace
|
||||
printf "\n"
|
||||
get_pkg "$@"
|
||||
#int_check # Will implement this later on
|
||||
unpack_pkg "$@"
|
||||
installpkg "$@"
|
||||
cleanup "$@"
|
||||
printf "$green[ $check ]$reset Operation completed.\n"
|
||||
exit 0
|
||||
fi
|
||||
;;
|
||||
-u|update)
|
||||
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
|
||||
printf "$red[ $error ]$reset Please run Glacier as root.\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf "$blue[ i ]$reset Updating package '$2'.\n"
|
||||
read -p "$(printf "$blue[ ? ]$reset Proceed with this operation? (y/n) ")" -n 1 -r
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
cd /opt/glacier/workspace
|
||||
printf "\n"
|
||||
get_pkg "$@"
|
||||
#int_check
|
||||
unpack_pkg "$@"
|
||||
updatepkg "$@"
|
||||
cleanup "$@"
|
||||
printf "$green[ $check ]$reset Operation completed.\n"
|
||||
exit 0
|
||||
fi
|
||||
;;
|
||||
-x|remove)
|
||||
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
|
||||
printf "$red[ $error ]$reset Please run Glacier as root.\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf "$blue[ i ]$reset Removing package '$2'.\n"
|
||||
read -p "$(printf "$blue[ ? ]$reset Proceed with this operation? (y/n) ")" -n 1 -r
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
cd /opt/glacier/workspace
|
||||
printf "\n"
|
||||
get_pkg "$@"
|
||||
#int_check
|
||||
unpack_pkg "$@"
|
||||
removepkg "$@"
|
||||
cleanup "$@"
|
||||
printf "$green[ $check ]$reset Operation completed.\n"
|
||||
exit 0
|
||||
fi
|
||||
;;
|
||||
-q|query)
|
||||
query "$@"
|
||||
exit 0
|
||||
;;
|
||||
-c|cache)
|
||||
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
|
||||
printf "$red[ $error ]$reset Please run Glacier as root.\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf "$blue[ i ]$reset Caching package '$2'.\n"
|
||||
read -p "$(printf "$blue[ ? ]$reset Proceed with this operation? (y/n) ")" -n 1 -r
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
cd /var/cache/glacier
|
||||
printf "\n"
|
||||
get_pkg "$@"
|
||||
printf "$green[ $check ]$reset Operation completed.\n"
|
||||
exit 0
|
||||
fi
|
||||
;;
|
||||
-ci|cache-install)
|
||||
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
|
||||
printf "$red[ $error ]$reset Please run Glacier as root.\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf "$blue[ i ]$reset Installing package '$2' from cache.\n"
|
||||
read -p "$(printf "$blue[ ? ]$reset Proceed with this operation? (y/n) ")" -n 1 -r
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
cd /var/cache/glacier
|
||||
mv $2.tar.gz /opt/glacier/workspace
|
||||
cd /opt/glacier/workspace
|
||||
printf "\n"
|
||||
unpack_pkg "$@"
|
||||
installpkg "$@"
|
||||
cleanup "$@"
|
||||
printf "$green[ $check ]$reset Operation completed.\n"
|
||||
exit 0
|
||||
fi
|
||||
;;
|
||||
-cc|cache-clear)
|
||||
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
|
||||
printf "$red[ $error ]$reset Please run Glacier as root.\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
clear_cache "$@"
|
||||
printf "$green[ $check ]$reset Operation completed.\n"
|
||||
exit 0
|
||||
;;
|
||||
--debuginfo)
|
||||
debug_info "$@"
|
||||
exit 0
|
||||
;;
|
||||
-*|--*)
|
||||
printf "$red[ $error ]$reset Unknown option, see 'glacier -h' for usage.\n"
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
printf "$red[ $error ]$reset Unknown option, see 'glacier -h' for usage.\n"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
printf "$red[ $error ]$reset Unknown option, see 'glacier -h' for usage.\n"
|
||||
exit 1
|
||||
Reference in New Issue
Block a user