init
This commit is contained in:
commit
1816522a71
11 changed files with 229 additions and 0 deletions
8
lib/headers
Normal file
8
lib/headers
Normal file
|
@ -0,0 +1,8 @@
|
|||
#!/bin/sh
|
||||
|
||||
show_welcome_header() {
|
||||
[ "$SC_SKIP_WELCOME_HEADER" = "1" ] && return 0
|
||||
cat $SC_ASSETS/saluco-header.txt
|
||||
echo "Welcome, $(whoami) ($(id -u))!"
|
||||
echo ""
|
||||
}
|
16
lib/logger
Normal file
16
lib/logger
Normal file
|
@ -0,0 +1,16 @@
|
|||
#!/bin/sh
|
||||
|
||||
__sc_log() {
|
||||
level=$1; shift
|
||||
echo "[$level] $@"
|
||||
}
|
||||
|
||||
alias LOGD="__sc_log debug"
|
||||
alias LOGI="__sc_log info"
|
||||
alias LOGW="__sc_log warn"
|
||||
alias LOGE="__sc_log error"
|
||||
|
||||
fatal_log() {
|
||||
__sc_log fatal $@
|
||||
exit 1
|
||||
}
|
5
lib/manipulation
Normal file
5
lib/manipulation
Normal file
|
@ -0,0 +1,5 @@
|
|||
#!/bin/sh
|
||||
|
||||
get_first_in_list() {
|
||||
echo $1
|
||||
}
|
64
lib/pm
Normal file
64
lib/pm
Normal file
|
@ -0,0 +1,64 @@
|
|||
#!/bin/sh
|
||||
|
||||
# sc.requires: logger
|
||||
|
||||
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
|
||||
echo dnf
|
||||
elif command -v yum > /dev/null; then
|
||||
echo yum
|
||||
elif command -v zypper > /dev/null; then
|
||||
echo zypper
|
||||
elif command -v brew > /dev/null; then
|
||||
echo brew
|
||||
elif command -v apk > /dev/null; then
|
||||
echo apk
|
||||
elif command -v nix-env > /dev/null; then
|
||||
echo nix
|
||||
else
|
||||
fatal_log "no supported package manager found"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
SC_PACKAGE_MANAGER="${SC_PACKAGE_MANAGER:-$(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 ;;
|
||||
*)
|
||||
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" ;;
|
||||
*)
|
||||
fatal_log "unsupported package manager: $SC_PACKAGE_MANAGER"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
18
lib/privileges
Normal file
18
lib/privileges
Normal file
|
@ -0,0 +1,18 @@
|
|||
#!/bin/sh
|
||||
|
||||
escalate_command() {
|
||||
if [ "$(id -u)" = "0" ]; then
|
||||
$@
|
||||
else
|
||||
sudo -E $@
|
||||
fi
|
||||
}
|
||||
|
||||
escalate() {
|
||||
export SC_ESCALATED=1
|
||||
export SC_SKIP_WELCOME_HEADER=1
|
||||
|
||||
echo "e: sc-client $@"
|
||||
|
||||
escalate_command $(get_first_in_list $SC_COMMAND) $@
|
||||
}
|
10
lib/setup-env
Normal file
10
lib/setup-env
Normal file
|
@ -0,0 +1,10 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
. $SC_SRC/lib/variables
|
||||
|
||||
. $SC_LIB/headers
|
||||
. $SC_LIB/logger
|
||||
. $SC_LIB/manipulation
|
||||
. $SC_LIB/privileges
|
6
lib/variables
Normal file
6
lib/variables
Normal file
|
@ -0,0 +1,6 @@
|
|||
#!/bin/sh
|
||||
|
||||
export SC_SRC="${SC_SRC:-/opt/sconnect}"
|
||||
|
||||
export SC_LIB="$SC_SRC/lib"
|
||||
export SC_ASSETS="$SC_SRC/assets"
|
Loading…
Add table
Add a link
Reference in a new issue