feat: a3 and other things

This commit is contained in:
Strix 2024-06-06 02:00:49 +02:00
parent dd7516e6d7
commit 4be03b9764
7 changed files with 180 additions and 82 deletions

View file

@ -1,6 +0,0 @@
_
___ __ _| |_ _ ___ ___
/ __|/ _` | | | | |/ __/ _ \
\__ \ (_| | | |_| | (_| (_) |
|___/\__,_|_|\__,_|\___\___/

8
bin/sc
View file

@ -1,8 +1,8 @@
#!/bin/sh
SC_COMMAND="$0 $@"
SC_SRC=${SC_SRC:-/opt/sconnect}
. $SC_SRC/lib/setup-env
SC_LIB=${SC_LIB:-/usr/lib/sc}
. $SC_LIB/setup-env
SC_HOSTS=""
@ -29,8 +29,8 @@ for host in $SC_HOSTS; do
else
LOGI "attempting to install on $host..."
rsync -au $SC_SRC/. $host:/opt/sconnect
ssh $host SC_SKIP_WELCOME_HEADER=1 /opt/sconnect/bin/sc-client lib privileges escalate_command install -m a+rx -o root /opt/sconnect/bin/sc /usr/bin
ssh $host SC_SKIP_WELCOME_HEADER=1 /opt/sconnect/bin/sc-client lib privileges escalate_command install -m a+rx -o root /opt/sconnect/bin/sc-client /usr/bin
ssh $host SC_SKIP_WELCOME_HEADER=1 SC_INCLUDE_LIBS="privileges" /opt/sconnect/bin/sc-client eval escalate_command install -m a+rx -o root /opt/sconnect/bin/sc /usr/bin
ssh $host SC_SKIP_WELCOME_HEADER=1 SC_INCLUDE_LIBS="privileges" /opt/sconnect/bin/sc-client eval escalate_command install -m a+rx -o root /opt/sconnect/bin/sc-client /usr/bin
LOGI "installed"
fi
;;

View file

@ -1,8 +1,8 @@
#!/bin/sh
SC_COMMAND="$0 $@"
SC_SRC=${SC_SRC:-/opt/sconnect}
. $SC_SRC/lib/setup-env
SC_LIB=${SC_LIB:-/usr/lib/sc}
. $SC_LIB/setup-env
show_welcome_header
@ -11,9 +11,12 @@ command=$1
shift
case $command in
update)
LOGI attempting to update system...
escalate lib pm upgrade_packages
install-dotfiles)
[ -d "$HOME/.dotfiles" ] && fatal_log "dotfiles already exist"
LOGI installing dotfiles...
git clone https://git.saluco.nl/strix/dotfiles $HOME/.dotfiles
cd $HOME/.dotfiles
./dot a
;;
run)
if [ -z "$@" ]; then
@ -27,18 +30,20 @@ run)
else
$@
fi
;;
lib)
[ $# -lt 2 ] && fatal_log "usage: $0 lib <library> <command>"
. $SC_LIB/$1
shift
pm)
. $SC_LIB/pm
case $1 in
upgrade) pm_upgrade_packages ;;
install) shift; pm_install_packages $@ ;;
remove) shift; pm_remove_packages $@ ;;
esac
;;
eval)
LOGD "evaluating: $@..."
$@
;;
check)
exit 0
;;
*)
fatal_log "invalid command"
;;
check) exit 0 ;;
*) fatal_log "invalid command" ;;
esac

View file

@ -1,16 +1,36 @@
#!/bin/sh
__sc_log() {
level=$1; shift
echo "[$level] $@"
# levels:
# DEBUG = 0
# INFO = 1
# WARN = 2
# ERROR = 3
SC_LOGGER_LEVEL=${SC_LOGGER_LEVEL:-1}
__sc_log_level_to_text() {
case $1 in
0) echo "debug" ;;
1) echo "info" ;;
2) echo "warn" ;;
3) echo "error" ;;
4) echo "fatal" ;;
esac
}
alias LOGD="__sc_log debug"
alias LOGI="__sc_log info"
alias LOGW="__sc_log warn"
alias LOGE="__sc_log error"
__sc_log() {
level=$1
shift
if [ "$level" -ge "$SC_LOGGER_LEVEL" ]; then
echo "[$(__sc_log_level_to_text $level)] $@"
fi
}
alias LOGD="__sc_log 0"
alias LOGI="__sc_log 1"
alias LOGW="__sc_log 2"
alias LOGE="__sc_log 3"
fatal_log() {
__sc_log fatal $@
__sc_log 4 $@
exit 1
}

141
lib/pm
View file

@ -2,22 +2,22 @@
# sc.requires: logger
detect_package_manager() {
if command -v apt > /dev/null; then
pm_detect_package_manager() {
if command -v apt >/dev/null; then
echo apt
elif command -v pacman > /dev/null; then
echo arch
elif command -v dnf > /dev/null; then
elif command -v pacman >/dev/null; then
echo pacman
elif command -v dnf >/dev/null; then
echo dnf
elif command -v yum > /dev/null; then
elif command -v yum >/dev/null; then
echo yum
elif command -v zypper > /dev/null; then
elif command -v zypper >/dev/null; then
echo zypper
elif command -v brew > /dev/null; then
elif command -v brew >/dev/null; then
echo brew
elif command -v apk > /dev/null; then
elif command -v apk >/dev/null; then
echo apk
elif command -v nix-env > /dev/null; then
elif command -v nix-env >/dev/null; then
echo nix
else
fatal_log "no supported package manager found"
@ -25,39 +25,110 @@ detect_package_manager() {
fi
}
SC_PACKAGE_MANAGER="${SC_PACKAGE_MANAGER:-$(detect_package_manager)}"
SC_PACKAGE_MANAGER="${SC_PACKAGE_MANAGER:-$(pm_detect_package_manager)}"
upgrade_packages() {
case $SC_PACKAGE_MANAGER in
apt) apt update && apt upgrade -y ;;
arch) pacman -Syyu --noconfirm ;;
dnf) dnf upgrade -y ;;
yum) yum update -y ;;
zypper) zypper refresh && zypper update -y ;;
brew) brew update && brew upgrade ;;
apk) apk update && apk upgrade ;;
nix) nix-channel --update && nix-env -u ;;
pm_upgrade_packages() {
LOGI "Upgrading packages using ${SC_PACKAGE_MANAGER}..."
case "$SC_PACKAGE_MANAGER" in
apt)
sudo apt update && sudo apt upgrade -y
;;
pacman)
sudo pacman -Syu
;;
dnf)
sudo dnf upgrade --refresh -y
;;
yum)
sudo yum update -y
;;
zypper)
sudo zypper refresh && sudo zypper update -y
;;
brew)
brew update && brew upgrade
;;
apk)
sudo apk update && sudo apk upgrade
;;
nix)
nix-env --upgrade
;;
*)
fatal_log "unsupported package manager: $SC_PACKAGE_MANAGER"
fatal_log "Unsupported package manager: ${SC_PACKAGE_MANAGER}"
exit 1
;;
esac
}
install_package() {
[ $# -lt 1 ] && fatal_log "usage: install_package <package>" && exit 1
package=$1
case $SC_PACKAGE_MANAGER in
apt) apt install -y "$package" ;;
arch) pacman -S --noconfirm "$package" ;;
dnf) dnf install -y "$package" ;;
yum) yum install -y "$package" ;;
zypper) zypper install -y "$package" ;;
brew) brew install "$package" ;;
apk) apk add "$package" ;;
nix) nix-env -iA nixpkgs."$package" ;;
pm_install_packages() {
LOGI "Installing packages using ${SC_PACKAGE_MANAGER}..."
packages="$@"
case "$SC_PACKAGE_MANAGER" in
apt)
sudo apt install -y $packages
;;
pacman)
sudo pacman -S --noconfirm $packages
;;
dnf)
sudo dnf install -y $packages
;;
yum)
sudo yum install -y $packages
;;
zypper)
sudo zypper install -y $packages
;;
brew)
brew install $packages
;;
apk)
sudo apk add $packages
;;
nix)
nix-env -i $packages
;;
*)
fatal_log "unsupported package manager: $SC_PACKAGE_MANAGER"
fatal_log "Unsupported package manager: ${SC_PACKAGE_MANAGER}"
exit 1
;;
esac
}
pm_remove_packages() {
LOGI "Removing packages using ${SC_PACKAGE_MANAGER}..."
packages="$@"
case "$SC_PACKAGE_MANAGER" in
apt)
sudo apt remove -y $packages
;;
pacman)
sudo pacman -Rns --noconfirm $packages
;;
dnf)
sudo dnf remove -y $packages
;;
yum)
sudo yum remove -y $packages
;;
zypper)
sudo zypper remove -y $packages
;;
brew)
brew uninstall $packages
;;
apk)
sudo apk del $packages
;;
nix)
nix-env -e $packages
;;
*)
fatal_log "Unsupported package manager: ${SC_PACKAGE_MANAGER}"
exit 1
;;
esac

View file

@ -2,9 +2,19 @@
set -e
. $SC_SRC/lib/variables
if [ $SC_DEBUG ]; then
SC_LOGGER_LEVEL=0
echo "*** SC DEBUG ***"
fi
. $SC_LIB/variables
. $SC_LIB/headers
. $SC_LIB/logger
. $SC_LIB/manipulation
. $SC_LIB/privileges
for l in $SC_INCLUDE_LIBS; do
[ -f "$SC_LIB/$l" ] || continue
LOGD "including $l..."
. $SC_LIB/$l
done

View file

@ -1,6 +1,4 @@
#!/bin/sh
export SC_SRC="${SC_SRC:-/opt/sconnect}"
export SC_LIB="$SC_SRC/lib"
export SC_ASSETS="$SC_SRC/assets"
export SC_LIB=${SC_LIB:-/usr/lib/sc}
export SC_ASSETS="$SC_LIB/assets"