aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xscripts/git-do7
-rwxr-xr-xscripts/git-sync74
-rwxr-xr-xscripts/maketar6
-rwxr-xr-xscripts/makezip2
-rwxr-xr-xscripts/pmount83
-rwxr-xr-xscripts/pumount44
-rwxr-xr-xscripts/qrs80
-rwxr-xr-xscripts/qs39
-rwxr-xr-xscripts/qs141
9 files changed, 376 insertions, 0 deletions
diff --git a/scripts/git-do b/scripts/git-do
new file mode 100755
index 0000000..2e2cde3
--- /dev/null
+++ b/scripts/git-do
@@ -0,0 +1,7 @@
+#!/bin/sh
+for i in *; do
+ if [ ! -e "$i"/.git ]; then continue; fi
+ echo "================== $i =================="
+ (cd "$i" && git "$@")
+done
+
diff --git a/scripts/git-sync b/scripts/git-sync
new file mode 100755
index 0000000..deb19bc
--- /dev/null
+++ b/scripts/git-sync
@@ -0,0 +1,74 @@
+#!/bin/bash
+set -e
+
+hosthash=$(python3 -c "import uuid, hashlib
+print(hashlib.new('sha1', str(uuid.getnode()).encode('utf8')).hexdigest())")
+
+if [ -d "$(git rev-parse --git-dir)/annex" ]; then
+ echo 'Sync: using git annex'
+ exec git annex sync "$@"
+fi
+
+# determine current branch name
+branch_name=$(git symbolic-ref -q --short HEAD)
+
+# remote name
+remote_name=$(git config --get branch.${branch_name}.remote || true)
+
+# conflict commit message
+conflict_message="Merge conflict autocommit on ${hosthash}"
+
+if [ -z "$remote_name" ]; then
+ echo "No remote for this repository" >&2
+ exit 1
+fi
+
+if [ "$(git config --get --bool branch.${branch_name}.sync)" != "true" ]; then
+ echo "Branch is not configured to accept git-sync" >&2
+ echo "To accept git-sync operation, set current branch sync to true:" >&2
+ echo " git config --bool branch.${branch_name}.sync true" >&2
+ exit 1
+fi
+
+echo 'Sync: git autocommit'
+git add -A "./$(git rev-parse --show-cdup)"
+git commit -m "Auto-commit on ${hosthash}" >/dev/null 2>&1 || true
+
+echo 'Sync: fetch and merge'
+
+git fetch
+
+# might fail one time if conflict detected
+git merge -m "$conflict_message" || true
+
+echo 'Sync: conflict autocommit'
+
+git status --porcelain | while read -r filename; do
+ state="${filename:0:2}"
+ filename="${filename:3}"
+ ours="${filename}.${hosthash}.conflict"
+ theirs="${filename}.${remote_name}.conflict"
+ case "$state" in
+ *U*)
+ git checkout --ours -- "$filename"
+ mv -i -- "$filename" "$ours"
+ git add -- "$ours"
+ git checkout --theirs -- "$filename"
+ cp -ai -- "$filename" "$theirs"
+ git add -- "$filename"
+ git add -- "$theirs"
+ ;;
+ esac
+done
+
+# no action is done if there is nothing to commit
+git commit -m "$conflict_message" || true
+
+# should not fail again
+git merge -m "$conflict_message"
+
+echo 'Sync: pushing changes'
+
+git push
+
+echo 'Sync: done'
diff --git a/scripts/maketar b/scripts/maketar
new file mode 100755
index 0000000..a85fc58
--- /dev/null
+++ b/scripts/maketar
@@ -0,0 +1,6 @@
+#!/bin/bash
+if [ -x "$(which pigz)" ]; then
+ exec tar cf - "${1%%/}/" | pigz > "${1%%/}.tgz"
+else
+ exec tar czf "${1%%/}.tgz" "${1%%/}/"
+fi
diff --git a/scripts/makezip b/scripts/makezip
new file mode 100755
index 0000000..6a73850
--- /dev/null
+++ b/scripts/makezip
@@ -0,0 +1,2 @@
+#!/bin/bash
+exec zip -9 -r "${1%%/}.zip" "${1%%/}/"
diff --git a/scripts/pmount b/scripts/pmount
new file mode 100755
index 0000000..2022c10
--- /dev/null
+++ b/scripts/pmount
@@ -0,0 +1,83 @@
+#!/bin/bash
+
+set -e
+
+declare -a devices
+
+populate_devices()
+{
+ for devsys in /sys/class/block/sd*; do
+ case $(readlink $devsys) in
+ */devices/*/usb*/*/block/sd*[a-z]);;
+ # Skip non removable devices (/removable in sys is not reliable
+ # for usb3 disks). My definition of a removable device in this
+ # script is usb devices for now.
+ *) continue;;
+ esac
+ dev=${devsys##/sys/class/block/}
+ if [ -e /sys/class/block/$dev/${dev}1 ]; then
+ for subdev in /sys/class/block/$dev/${dev}*; do
+ subdev=${subdev##/sys/class/block/$dev/}
+ if ! mount | grep -q "^/dev/$subdev on /media/"; then
+ devices+=($subdev)
+ fi
+ done
+ else
+ if ! mount | grep -q "^/dev/$dev on /media/"; then
+ devices+=($dev)
+ fi
+ fi
+ done
+}
+
+get_label()
+{
+ dev=$1
+ for label in /dev/disk/by-label/*; do
+ label=${label##*/}
+ devfound=$(readlink /dev/disk/by-label/$label)
+ devfound=${devfound##*/}
+ if [ "$devfound" == "$dev" ]; then
+ echo $label
+ return
+ fi
+ done
+ echo $dev
+}
+
+choose_device()
+{
+ echo "List of mountable devices (${#devices[*]}):"
+ format=" %-8s %s\n"
+ printf "$format" =Device= =Label=
+ for dev in ${devices[*]}; do
+ printf "$format" $dev "$(get_label $dev)"
+ done
+
+ select choice in ${devices[@]}; do
+ REPLY=$((REPLY-1))
+ break
+ done
+}
+
+if [ "$#" -eq 0 ]; then
+ populate_devices
+ if [ ${#devices[*]} -eq 0 ]; then
+ echo "Nothing can be done, bye."
+ exit 0
+ fi
+
+ if [ ${#devices[*]} -eq 1 ]; then
+ dev=${devices[0]}
+ label="$(get_label ${devices[0]})"
+ else
+ choose_device
+ dev=${devices[$REPLY]}
+ label="$(get_label $dev)"
+ fi
+
+ echo "mounting /dev/$dev in /media/$label"
+ exec pmount $dev "$label"
+fi
+
+exec /usr/bin/pmount "$@"
diff --git a/scripts/pumount b/scripts/pumount
new file mode 100755
index 0000000..db1ce8b
--- /dev/null
+++ b/scripts/pumount
@@ -0,0 +1,44 @@
+#!/bin/bash
+
+set -e
+
+dash_found=
+for arg in "$@"; do
+ if [ -z "${arg##-*}" ]; then
+ dash_found=true
+ break
+ fi
+done
+
+if [ "$#" -gt 0 ]; then
+ if [ -n "$dash_found" ]; then
+ exec /usr/bin/pumount "$@"
+ fi
+ for arg in "$@"; do
+ /usr/bin/pumount "$arg"
+ done
+ exit 0
+fi
+
+cd /media/
+
+mps=(*)
+
+if [ ${#mps[@]} -eq 0 ]; then
+ echo "Nothing to be done."
+ exit 0
+fi
+
+if [ ${#mps[@]} -eq 1 ]; then
+ if [ "${mps[0]}" == "*" ]; then
+ echo "Nothing to be done."
+ exit 0
+ fi
+ echo "unmounting /media/${mps[0]}"
+ exec /usr/bin/pumount "/media/${mps[0]}"
+fi
+
+select mp in ${mps[*]}; do
+ echo "unmounting /media/$mp"
+ exec /usr/bin/pumount "/media/$mp"
+done
diff --git a/scripts/qrs b/scripts/qrs
new file mode 100755
index 0000000..be41aa0
--- /dev/null
+++ b/scripts/qrs
@@ -0,0 +1,80 @@
+#!/bin/bash
+
+# standard rsync port is 873, I choose 8873 for userside listen.
+PORT=8873
+
+printf "Examples of get with rsync (full rsync):\n"
+
+msg=" rsync -Pa 'rsync://%s:${PORT}/qrs/.' .\n"
+printf "$msg" "${HOSTNAME}.local"
+printf "$msg" "${HOSTNAME}"
+
+for ipv6 in ::1 \
+ $(ip -oneline -family inet6 address show scope site \
+ | sed 's/^.*inet6 \([0-9:a-fA-F]\+\).*$/\1/') \
+ $(ip -oneline -family inet6 address show scope global \
+ | sed 's/^.*inet6 \([0-9:a-fA-F]\+\).*$/\1/') \
+; do
+ printf "$msg" "[${ipv6}]"
+done
+
+for ipv4 in $(ip -oneline -family inet address show \
+ | sed 's/^.*inet \([0-9.]\+\).*$/\1/'); do
+ printf "$msg" "${ipv4}"
+done
+
+# <(cat <<EOF ... EOF) redirection does not work with rsync, I suspect the
+# daemon to read two times the file. Make a real file instead and delete it
+# with a trap.
+
+CONF=$(mktemp)
+cleanup() { rm -f "$CONF"; }
+trap cleanup EXIT INT QUIT HUP TERM ABRT
+
+cat >"$CONF" <<EOF
+# GLOBAL OPTIONS
+#motd file=/etc/motd
+#log file=/var/log/rsyncd
+# for pid file, do not use /var/run/rsync.pid if
+# you are going to run rsync out of the init.d script.
+# The init.d script does its own pid file handling,
+# so omit the "pid file" line completely in that case.
+# pid file=/var/run/rsyncd.pid
+#syslog facility=daemon
+#socket options=
+port = $PORT
+reverse lookup = no
+
+# MODULE OPTIONS
+[qrs]
+path = $PWD
+use chroot = no
+
+#comment = public archive
+#use chroot = no
+#max connections=10
+#lock file = /var/lock/rsyncd
+# the default for read only is yes...
+#read only = yes
+#list = yes
+#uid = nobody
+#gid = nogroup
+#exclude =
+#exclude from =
+#include =
+#include from =
+#auth users =
+#secrets file = /etc/rsyncd.secrets
+#strict modes = yes
+#hosts allow =
+#hosts deny =
+#ignore errors = no
+#ignore nonreadable = yes
+#transfer logging = no
+#log format = %t: host %h (%a) %o %f (%l bytes). Total %b bytes.
+#timeout = 600
+#refuse options = checksum dry-run
+#dont compress = *.gz *.tgz *.zip *.z *.rpm *.deb *.iso *.bz2 *.tbz
+EOF
+
+rsync --daemon --no-detach --log-file=/dev/stderr --config="$CONF"
diff --git a/scripts/qs b/scripts/qs
new file mode 100755
index 0000000..afc998f
--- /dev/null
+++ b/scripts/qs
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+PORT=8000
+
+cat <<EOF
+Quickshare (qs)
+###############
+
+Will run (port is optional and = 8000 by default):
+
+ python3 -m SimpleHTTPServer ${PORT}
+
+Or, if python3 is not installed on the host:
+
+ python -m SimpleHTTPServer ${PORT}
+
+Depending on the current lan configuration,
+you can access files by going to either:
+
+ http://${HOSTNAME}.local:${PORT}/
+ http://${HOSTNAME}:${PORT}/
+EOF
+
+for ipv4 in $(ip -oneline -family inet address show \
+ | sed 's/^.*inet \([0-9.]\+\).*$/\1/'); do
+ echo " http://${ipv4}:${PORT}/"
+done
+
+for ipv6 in $(ip -oneline -family inet6 address show \
+ | sed 's/^.*inet6 \([0-9:a-fA-F]\+\).*$/\1/'); do
+ echo " http://[${ipv6}]:${PORT}/"
+done
+
+echo ""
+echo "=================================================="
+
+[ -e /usr/bin/python3 ] && \
+ python3 -m http.server 8000 || \
+ python2 -m SimpleHTTPServer 8000
diff --git a/scripts/qs1 b/scripts/qs1
new file mode 100755
index 0000000..d524223
--- /dev/null
+++ b/scripts/qs1
@@ -0,0 +1,41 @@
+#!/bin/bash
+set -eu
+port=8000
+
+disp_quick_usage()
+{
+ cat <<EOF
+Quick one-shot share
+####################
+
+Dependings on the current lan configuration,
+you can access the file with one of:
+
+ wget --content-disposition ${HOSTNAME}.local:${port}
+ wget --content-disposition ${HOSTNAME}:${port}
+EOF
+ for ip in $(ip -oneline -family inet address show \
+ | sed 's/^.*inet \([0-9.]\+\).*$/\1/') \
+ $(ip -oneline -family inet6 address show \
+ | sed 's/^.*inet6 \([0-9:a-fA-F]\+\).*$/\1/'); do
+ echo " wget --content-disposition ${ip}:${port}"
+ done
+ echo ""
+ echo "Note: --content-disposition is optional => use remote filename"
+ echo "=================================================="
+}
+
+
+disp_quick_usage
+filename="$1"
+sfilename="$(echo x$filename | sed 's/^x//;s/"//')"
+(
+ echo "HTTP/1.1 200 OK"
+ #echo "Content-Type: $(file -bni "$1")"
+ echo "Content-Type: application/octet-stream"
+ echo "Content-Transfer-Encoding: binary"
+ echo "Content-Disposition: attachment; filename=\"$sfilename\""
+ echo "Content-Length: $(du -b "$filename" | cut -f1)"
+ echo ""
+ cat -- "$filename"
+) | nc -l -q0 -p $port >/dev/null 2>&1