-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathupload_mega.sh
More file actions
executable file
·53 lines (40 loc) · 989 Bytes
/
upload_mega.sh
File metadata and controls
executable file
·53 lines (40 loc) · 989 Bytes
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
#!/bin/sh
set -eu
MEGA_USER="$1"
MEGA_PASS="$2"
DIR="$3"
MEGA_PATH="$4"
IMG_EXT=".img.gz"
[ -z "$DIR" ] || [ -z "$MEGA_PATH" ] && {
printf "\nUsage: %s <MEGA_USER> <MEGA_PASS> <DIRNAME> <MEGA_PATH>\n" "$0"
exit 1
}
if ! command -v mega-whoami >/dev/null 2>&1; then
printf "Error: MEGAcmd not installed or missing 'mega-whoami'\n"
exit 1
fi
TARGET_DIR="./$DIR/compress"
[ -d "$TARGET_DIR" ] || {
printf "\nError: Directory '%s' not found\n" "$TARGET_DIR"
exit 1
}
FOUND=0
if ! mega-whoami >/dev/null 2>&1; then
if [ -n "$MEGA_USER" ] && [ -n "$MEGA_PASS" ]; then
mega-login "$MEGA_USER" "$MEGA_PASS"
else
printf "Error: Not logged into MEGA or MEGA_USER/MEGA_PASS not set\n"
exit 1
fi
fi
for FILE in "$TARGET_DIR"/*"$IMG_EXT"; do
[ -f "$FILE" ] || continue
FOUND=1
printf "\nUploading: %s\n" "$FILE"
mega-put "$FILE" "$MEGA_PATH"
done
printf "\n"
[ "$FOUND" -eq 0 ] && {
printf "No compressed images (%s) found in '%s'\n" "$IMG_EXT" "$TARGET_DIR"
exit 1
}