aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/%HOME%
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2017-12-01 17:49:21 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2017-12-01 17:49:21 +0300
commit52e285cd3a639b086bdcc9497f2d0d4949390610 (patch)
tree688c0e8077fd948e93f40292ebfe8dc58dc8130f /%HOME%
parentfix_permissions.sh: code style (diff)
downloadlinux-home-52e285cd3a639b086bdcc9497f2d0d4949390610.tar.gz
linux-home-52e285cd3a639b086bdcc9497f2d0d4949390610.zip
os.sh: support Fedora
Also, OS detection has been reworked a bit.
Diffstat (limited to '')
-rw-r--r--%HOME%/.bash_utils/os.sh62
1 files changed, 41 insertions, 21 deletions
diff --git a/%HOME%/.bash_utils/os.sh b/%HOME%/.bash_utils/os.sh
index c38bbbe..9058b38 100644
--- a/%HOME%/.bash_utils/os.sh
+++ b/%HOME%/.bash_utils/os.sh
@@ -7,40 +7,41 @@
_os=''
+_CYGWIN='Cygwin'
+_UBUNTU='Ubuntu'
+_MINT='Linux Mint'
+_ARCH='Arch Linux'
+_FEDORA='Fedora'
+
os_detect() {
- command -v uname > /dev/null \
- && [ "$( uname -o )" == 'Cygwin' ] \
- && _os='Cygwin' \
+ command -v uname > /dev/null \
+ && [ "$( uname -o )" == "$_CYGWIN" ] \
+ && _os="$_CYGWIN" \
&& return 0
[ -r /etc/os-release ] \
&& _os="$( . /etc/os-release && echo "$NAME" )" \
+ && test "$_os" == "$_UBUNTU" \
+ -o "$_os" == "$_MINT" \
+ -o "$_os" == "$_ARCH" \
+ -o "$_os" == "$_FEDORA" \
&& return 0
+ _os=''
return 1
}
os_detect
-os_detected() {
- test -n "$_os"
-}
-
-os_is_cygwin() {
- test "$_os" == 'Cygwin'
-}
-
-os_is_ubuntu() {
- test "$_os" == 'Ubuntu'
-}
+os_detected() { test -n "$_os" ; }
-os_is_linux_mint() {
- test "$_os" == 'Linux Mint'
-}
+os_is_cygwin() { test "$_os" == "$_CYGWIN" ; }
+os_is_ubuntu() { test "$_os" == "$_UBUNTU" ; }
+os_is_mint() { test "$_os" == "$_MINT" ; }
+os_is_arch() { test "$_os" == "$_ARCH" ; }
+os_is_fedora() { test "$_os" == "$_FEDORA" ; }
-os_is_arch() {
- test "$_os" == 'Arch Linux'
-}
+# Cygwin
pkg_list_cygwin() (
set -o errexit -o nounset -o pipefail
@@ -50,6 +51,8 @@ pkg_list_cygwin() (
| cut -d ' ' -f 1
)
+# Ubuntu/Linux Mint
+
setup_pkg_list_ubuntu() (
set -o errexit -o nounset -o pipefail
@@ -77,9 +80,13 @@ pkg_list_ubuntu() (
| cut -d ':' -f 1
)
+# Arch Linux
+
setup_pkg_list_arch() (
set -o errexit -o nounset -o pipefail
+ # Assuming you only selected groups 'base and 'base-devel' during
+ # installation.
local -ra groups=(base base-devel)
pacman -Q --groups -q -- ${groups[@]+"${groups[@]}"} | sort
@@ -96,16 +103,29 @@ pkg_list_arch() {
pacman -Qq
}
+# Fedora
+
+pkg_list_fedora() (
+ set -o errexit -o nounset -o pipefail
+
+ rpm --queryformat="%{NAME}\n" -qa | sort
+)
+
+# Generic routines
+
pkg_list() (
set -o errexit -o nounset -o pipefail
if os_is_cygwin; then
pkg_list_cygwin
- elif os_is_ubuntu || os_is_linux_mint; then
+ elif os_is_ubuntu || os_is_mint; then
pkg_list_ubuntu
elif os_is_arch; then
pkg_list_arch
+ elif os_is_fedora; then
+ pkg_list_fedora
else
+ echo "${FUNCTION[0]}: unsupported OS" >&2
return 1
fi
)