upd/usr/local/bin/upd

114 lines
2.5 KiB
Bash
Executable File

#!/bin/bash
# version: 0.1.3
# file: upd
# Folder: /usr/local/bin
# By echolib
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
#======================================================================
# Tools
#======================================================================
# Check Command
if__command() {
! [[ `command -v $1` ]] \
&& echo -e "$I_Red Missing $1 command" \
&& exit
}
if__file() {
case "$2" in
source)
! [[ -f "$1" ]] \
&& echo "# Missing file: $1" \
&& exit
source "$1"
;;
create)
! [[ -f "$1" ]] \
&& touch "$1"
;;
read)
clear
cat "$1"
;;
esac
}
if__folder() {
if ! [[ -d "$1" ]];then
case "$2" in
make)
mkdir -p "$1"
if__folder "$1" check
;;
check)
echo "! Missing folder: $1"
exit
;;
*)
echo "! Missing folder: $1"
exit
;;
esac
fi
}
if__arch() {
if [[ `command -v apt` ]];then
arch="apt"
elif [[ `command -v pacman` ]];then
arch="pacman"
if__command "checkupdates"
[[ `command -v yay` ]] \
&& aur=yay
else
echo "! upd is not yet ready for this System"
exit
fi
}
#======================================================================
# Main
#======================================================================
if__arch
if__file "/etc/upd/upd.conf" source
if__file "$upd_script_tools" source
if__file "$upd_script_updater" source
if__file "$upd_script_check" source
if__file "$upd_script_upgrader" source
if__file "$upd_script_help" source
if__folder "$upd_dir_home" make
if__file "$upd_file_check" create
# create specific db file for aur packages
[[ "$aur" == "yay" ]] \
&& if__file "$upd_file_check_aur" create
case "$1" in
readme) if__file "/var/lib/upd/README.md" read ;;
help|--help|-h) upd__help ;;
""|check|-c) check__OPTIONS ;;
clean|-C) clean__OPTIONS ;;
-cr) upd_cr=true;upd__check_reboot ;;
list|-l) upd__list ;;
version|-v) awk 'NR==2 {print "# Installed:",$3}' "/usr/local/bin/upd" ;;
-vv) script__versions ;;
-vvv) verbose=true;script__versions ;;
-U) Updater ;;
-u) sysup="system";upg__main ;;
-f) sysup="full";upg__main ;;
--arch-mirror|-am) arch__mirror ;;
--arch-repair|-ar) arch__repair ;;
-A) sysup="aur";upg__main ;;
*) echo "! Bad argument '$1' : see upd --help" ;;
esac