Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Commit

Permalink
Working upload for app and plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Heckel committed Mar 3, 2015
1 parent bd6c3bf commit bee59c1
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 45 deletions.
14 changes: 7 additions & 7 deletions gradle/upload/upload-application.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if [ -n "$TRAVIS_PULL_REQUEST" -a "$TRAVIS_PULL_REQUEST" != "false" ]; then
exit 0
fi

source "$SCRIPTDIR/upload-functions.sh"
source "$SCRIPTDIR/upload-functions"

properties_file=$REPODIR/syncany-lib/build/resources/main/application.properties

Expand Down Expand Up @@ -81,20 +81,20 @@ file_javadoc=$(ls $REPODIR/build/upload/javadoc.tar.gz)
[ -f "$file_javadoc" ] || (echo "ERROR: Not found: $file_javadoc" && exit 3)

echo "Uploading TAR.GZ: $(basename $file_targz) ..."
upload_file "$file_targz" "tar.gz" "app" "$snapshot" "all" "all"
upload_app "$file_targz" "tar.gz" "$snapshot"

echo "Uploading ZIP: $(basename $file_zip) ..."
upload_file "$file_zip" "zip" "app" "$snapshot" "all" "all"
upload_app "$file_zip" "zip" "$snapshot"

echo "Uploading DEB: $(basename $file_deb) ..."
upload_file "$file_deb" "deb" "app" "$snapshot" "all" "all"
upload_app "$file_deb" "deb" "$snapshot"

echo "Uploading EXE: $(basename $file_exe) ..."
upload_file "$file_exe" "exe" "app" "$snapshot" "all" "all"
upload_app "$file_exe" "exe" "$snapshot"

echo "Uploading REPORTS: $(basename $file_reports) ..."
upload_file "$file_reports" "exe" "app/reports" "$snapshot" "all" "all"
upload_file "$file_reports" "app/reports" "snapshot=$snapshot"

echo "Uploading JAVADOC: $(basename $file_javadoc) ..."
upload_file "$file_javadoc" "exe" "app/javadoc" "$snapshot" "all" "all"
upload_file "$file_javadoc" "app/javadoc" "snapshot=$snapshot"

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SYNCANY_API_ENDPOINT="https://api.syncany.org/v3"
SYNCANY_API_ENDPOINT="http://tests.lan/syncany-website/api.syncany.org/html/v3"
#SYNCANY_API_ENDPOINT="http://tests.lan/syncany-website/api.syncany.org/html/v3"

if [ "$SYNCANY_API_KEY" == "" ]; then
echo "ERROR: SYNCANY_API_KEY environment variable not set."
Expand All @@ -20,16 +20,13 @@ urlencode() {
}

upload_file() {
# upload_file <filename> <type> <request> <snapshot> <os> <arch>
# upload_file <filename> <request> <method_args>

filename="$1"
type="$2"
request="$3"
snapshot="$4"
os="$5"
arch="$6"
request="$2"
method_args="$3"

if [ -z "$filename" -o -z "$type" -o -z "$request" -o -z "$snapshot" -o -z "$os" -o -z "$arch" ]; then
if [ -z "$filename" -o -z "$request" -o -z "$method_args" ]; then
echo "ERROR: Invalid arguments for upload_file. None of the arguments can be zero."
exit 2
fi
Expand All @@ -43,23 +40,75 @@ upload_file() {
basename_encoded=$(urlencode $basename)
checksum=$(sha256sum "$filename" | awk '{ print $1 }')

method="PUT"
methodArgs="type=$type&filename=$basename_encoded&snapshot=$snapshot&os=$os&arch=$arch&checksum=$checksum"

time=$(date +%s)
rand=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1)
method_args="$method_args&filename=$basename_encoded&checksum=$checksum&time=$time&rand=$rand"

protected="$method:$request:$methodArgs:$time:$rand"
protected="PUT:$request:$method_args"
signature=$(echo -n "$protected" | openssl dgst -sha256 -hmac $SYNCANY_API_KEY | awk '{ print $2 }')
full_url="$SYNCANY_API_ENDPOINT/$request?$method_args&signature=$signature"

curl -v -T "$filename" "$SYNCANY_API_ENDPOINT/$request?$methodArgs&time=$time&rand=$rand&signature=$signature"
rm /tmp/curlerr.tmp 2> /dev/null || true

http_response_code=$(curl \
--verbose \
--silent \
--output /dev/null \
--write-out "%{http_code}" \
--stderr /tmp/curlerr.tmp \
--upload-file "$filename" \
"$full_url")

exit_code=$?

if [ $exit_code -ne 0 ]; then
echo "ERROR: Upload failed. curl exit code was $exit_code."
exit 5
if [ "$exit_code" != "0" -o "$http_response_code" != "200" ]; then
echo ""
echo "ERROR: Upload failed. curl exit code was $exit_code, HTTP response code was $http_response_code."

if [ -f /tmp/curlerr.tmp ]; then
echo ""
echo "Details:"
echo ""
cat /tmp/curlerr.tmp | sed -r 's/signature=\w+/signature=[REMOVED]/'
echo ""
fi

exit 6
fi
}

upload_plugin() {
# upload_plugin <filename> <type> <plugin_id> <snapshot> <os> <arch>

file="$1"
type="$2"
plugin_id="$3"
snapshot="$4"

if [ -z "$file" -o -z "$type" -o -z "$plugin_id" -o -z "$snapshot" ]; then
echo "ERROR: Invalid arguments for upload_plugin. None of the arguments can be zero."
exit 2
fi

os=$(get_os_from_filename "$(basename "$file")")
arch=$(get_arch_from_filename "$(basename "$file")")

upload_file "$file" "plugins/$plugin_id" "type=$type&snapshot=$snapshot&os=$os&arch=$arch"
}

upload_app() {
# upload_app <filename> <type> <snapshot>

file="$1"
type="$2"
snapshot="$3"

if [ -z "$file" -o -z "$type" -o -z "$snapshot" ]; then
echo "ERROR: Invalid arguments for upload_app. None of the arguments can be zero."
exit 2
fi

upload_file "$file" "app" "type=$type&snapshot=$snapshot"
}

get_property() {
Expand Down
28 changes: 6 additions & 22 deletions gradle/upload/upload-plugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ if [ -n "$TRAVIS_PULL_REQUEST" -a "$TRAVIS_PULL_REQUEST" != "false" ]; then
exit 0
fi

source "$SCRIPTDIR/upload-functions.sh"
source "$SCRIPTDIR/upload-functions"

properties_file=$(ls -d build/resources/main/org/syncany/plugins/*/plugin.properties)
properties_file=$(ls build/resources/main/org/syncany/plugins/*/plugin.properties)

if [ ! -f "$properties_file" ]; then
echo "ERROR: Cannot find properties file with plugin details."
Expand Down Expand Up @@ -42,38 +42,22 @@ files_appzip=$(ls $REPODIR/build/upload/*.app.zip 2> /dev/null)

for file in $files_jar; do
echo "Uploading JAR: $(basename $file) ..."

os=$(get_os_from_filename "$(basename "$file")")
arch=$(get_arch_from_filename "$(basename "$file")")

upload_file "$file" "jar" "plugins/$plugin_id" "$snapshot" "$os" "$arch"
upload_plugin "$file" "jar" "$plugin_id" "$snapshot"
done

for file in $files_deb; do
echo "Uploading DEB: $(basename $file) ..."

os=$(get_os_from_filename "$(basename "$file")")
arch=$(get_arch_from_filename "$(basename "$file")")

upload_file "$file" "deb" "plugins/$plugin_id" "$snapshot" "$os" "$arch"
upload_plugin "$file" "deb" "$plugin_id" "$snapshot"
done

if [ "$plugin_id" == "gui" ]; then
for file in $files_exe; do
echo "Uploading EXE: $(basename $file) ..."

os=$(get_os_from_filename "$(basename "$file")")
arch=$(get_arch_from_filename "$(basename "$file")")

upload_file "$file" "exe" "plugins/$plugin_id" "$snapshot" "$os" "$arch"
upload_plugin "$file" "exe" "$plugin_id" "$snapshot"
done

for file in $files_appzip; do
echo "Uploading APP.ZIP: $(basename $file) ..."

os=$(get_os_from_filename "$(basename "$file")")
arch=$(get_arch_from_filename "$(basename "$file")")

upload_file "$file" "app.zip" "plugins/$plugin_id" "$snapshot" "$os" "$arch"
upload_plugin "$file" "app.zip" "$plugin_id" "$snapshot"
done
fi

0 comments on commit bee59c1

Please sign in to comment.