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 #!/bin/sh
SC_COMMAND="$0 $@" SC_COMMAND="$0 $@"
SC_SRC=${SC_SRC:-/opt/sconnect} SC_LIB=${SC_LIB:-/usr/lib/sc}
. $SC_SRC/lib/setup-env . $SC_LIB/setup-env
SC_HOSTS="" SC_HOSTS=""
@ -29,8 +29,8 @@ for host in $SC_HOSTS; do
else else
LOGI "attempting to install on $host..." LOGI "attempting to install on $host..."
rsync -au $SC_SRC/. $host:/opt/sconnect 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 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 /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-client /usr/bin
LOGI "installed" LOGI "installed"
fi fi
;; ;;

View file

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

View file

@ -1,16 +1,36 @@
#!/bin/sh #!/bin/sh
__sc_log() { # levels:
level=$1; shift # DEBUG = 0
echo "[$level] $@" # 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" __sc_log() {
alias LOGI="__sc_log info" level=$1
alias LOGW="__sc_log warn" shift
alias LOGE="__sc_log error" 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() { fatal_log() {
__sc_log fatal $@ __sc_log 4 $@
exit 1 exit 1
} }

153
lib/pm
View file

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

View file

@ -2,9 +2,19 @@
set -e 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/headers
. $SC_LIB/logger . $SC_LIB/logger
. $SC_LIB/manipulation . $SC_LIB/manipulation
. $SC_LIB/privileges . $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 #!/bin/sh
export SC_SRC="${SC_SRC:-/opt/sconnect}" export SC_LIB=${SC_LIB:-/usr/lib/sc}
export SC_ASSETS="$SC_LIB/assets"
export SC_LIB="$SC_SRC/lib"
export SC_ASSETS="$SC_SRC/assets"