-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_pull.sh
More file actions
executable file
·94 lines (78 loc) · 2.16 KB
/
Copy pathmy_pull.sh
File metadata and controls
executable file
·94 lines (78 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
#
# Time-stamp: Sunday 2026-04-26 Jess Moore
#
# Pull local document from a remote sync folder
function usage() {
echo "Usage: my_pull.sh [-n|-p|-o folder] [remotesubdir] [filename]"
echo ""
echo "Description: Pull a document from a remote sync folder."
echo "This script copies a document from a subdirectory of the chosen"
echo "remote folder into the current directory. Check the remote"
echo "afterwards to confirm syncing is up to date."
echo ""
echo "Flags (exactly one required):"
echo " -n Nextcloud folder (~/Documents/Nextcloud)"
echo " -p Private folder (~/Documents/private)"
echo " -o folder Other folder (~/Documents/<folder>)"
echo ""
echo "Arguments:"
echo " filename: Name of file (must include extension)."
echo " remotesubdir: Subdirectory within the remote folder."
echo ""
exit 1
}
BASE_DIR=""
[[ "$1" == "--help" ]] && usage
while getopts ":hnpo:" opt; do
case $opt in
h) usage ;;
n) BASE_DIR="${HOME}/Documents/Nextcloud" ;;
p) BASE_DIR="${HOME}/Documents/private" ;;
o) BASE_DIR="${HOME}/Documents/${OPTARG}" ;;
*) usage ;;
esac
done
shift $((OPTIND - 1))
if [[ -z "$BASE_DIR" || $# -ne 2 ]]; then
usage
fi
REM_SUB_DIR=$1
FILE=$2
# User
user=$(whoami)
REM_DIR="${BASE_DIR}/${REM_SUB_DIR}"
# Check remote dir exists
if [[ ! -d ${REM_DIR} ]]; then
echo "Remote directory does not exist"
exit 1
else
echo "Remote directory: ${REM_DIR}"
fi
# Check remote file exists
if [[ ! -e "${REM_DIR}/$FILE" ]]; then
echo "$FILE does not exist."
exit 1
fi
if [[ "${user}" == "u9904893" ]]; then
# Backup local file before overwrite
if [[ -f "${FILE}" ]]; then
echo "Backing up local file to *.bak"
cp -p "${FILE}" "${FILE}.bak"
fi
echo "Files on remote:"
FILES_REM=$(find "${REM_DIR}" -name "${FILE}*")
for f in $FILES_REM
do
ls -lt "$f"
done
echo "Pulling from ${REM_DIR}..."
cp -p "${REM_DIR}/${FILE}" "${FILE}"
fi
echo "Done"
FILES_LOC=$(find . -name "${FILE}*")
echo "Local files:"
for f in $FILES_LOC
do
ls -lt "$f"
done