msync, dotinstall.sh: rewrite scripts with options
This commit is contained in:
parent
976dedb369
commit
fc76ddd914
@ -1,18 +1,94 @@
|
|||||||
#!/bin/sh
|
#!/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
|
for f in $(find -type d); do
|
||||||
DIR=$HOME$(echo $f | cut -c 2-)
|
DIR=$DESTFOLDER$(echo $f | cut -c 2-)
|
||||||
echo $DIR
|
|
||||||
mkdir $DIR
|
if ! [ -d "$DIR" ]; then
|
||||||
|
if [ "$VERBOSE" = "Y" ]; then
|
||||||
|
printf "$DIR\n"
|
||||||
|
fi
|
||||||
|
mkdir $DIR
|
||||||
|
fi
|
||||||
done
|
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
|
for f in $(find -type f); do
|
||||||
DEST=$HOME$(echo $f | cut -c 2-)
|
DEST="$DESTFOLDER$(echo $f | cut -c 2-)"
|
||||||
SRC=$PWD$(echo $f | cut -c 2-)
|
SRC="$PWD$(echo $f | cut -c 2-)"
|
||||||
echo $SRC $DEST
|
if [ -e "$DEST" ]; then
|
||||||
ln -s $SRC $DEST
|
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
|
done
|
||||||
|
@ -4,14 +4,35 @@
|
|||||||
|
|
||||||
set -e
|
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
|
case "${o}" in
|
||||||
p) ACTION=PUSH ;;
|
p) ACTION=PUSH ;;
|
||||||
r) ACTION=RECV ;;
|
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
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
MNT="$HOME/quar/mnt"
|
|
||||||
ROOT="$MNT/Internal shared storage"
|
ROOT="$MNT/Internal shared storage"
|
||||||
|
|
||||||
imp () {
|
imp () {
|
||||||
@ -26,33 +47,53 @@ exp () {
|
|||||||
find "$1" -type f | xargs -I{} cp -n "{}" "$2"
|
find "$1" -type f | xargs -I{} cp -n "{}" "$2"
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ $ACTION = PUSH ]
|
display_help () {
|
||||||
then
|
cat << "EOF"
|
||||||
# Optionally send sorted files back
|
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/"
|
case "$ACTION" in
|
||||||
exp ~/med/memes/bork/ "$ROOT/Pictures/memes2/"
|
PUSH)
|
||||||
exp ~/med/rw/sch/ "$ROOT/Pictures/rw/sch/"
|
# Optionally send sorted files back
|
||||||
exp ~/med/sticker/ "$ROOT/Pictures/sticker/"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $ACTION = RECV ]
|
exp ~/med/memes/woof/ "$ROOT/Pictures/memes/"
|
||||||
then
|
exp ~/med/memes/bork/ "$ROOT/Pictures/memes2/"
|
||||||
# Move files to the quarantine zone for categorisation and renaming
|
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/Infinity/" $DEST
|
||||||
imp "$ROOT/Pictures/Screenshots/" ~/quar
|
imp "$ROOT/Pictures/Screenshots/" $DEST
|
||||||
|
|
||||||
imp "$ROOT/Movies/Infinity/" ~/quar
|
imp "$ROOT/Movies/Infinity/" $DEST
|
||||||
|
|
||||||
imp "$ROOT/DCIM/OpenCamera/" ~/quar
|
imp "$ROOT/DCIM/OpenCamera/" $DEST
|
||||||
imp "$ROOT/DCIM/Camera/" ~/quar
|
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/Documents/contacts.vcf" $DEST
|
||||||
imp "$ROOT/infbk/" ~/quar/infinity/
|
imp "$ROOT/infbk/" $DEST
|
||||||
impf "$ROOT/.SeedVaultAndroidBackup/" ~/quar/seedvault/
|
impf "$ROOT/.SeedVaultAndroidBackup/" $DEST/seedvault/
|
||||||
fi
|
;;
|
||||||
|
|
||||||
|
HELP)
|
||||||
|
# show help
|
||||||
|
display_help
|
||||||
|
;;
|
||||||
|
|
||||||
|
NONE)
|
||||||
|
# Default
|
||||||
|
printf "$SCRIPT_NAME: no option specified, see $SCRIPT_NAME -h for help"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
Loading…
Reference in New Issue
Block a user