summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2016-12-03 13:13:30 +0100
committerErich Eckner <git@eckner.net>2016-12-03 13:13:30 +0100
commita9076d7afc9b78003e175195f3d94b207687d9b1 (patch)
treebd4af09404be0d9fda2532d858814b8f7ba3e4d0
parent0a038d8f0d7ce05c0cab6307178bb66c3eac4ea0 (diff)
downloadmounted-0.0.tar.xz
neue Version: 0.0v0.0
-rw-r--r--.gitignore4
-rw-r--r--Makefile65
-rw-r--r--man.commons.in22
-rwxr-xr-xmounted32
-rwxr-xr-xmounted.conf22
-rwxr-xr-xmounted.in68
6 files changed, 181 insertions, 32 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..2baa9ef
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+mounted
+man.commons
+*.common
+*.1
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..a3eb4ab
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,65 @@
+#
+# mounted - wrapper for use by conky to show mounted partitions
+#
+# Copyright (c) 2016 Erich Eckner <opensource at eckner dot net>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+# USA.
+#
+
+DESTDIR =
+ETCDIR = /etc
+BINDIR = /usr/bin
+MANDIR = /usr/share/man
+
+VERSION = 0.0
+
+all: man.commons mounted mounted.1
+
+%: %.in
+ sed " \
+ s/#VERSION#/$(VERSION)/; \
+ s@#BINDIR#@$(BINDIR)@; \
+ s@#ETCDIR#@$(ETCDIR)@; \
+ s@#HELPTEXT#\(\s\+\)#@ --help \1display this help and exit\n --version\1display version and exit@; \
+ " $< > $@
+ [ "$@" = "mounted" ] && chmod +x "$@" || true
+
+%.1: % man.commons
+ grep -v "^$<(" man.commons | sed '/^\[SEE ALSO]$$/{n;:a;N;/\[/b;s/\n/, /;ta;}' > "$<.common" && \
+ help2man \
+ -n 'Wrapper for use by cron to show mounted partitions' \
+ -o "$@" -N --include $<.common --no-discard-stderr "./$<"
+
+.PHONY: install dist clean
+
+install: all
+ install -D -m0755 mounted $(DESTDIR)$(BINDIR)/mounted
+ install -D -m0644 mounted.1 $(DESTDIR)$(MANDIR)/man1/mounted.1
+ install -D -m0644 mounted.conf $(DESTDIR)$(ETCDIR)/mounted.conf
+
+clean:
+ ls -A | \
+ grep "^\($(shell sed 's|\.|\\.|; s|\*|.*|; s|$$|\\|' .gitignore | tr '\n' '\|')\)\$$" | \
+ xargs -r rm
+
+dist: clean
+ git status --porcelain 2> /dev/null | grep -q "\S" && (git add .; git commit -m"neue Version: $(VERSION)") || true
+ ! git tag -d v$(VERSION) 2> /dev/null
+ git tag v$(VERSION)
+ git push
+ git push --tags
+
+# End of file
diff --git a/man.commons.in b/man.commons.in
new file mode 100644
index 0000000..01e7180
--- /dev/null
+++ b/man.commons.in
@@ -0,0 +1,22 @@
+[CONFIGURATION]
+The configfile \fB#ETCDIR#/mounted.conf\fP is a bash script, which defines the following variables and routines:
+.TP
+.B "onlyFs"
+mount entry must match regEx to be displayed
+.TP
+.B "ignoreFs"
+mount entry must not match regEx to be displayed
+.TP
+.B "mountName"
+routine printing substitution of mount point provided as \fI$1\fP
+[FILES]
+.TP
+.B "#BINDIR#/mounted"
+program file
+.TP
+.B "#ETCDIR#/mounted.conf"
+contains configuration
+[AUTHOR]
+.nf
+Erich Eckner <opensource at eckner dot net>
+.fi
diff --git a/mounted b/mounted
deleted file mode 100755
index 10f9ebc..0000000
--- a/mounted
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/bash
-
-set -o pipefail
-
-mounts="$(mount | grep "\(^/dev/\)\|\(ncpfs\)\|\(fuse.sshfs\)" | grep -v '\s/mnt/key\s')"
-lines=$(echo "${mounts}" | wc -l)
-
-for (( i=1; i<=${lines}; i++))
-do
- mount="$(echo "${mounts}" | head -n$i | tail -n1)"
- dev="$(echo "${mount}" | awk '{print $1}')"
- mp="$(echo "${mount}" | awk '{print $3}')"
- case "${mp}" in
- "/mnt/windows" ) mpa="win" ;;
- "/mnt/141.35.60.68_home_simulation" ) mpa="smh" ;;
- "/mnt/141.35.60.68_home_experiment" ) mpa="exh" ;;
- "/mnt/141.35.60.68_home_expshhg" ) mpa="esh" ;;
- "/mnt/141.35.60.68_home_erich" ) mpa="seh" ;;
- "/mnt/141.35.50.159_home" ) mpa="nse" ;;
- "/mnt/141.35.51.219_expshhg" ) mpa="jes" ;;
- "/mnt/141.35.60.68" ) mpa="sim" ;;
- "/mnt/192.168.0.12" ) mpa="hom" ;;
- "/mnt/usb/"* ) mpa="${mp#/mnt/usb/}" ;;
- * ) mpa="${mp}" ;;
- esac
- if [ "${mp}" == "/" ] || df -a | grep -q "^${dev} "
- then
- echo " \${color}${mpa} \${fs_used ${mp}}/\${fs_size ${mp}} \${fs_bar 6 ${mp}}"
- else
- echo " ${dev} -> ${mp}"
- fi
-done
diff --git a/mounted.conf b/mounted.conf
new file mode 100755
index 0000000..446af5c
--- /dev/null
+++ b/mounted.conf
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+set -o pipefail
+
+onlyFs='\(^/dev/\)\|\(ncpfs\)\|\(fuse.sshfs\)'
+ignoreFs='/mnt/key'
+
+mountName() {
+ case "${1}" in
+ "/mnt/windows" ) echo "win" ;;
+ "/mnt/141.35.60.68_home_simulation" ) echo "smh" ;;
+ "/mnt/141.35.60.68_home_experiment" ) echo "exh" ;;
+ "/mnt/141.35.60.68_home_expshhg" ) echo "esh" ;;
+ "/mnt/141.35.60.68_home_erich" ) echo "seh" ;;
+ "/mnt/141.35.50.159_home" ) echo "nse" ;;
+ "/mnt/141.35.51.219_expshhg" ) echo "jes" ;;
+ "/mnt/141.35.60.68" ) echo "sim" ;;
+ "/mnt/192.168.0.12" ) echo "hom" ;;
+ "/mnt/usb/"* ) echo "${1#/mnt/usb/}" ;;
+ * ) echo "${1}" ;;
+ esac
+}
diff --git a/mounted.in b/mounted.in
new file mode 100755
index 0000000..0d0d327
--- /dev/null
+++ b/mounted.in
@@ -0,0 +1,68 @@
+#!/bin/bash
+
+verwendung() {
+ echo 'Usage: mounted [ --help | --version ]'
+ echo ''
+ echo 'Mounted prints information about mounted partitions in a format useful for conky.'
+ echo '
+#HELPTEXT# #
+'
+ exit $1
+}
+
+if [ $# -eq 1 ]
+then
+ if [ "$1" == "--help" ]
+ then
+ verwendung
+ fi
+ if [ "$1" == "--version" ]
+ then
+ echo '#VERSION#'
+ exit 0
+ fi
+fi
+
+if [ $# -ne 0 ]
+then
+ verwendung 1
+fi
+
+[ -r "#ETCDIR#/mounted.conf" ] && \
+ . "#ETCDIR#/mounted.conf"
+
+mounts="$( \
+ mount | \
+ grep "${onlyFs}" | \
+ grep -v "${ignoreFs}"
+)"
+lines=$( \
+ echo "${mounts}" | \
+ wc -l
+)
+
+for (( i=1; i<=${lines}; i++))
+do
+ mount="$(
+ echo "${mounts}" | \
+ head -n${i} | \
+ tail -n1
+ )"
+ dev="$(
+ echo "${mount}" | \
+ awk '{print $1}'
+ )"
+ mp="$(
+ echo "${mount}" | \
+ awk '{print $3}'
+ )"
+ mpa="$(
+ mountName "${mp}"
+ )"
+ if [ "${mp}" == "/" ] || df -a | grep -q "^${dev} "
+ then
+ echo " \${color}${mpa} \${fs_used ${mp}}/\${fs_size ${mp}} \${fs_bar 6 ${mp}}"
+ else
+ echo " ${dev} -> ${mp}"
+ fi
+done