Refactor install logic, use file-based overrides per OS/distro
This commit is contained in:
46
box_setup.sh
46
box_setup.sh
@@ -2,44 +2,52 @@
|
||||
|
||||
[[ $1 = "--help" ]] && {
|
||||
echo "\nusage: ./box_setup.sh [system-type]"
|
||||
echo "\nsystem-type options: work"
|
||||
echo "\nexamples:\n ./box_setup.sh\n ./box_setup.sh work\n"
|
||||
echo "\nsystem-type options: music_studio, programming"
|
||||
echo "\nexamples:\n ./box_setup.sh\n ./box_setup.sh music_studio\n"
|
||||
exit 0
|
||||
}
|
||||
|
||||
echo "---- settings vars for system type -----"
|
||||
|
||||
# determine OS and, if linux, distro
|
||||
[[ "$OSTYPE" = *"darwin"* ]] && setup_os="macos" || {
|
||||
[[ "$OSTYPE" = *"linux"* ]] && setup_os="linux" && {
|
||||
# determine OS and distro
|
||||
case "$OSTYPE" in
|
||||
(*linux*)
|
||||
setup_os="linux"
|
||||
[[ -f /etc/os-release ]] && . /etc/os-release
|
||||
setup_distro=$(echo "${NAME%% *}" | tr '[:upper:]' '[:lower:]')
|
||||
[[ -z "$setup_distro" ]] && echo "OS: linux; distro not detected" && exit 1
|
||||
}
|
||||
}
|
||||
[[ -z "$setup_os" ]] && echo "OS not detected" && exit 1
|
||||
;;
|
||||
(*darwin*)
|
||||
setup_os="macos"
|
||||
setup_distro="macos" # just repeat macos, but maybe there is some better value
|
||||
;;
|
||||
esac
|
||||
|
||||
# ensure OS and distro are set before proceeding
|
||||
[[ -z "$setup_os" ]] && echo "setup OS not detected" && exit 1
|
||||
[[ -z "$setup_distro" ]] && echo "setup distro not detected" && exit 1
|
||||
|
||||
# set package manager commands for installs
|
||||
[[ "$setup_os" = "macos" ]] && {
|
||||
install_cmd="brew install"
|
||||
update_pkg_manager_and_defs_cmd='brew update'
|
||||
update_pkgs_cmd='brew upgrade'
|
||||
} || {
|
||||
[[ "$setup_os" = "linux" ]] && {
|
||||
case "$setup_os" in
|
||||
(linux)
|
||||
case $setup_distro in
|
||||
(arch | artix)
|
||||
install_cmd="sudo pacman -S --noconfirm"
|
||||
update_pkg_manager_and_defs_cmd='' # don't; update system instead
|
||||
update_pkgs_cmd='sudo pacman -Syu'
|
||||
;;
|
||||
;;
|
||||
(debian)
|
||||
install_cmd="sudo apt install"
|
||||
update_pkg_manager_and_defs_cmd='sudo apt update'
|
||||
update_pkgs_cmd='sudo apt upgrade'
|
||||
;;
|
||||
;;
|
||||
esac
|
||||
}
|
||||
}
|
||||
;;
|
||||
(macos)
|
||||
install_cmd="brew install"
|
||||
update_pkg_manager_and_defs_cmd='brew update'
|
||||
update_pkgs_cmd='brew upgrade'
|
||||
;;
|
||||
esac
|
||||
|
||||
# export vars for scripts
|
||||
export BOX_SETUP_OS="$setup_os"
|
||||
|
||||
Reference in New Issue
Block a user