msync, dotinstall.sh: rewrite scripts with options

This commit is contained in:
dogeystamp 2022-07-11 17:44:22 -04:00
parent 976dedb369
commit fc76ddd914
Signed by: dogeystamp
GPG Key ID: 7225FE3592EFFA38
2 changed files with 151 additions and 34 deletions

View File

@ -1,18 +1,94 @@
#!/bin/sh
cd $(dirname $(echo $0))/src/
# Symlink dotfiles into the home directory
set -e
SCRIPT_NAME="$(basename $0)"
# Default source for dotfiles
SRCFOLDER="$(dirname "$0")/src/"
DESTFOLDER="$HOME"
# Allow overwriting of outdated files
FORCE="N"
VERBOSE="N"
display_help () {
cat >&2 <<EOF
usage: $SCRIPT_NAME [-h] [-v] [-f] [-s PATH] [-d PATH]
-h: display help
-f: allow overwriting existing dotfiles
-v: print modified files
-s: path to source of dotfiles
-d: path to destination where dotfiles are linked from
EOF
}
while getopts "fvhs:d:" o; do
case "$o" in
h)
display_help
exit 0
;;
f) FORCE="Y" ;;
v) VERBOSE="Y" ;;
s)
DESTFOLDER="$OPTARG"
;;
d)
DESTFOLDER="$OPTARG"
;;
esac
done
if ! [ -d "$SRCFOLDER" ]; then
printf "$SCRIPT_NAME: source folder $SRCFOLDER is invalid.\n"
exit 1
fi
if ! [ -d "$DESTFOLDER" ]; then
printf "$SCRIPT_NAME: destination $DESTFOLDER is invalid.\n"
exit 1
fi
cd $SRCFOLDER
echo Making directories
for f in $(find -type d); do
DIR=$HOME$(echo $f | cut -c 2-)
echo $DIR
mkdir $DIR
DIR=$DESTFOLDER$(echo $f | cut -c 2-)
if ! [ -d "$DIR" ]; then
if [ "$VERBOSE" = "Y" ]; then
printf "$DIR\n"
fi
mkdir $DIR
fi
done
echo Symlinking dotfiles
link () {
SRC="$1"
DEST="$2"
OPTS="$3"
ln -s $OPTS "$SRC" "$DEST"
if [ "$VERBOSE" = "Y" ]; then
printf "$2\n"
fi
}
for f in $(find -type f); do
DEST=$HOME$(echo $f | cut -c 2-)
SRC=$PWD$(echo $f | cut -c 2-)
echo $SRC $DEST
ln -s $SRC $DEST
DEST="$DESTFOLDER$(echo $f | cut -c 2-)"
SRC="$PWD$(echo $f | cut -c 2-)"
if [ -e "$DEST" ]; then
if ! [ "$SRC" -ef "$DEST" ]; then
if [ "$FORCE" = "Y" ]; then
link "$SRC" "$DEST" -f
else
printf "$SCRIPT_NAME: $DEST already exists\n" >&2
fi
fi
else
link "$SRC" "$DEST"
fi
done

View File

@ -4,14 +4,35 @@
set -e
while getopts ":pr" o; do
SCRIPT_NAME="$(basename $0)"
ACTION=NONE
MNT="$HOME/quar/mnt"
DEST="$HOME/quar"
while getopts "prhs:d:" o; do
case "${o}" in
p) ACTION=PUSH ;;
r) ACTION=RECV ;;
h) ACTION=HELP ;;
s)
ROOT="$OPTARG"
if ! [ -e "$MNT" ]; then
printf "$SCRIPT_NAME: source mountpoint $MNT does not exist"
exit 1
fi
;;
d)
DEST="$OPTARG"
if ! [ -e "$DEST" ]; then
printf "$SCRIPT_NAME: destination $DEST does not exist"
exit 1
fi
;;
esac
done
MNT="$HOME/quar/mnt"
ROOT="$MNT/Internal shared storage"
imp () {
@ -26,33 +47,53 @@ exp () {
find "$1" -type f | xargs -I{} cp -n "{}" "$2"
}
if [ $ACTION = PUSH ]
then
# Optionally send sorted files back
display_help () {
cat << "EOF"
usage: $SCRIPT_NAME [-r] [-p] [-h] [-s PATH] [-d PATH]
-r: receive files from mobile device
-p: send files to mobile device
-s: set go-mtpfs source mountpoint path
-d: set local download destination path
EOF
}
exp ~/med/memes/woof/ "$ROOT/Pictures/memes/"
exp ~/med/memes/bork/ "$ROOT/Pictures/memes2/"
exp ~/med/rw/sch/ "$ROOT/Pictures/rw/sch/"
exp ~/med/sticker/ "$ROOT/Pictures/sticker/"
fi
case "$ACTION" in
PUSH)
# Optionally send sorted files back
if [ $ACTION = RECV ]
then
# Move files to the quarantine zone for categorisation and renaming
exp ~/med/memes/woof/ "$ROOT/Pictures/memes/"
exp ~/med/memes/bork/ "$ROOT/Pictures/memes2/"
exp ~/med/rw/sch/ "$ROOT/Pictures/rw/sch/"
exp ~/med/sticker/ "$ROOT/Pictures/sticker/"
;;
RECV)
# Move files to the quarantine zone for categorisation and renaming
imp "$ROOT/Pictures/Infinity/" ~/quar
imp "$ROOT/Pictures/Screenshots/" ~/quar
imp "$ROOT/Pictures/Infinity/" $DEST
imp "$ROOT/Pictures/Screenshots/" $DEST
imp "$ROOT/Movies/Infinity/" ~/quar
imp "$ROOT/Movies/Infinity/" $DEST
imp "$ROOT/DCIM/OpenCamera/" ~/quar
imp "$ROOT/DCIM/Camera/" ~/quar
imp "$ROOT/DCIM/OpenCamera/" $DEST
imp "$ROOT/DCIM/Camera/" $DEST
imp "$ROOT/Recordings/Sound records/" ~/quar
imp "$ROOT/Recordings/Sound records/" $DEST
imp "$ROOT/Documents/dr" ~/quar
imp "$ROOT/Documents/dr" $DEST
imp "$ROOT/Documents/contacts.vcf" ~/quar
imp "$ROOT/infbk/" ~/quar/infinity/
impf "$ROOT/.SeedVaultAndroidBackup/" ~/quar/seedvault/
fi
imp "$ROOT/Documents/contacts.vcf" $DEST
imp "$ROOT/infbk/" $DEST
impf "$ROOT/.SeedVaultAndroidBackup/" $DEST/seedvault/
;;
HELP)
# show help
display_help
;;
NONE)
# Default
printf "$SCRIPT_NAME: no option specified, see $SCRIPT_NAME -h for help"
;;
esac