-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_push.sh
More file actions
executable file
·77 lines (62 loc) · 1.74 KB
/
my_push.sh
File metadata and controls
executable file
·77 lines (62 loc) · 1.74 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
#!/bin/bash
#
# Time-stamp: Wednesday 2026-03-18 14:28:16 Jess Moore
#
# Push local document to remote Nextcloud folder
#
# Usage: my_push.sh [args...]
function usage() {
echo "Usage: my_push.sh [filename] [remotesubdir]"
echo ""
echo "Description: Push local document to remote Nextcloud folder."
echo "This script pushs a local document to the local sync drive of"
echo "remote Nextcloud folder, ie. the subdirectory of Nextcloud folder."
echo "Check Nextcloud online afterwards to confirm syncing is up to date."
echo ""
echo "Arguments:"
echo " filename: Name of file (must include extension)."
echo " remotesubdir: Sub directory on local sync dir to remote location"
echo ""
exit 1 # Exit with a non-zero status to indicate an error
}
if [[ $# -ne 2 || $* == *"help"* || $* == *"-h"* ]]; then
usage
fi
FILE=$1
REM_SUB_DIR=$2
# User
user=$(whoami)
REM_DIR="${HOME}/Documents/Nextcloud/${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 local file exists
if [[ ! -e "$FILE" ]]; then
echo "$FILE does not exist."
exit 1
fi
if [[ "${user}" == "u9904893" ]]; then
if [[ -f "${REM_DIR}/${FILE}" ]]; then
echo "Backing up remote file to *.bak"
cp -p "${REM_DIR}/${FILE}" "${REM_DIR}/${FILE}.bak"
fi
echo "Pushing to ${REM_DIR}..."
cp -p "$FILE" "${REM_DIR}"/.
echo "Files on Nextcloud:"
FILES_REM=$(find "${REM_DIR}" -name "${FILE}*")
for f in $FILES_REM
do
ls -lt "$f"
done
fi
echo "Done"
FILES_LOC=$(find . -name "${FILE}*")
echo "Local files:"
for f in $FILES_LOC
do
ls -lt "$f"
done