git.lirion.de

Of git, get, and gud

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Pfeiffer <coding _ lirion.de> 2019-09-25 13:59:25 +0200
committerHarald Pfeiffer <coding _ lirion.de> 2019-09-25 13:59:25 +0200
commitc55163b6359c42d6236a53dc84be54461b797a25 (patch)
tree7e1f88898ded14fa11c70b32cf096bc79bff01fc
downloadwinix-c55163b6359c42d6236a53dc84be54461b797a25.tar.bz2
Initial commit
-rw-r--r--README.md26
-rwxr-xr-xbin/winmount148
2 files changed, 174 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..1feb095
--- /dev/null
+++ b/README.md
@@ -0,0 +1,26 @@
+# Content
+
+This repository bears small scripts that are designed to make Linux happily interact with $things
+coming from Windows, a rather flawed OS (or rather graphical interrupt handler instead of OS),
+often working around fucked-up designs such as "drive letters" or NTFS (or gods beware, LDM - eh,
+that is deprecated - or Storage Spaces - oh that was fucked up and excluded from 1709 and is now
+"alive" again(???)) and so on.
+
+## bin/winmount
+
+TL;DR: mount windows drive letter either as read-only or read-write to $WINPARTS/letter,
+definition must be available in fstab(5)
+
+This script runs inside a dual-boot environment. Thus, NTFS is used as the common base for larger
+file repos available to both OSes as there is no NFS, NAS, or multi-filer SAN available.
+Since Microsoft among their array of fucked up design decisions still insist on calling parti-
+tions "drives" and makes them available as "drive letters", this script addresses all those
+drive letters under $WINPARTS/drive\_letter (see WINPARTS inside script).
+You might've guessed already: $WINPARTS/drive\_letter is a folder, we use that, so we expect
+a definition in fstab(5). The script will skip anything not defined there.
+
+**THE PURPOSE** is to make a drive letter available as read-write or read-only, as negative experi-
+ences with the garbled design of NTFS as file-system made the scripter decide to generally have
+them available as R/O and only make them writable on-demand.
+
+*Internet English: "How to use this script?" --> type scriptname -h :)*
diff --git a/bin/winmount b/bin/winmount
new file mode 100755
index 0000000..16aa489
--- /dev/null
+++ b/bin/winmount
@@ -0,0 +1,148 @@
+#!/usr/bin/env bash
+# vim: ls=4 ts=4
+
+# SCOPE
+# TL;DR: mount windows drive letter either as read-only or read-write to $WINPARTS/letter,
+# definition must be available in fstab(5)
+#
+# This script runs inside a dual-boot environment. Thus, NTFS is used as the common base for larger
+# file repos available to both OSes as there is no NFS, NAS, or multi-filer SAN available.
+# Since Microsoft among their array of fucked up design decisions still insist on calling parti-
+# tions "drives" and makes them available as "drive letters", this script addresses all those
+# drive letters under $WINPARTS/drive_letter (see WINPARTS below).
+# You might've guessed already: $WINPARTS/drive_letter is a folder, we use that, so we expect
+# a definition in fstab(5). The script will skip anything not defined there.
+#
+# THE PURPOSE is to make a drive letter available as read-write or read-only, as negative experi-
+# ences with the garbled design of NTFS as file-system made the scripter decide to generally have
+# them available as R/O and only make them writable on-demand.
+#
+# Internet English: "How to use this script?" --> type scriptname -h :)
+
+# -------- USER DEFINITIONS START -------- #
+# Where are the Windows "drive letters" mounted? We expect something like $WINPARTS/C for the %SystemDrive% partition.
+export WINPARTS="/windows"
+# Where is the system fstab? In most cases, it's safe to leave this unchanged.
+export FSTABF="/etc/fstab"
+# --------- USER DEFINITIONS END --------- #
+
+
+
+# DO NOT TOUCH FROM HERE UNLESS YOU KNOW YOUR BASH/KSH
+export FRD=""
+export RW=0
+export RO=0
+export RVAL=0
+
+# ------------- HELP START -------------- #
+function usage {
+ printf "USAGE: %b ( -r | -w ) DRIVE [DRIVE]...\n" "$(basename "$0")"
+ printf "Mounts every passed DRIVE either as read-only or as writeable.\n"
+ printf "\nDRIVE in our case is a Windows \"drive letter\" (Microtwat\n\tstill insist on that moronic definition (: )\n\n"
+ (
+ printf -- " ;-r,\n ;--ro:;Mount read-only\n"
+ printf -- " ;-w,\n ;--rw:;Mount writeable\n"
+ )|column -ts\;
+}
+# -------------- HELP END --------------- #
+
+# --------- PARAM PARSING START --------- #
+PARAMS=""
+while (( "$#" ));do
+ case "$1" in
+ -r|--ro)
+ RO=1
+ shift
+ ;;
+ -w|--rw)
+ RW=1
+ shift
+ ;;
+ -h|--help)
+ usage
+ exit 0
+ ;;
+ -f|--fus-ro-dah)
+ FRD="$2"
+ shift 2
+ ;;
+ --)
+ # end argument parsing
+ break
+ ;;
+ -*|--*=)
+ # unsupported flags
+ echo "Error: unsupported flag $1!" >&2
+ exit 1
+ ;;
+ *)
+ # preserve positional arguments
+ PARAMS="$PARAMS $1"
+ shift
+ ;;
+ esac
+done
+# set positional arguments in their proper place
+eval set -- "$PARAMS"
+# ---------- PARAM PARSING END ---------- #
+
+# ---------- RETVAL DEFS START ---------- #
+ROK='\033[666D[ \033[32mOK \033[0m]\033[u\033[K.'
+RWRN='\033[666D[\033[33mWARN\033[0m]\033[u\033[K.'
+RERR='\033[666D[\033[31mFAIL\033[0m]\033[u\033[K.'
+RINF='\033[666D[\033[36mINFO\033[0m]\033[u\033[K.'
+function ret {
+ RCODE="$RINF"
+ [ -z "$1" ]&&printf "Fatal error in %b(): no argument passed!\n" "${FUNCNAME[0]}">&2&&return 127
+ case "$1" in
+ "ok"|"OK") RCODE="$ROK";;
+ "warn"|"WARN") RCODE="$RWRN";;
+ "err"|"ERR"|"error"|"ERROR") RCODE="$RERR";;
+ "inf"|"INF"|"info"|"INFO") RCODE="$RINF";;
+ "beg"|"BEG"|"begin"|"BEGIN" ) printf "[....] %b\033[s..." "$2";return 0;;
+ "stat"|"STAT"|"status"|"STATUS" ) printf "\033[u\033[K... \033[90m(%b)\033[0m" "$2"; sleep 1;return 0;;
+ *) printf "Fatal error in %b(): argument \033[1m%b\033[0m invalid!\n" "${FUNCNAME[0]}" "$1">&2;return 127;;
+ esac
+ sleep 0.2718
+ case "$2" in
+ "") printf "%b\n" "$RCODE";;
+ *) printf "%b \033[90m(%b)\033[0m\n" "$RCODE" "$2";;
+ esac
+}
+# ----------- RETVAL DEFS END ----------- #
+
+[ "$RO" -eq 0 ]&&[ "$RW" -eq 0 ]&&printf "Please specify mount mode!\n\n">&2&&usage&&exit 2
+[ "$RO" -eq 1 ]&&[ "$RW" -eq 1 ]&&printf "Please specify only one mount mode!\n\n">&2&&usage&&exit 2
+
+DISKS=( $PARAMS )
+
+LORET=0;LOCNT=0
+for DISK in "${DISKS[@]}";do
+ LOCNT=$((LOCNT+1))
+ ret "beg" "Mounting $WINPARTS/$DISK"
+ grep -v '^#' "$FSTABF" 2>/dev/null|grep -P "[\t\ ]$WINPARTS/$DISK[\t\ ]" >/dev/null
+ [ "$?" -ne 0 ]&&sleep 0.666&&ret "err" "No fstab definition found!"&&LORET=$((LORET+1))&&continue
+ [ "$RO" -eq 1 ]&&ROPT="ro"
+ [ "$RW" -eq 1 ]&&ROPT="rw"
+ # This would work if remount was supported on NTFS. For now we have to unmount and mount again.
+ # MYERR="$(mount "$WINPARTS/$DISK" -o "remount,$ROPT" 3>&1 1>/dev/null 2>&3-)"
+ MYERR="$(umount "$WINPARTS/$DISK" 3>&1 1>/dev/null 2>&3-)"
+ case "$?" in
+ 32) ret "stat" "$MYERR";;
+ 0) ret "stat" "successfully unmounted";;
+ *) ret "err" "$MYERR";LORET=$((LORET+1));continue;;
+ esac
+ MYERR="$(mount "$WINPARTS/$DISK" -o "$ROPT" 3>&1 1>/dev/null 2>&3-)"
+ case "$?" in
+ 21) ret "warn" "Drive busy, already mounted elsewhere?"&&LORET=$((LORET+1));;
+ 0) ret "ok";;
+ *) ret "err" "$MYERR";;
+ esac
+done
+case "$LORET" in
+ 0);;
+ *)
+ printf "%b/%b disks failed!\n" "$LORET" "$LOCNT" >&2
+ exit $((LORET+100))
+ ;;
+esac