-
-
Save kshivang/a8c5e1bd8ca8988e738bcd3a2c29e5c3 to your computer and use it in GitHub Desktop.
Revisions
-
kshivang revised this gist
Dec 12, 2017 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,6 +22,9 @@ function getFirebaseURL { do : URL=$URL/$folder done if [ $MODE == "folder" ]; then URL="$URL/$FILE" fi URL=$URL.json echo $URL } -
kshivang renamed this gist
Dec 12, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
kshivang revised this gist
Dec 12, 2017 . 1 changed file with 1 addition and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,10 +15,6 @@ MODE="file" FILE="" FOLDER=() function getFirebaseURL { URL=$FIREBASE_URL @@ -150,6 +146,7 @@ while getopts "h:b:f:d" opt; do esac done FOLDER=(${FOLDER_PATH//\// }) S3_URI="s3://${BUCKET_NAME}${FOLDER_PATH}" if [ "${MODE}" == "file" ]; then -
kshivang renamed this gist
Dec 12, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
kshivang revised this gist
Dec 12, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,7 @@ FILE="" FOLDER=() function setFolder { FOLDER=(${FOLDER_PATH//\// }) echo $FOLDER } -
kshivang revised this gist
Dec 12, 2017 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -83,6 +83,8 @@ function printHelp { echo " -a for asmr directory" } FOLDER=${setFolder} if [[ "$#" -eq 0 ]]; then echo "Error: You need to pass to pass arguments" printHelp -
kshivang created this gist
Dec 12, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,158 @@ #!/bin/bash # Please pay attention to comment till line 12 # These are your configuration variables # Configuration SERVER="Amazon server where S3 is hosted" # "s3.ap-south-1" BUCKET_NAME="S3 Bucket Name" #Bucket Name FOLDER_PATH="/default/S3/FOLDER" # Default S3 Folder to upload FIREBASE_URL="https://your-project.firebaseio.com" #Your firebase project URL # Configuration End MODE="file" FILE="" FOLDER=() function setFolder { IFS='/' read -r -a FOLDER <<< "${FOLDER_PATH}" echo $FOLDER } function getFirebaseURL { URL=$FIREBASE_URL for folder in "${FOLDER[@]}" do : URL=$URL/$folder done URL=$URL.json echo $URL } function parseFileJSON { FILE_URL="https://${SERVER}.amazonaws.com/${BUCKET_NAME}${FOLDER_PATH}/$FILE" file="${FILE%.*}" JSON="{ \"${file}\": \"${FILE_URL}\" }" echo $JSON } function parseFolderJSON { cd ${FILE} files=(*) i=0 for file in "${files[@]}" do : FILE_URL="https://${SERVER}.amazonaws.com/${BUCKET_NAME}${FOLDER_PATH}/$FILE/$file" file_name="${file%.*}" if [ $i -eq 0 ]; then JSON="{ \"${file_name}\": \"${FILE_URL}\" " else JSON="${JSON}, \"${file_name}\": \"${FILE_URL}\" " fi i=$(($i+1)) done JSON="${JSON} }" echo $JSON } function updateToFirebase { URL=$(getFirebaseURL) echo "Firebase Patch request at $URL" if [ ${MODE} == "file" ]; then JSON=$(parseFileJSON) echo $JSON > upload.json curl -X PATCH -d @upload.json $URL else JSON=$(parseFolderJSON) echo $JSON > upload.json curl -X PATCH -d @upload.json $URL fi rm upload.json } function printHelp { echo "Usage: " echo " Just use af fileName or directoryName" echo " -h <help> print help(this message)" echo " -b <batch files> take batch upload" echo " -f <file> file/folder to upload" echo " -d <directory> aws directory where to upload e.g /sound/davidji" echo " -m for meditation directory" echo " -a for asmr directory" } if [[ "$#" -eq 0 ]]; then echo "Error: You need to pass to pass arguments" printHelp exit 1 fi while getopts "h:b:f:d" opt; do case "$opt" in h) printHelp exit 0 ;; b) if [[ -d $OPTARG ]]; then FILE=$OPTARG MODE="folder" if [[ $FILE == */ ]]; then FILE=${FILE%?} fi else echo "Error: $OPTARG is not a diretory." printHelp exit 1 fi ;; f) if [[ -d $OPTARG ]]; then FILE=$OPTARG else echo "Error: $OPTARG is not a file." printHelp exit 1 fi ;; d) FOLDER_PATH=$OPTARG FOLDER=$(setFolder) ;; m) FOLDER_PATH="/sound/meditation" FOLDER=$(setFolder) ;; a) FOLDER_PATH="/sound/asmr" FOLDER=$(setFolder) ;; *) FILE=$OPTARG if [[ -d $FILE ]]; then echo "Identified given argument as directory." MODE="folder" if [[ $FILE == */ ]]; then FILE=${FILE%?} fi elif [[ -f $FILE ]]; then echo "Identified given argument as file." else echo "Error: Given argument $FILE is not valid file or directory" printHelp exit 1 fi esac done S3_URI="s3://${BUCKET_NAME}${FOLDER_PATH}" if [ "${MODE}" == "file" ]; then aws s3 cp ${FILE} ${S3_URI}/${FILE} else aws s3 cp ${FILE} ${S3_URI}/${FILE} --recursive fi updateToFirebase