forked from holatuwol/liferay-faster-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload_to_gdrive
executable file
·62 lines (45 loc) · 1.36 KB
/
upload_to_gdrive
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
#!/bin/bash
if [ "" == "$(which gdrive)" ]; then
echo 'Please set up the gdrive script'
echo 'https://shouts.dev/mount-google-drive-using-gdrive-on-linux-server-with-own-oauth-credentials'
exit 1
fi
SCRIPT_FOLDER="$(dirname $BASH_SOURCE[0])"
if [ "" == "${1}" ]; then
echo -n "URL: "
read remote_file
else
remote_file="${1}"
fi
get_file_id() {
file_id=$(gdrive list --no-header --query "name = '${target_file}' and parents in '${folder_id}'" | awk '{ print $1 }' | head -1)
}
get_folder_id() {
folder_id=$(gdrive list --no-header --query "name = 'Large Attachments'" | awk '{ print $1 }')
}
echo 'Downloading file...'
python ${SCRIPT_FOLDER}/patcher/scrape_liferay.py "${remote_file}" | tee output.txt
local_file=$(tail -1 output.txt)
rm output.txt
if [[ ${local_file} != *.zip ]] && [[ ${local_file} != *.gz ]]; then
gzip -9 ${local_file}
local_file="${local_file}.gz"
fi
get_folder_id
if [ "" == "${folder_id}" ]; then
gdrive mkdir "Large Attachments"
get_folder_id
fi
target_file="${local_file}"
get_file_id
suffix=0
while [ "" != "${file_id}" ]; do
suffix=$((suffix + 1))
target_file="${local_file} (${suffix})"
get_file_id
done
echo 'Uploading file...'
gdrive upload --name "${target_file}" --delete --parent "${folder_id}" "${local_file}"
get_file_id
gdrive share --type domain --domain liferay.com "${file_id}"
gdrive info "${file_id}" | grep '^ViewUrl:'