feat: a3 and other things
This commit is contained in:
parent
dd7516e6d7
commit
4be03b9764
7 changed files with 180 additions and 82 deletions
|
@ -1,6 +0,0 @@
|
||||||
_
|
|
||||||
___ __ _| |_ _ ___ ___
|
|
||||||
/ __|/ _` | | | | |/ __/ _ \
|
|
||||||
\__ \ (_| | | |_| | (_| (_) |
|
|
||||||
|___/\__,_|_|\__,_|\___\___/
|
|
||||||
|
|
8
bin/sc
8
bin/sc
|
@ -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
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
;;
|
;;
|
||||||
lib)
|
|
||||||
[ $# -lt 2 ] && fatal_log "usage: $0 lib <library> <command>"
|
pm)
|
||||||
. $SC_LIB/$1
|
. $SC_LIB/pm
|
||||||
shift
|
case $1 in
|
||||||
|
upgrade) pm_upgrade_packages ;;
|
||||||
|
install) shift; pm_install_packages $@ ;;
|
||||||
|
remove) shift; pm_remove_packages $@ ;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
eval)
|
||||||
|
LOGD "evaluating: $@..."
|
||||||
$@
|
$@
|
||||||
;;
|
;;
|
||||||
check)
|
check) exit 0 ;;
|
||||||
exit 0
|
*) fatal_log "invalid command" ;;
|
||||||
;;
|
|
||||||
*)
|
|
||||||
fatal_log "invalid command"
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
|
|
36
lib/logger
36
lib/logger
|
@ -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
|
||||||
}
|
}
|
125
lib/pm
125
lib/pm
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
# 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
|
||||||
|
@ -25,39 +25,110 @@ 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)
|
||||||
|
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
|
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
|
||||||
|
;;
|
||||||
|
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
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -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
|
|
@ -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"
|
|
Loading…
Reference in a new issue