Creating a zip for my app in bash script - xcode

I'm trying to use Xcode 5 bots for my Continuos Integration. I need to create a zip-file of my app-file.
In my scheme under Archive I use this script:
LATESTBUILD=$(ls -1rt /Library/Server/Xcode/Data/BotRuns | tail -1)
APP="/Library/Server/Xcode/Data/BotRuns/${LATESTBUILD}/output/Archive.xcarchive/Products/Applications/${PRODUCT_NAME}.app"
echo "Zipping .app for ${PRODUCT_NAME}"
/usr/bin/zip -r "${APP}.zip" "${APP}"
echo "Sending to *HockeyApp*"
curl \
-F "status=2" \
-F "notify=0" \
-F "notes=Testing CI" \
-F "notes_type=0" \
-F "ipa=${APP}.zip" \
-H "X-HockeyAppToken: myToken \
https://rink.hockeyapp.net/api/2/apps/myAppID/app_versions/upload
This will create a .zip-file. However, not the actual app but the whole folder structure for ${app}.
How can I create a zip-file that only contains the actual app?

To specify a file parameter with curl, you have to prefix the filename with #. Correct would be:
echo "Sending to *HockeyApp*"
curl \
-F "status=2" \
-F "notify=0" \
-F "notes=Testing CI" \
-F "notes_type=0" \
-F "ipa=#${APP}.zip" \
-H "X-HockeyAppToken: myToken \
https://rink.hockeyapp.net/api/2/apps/myAppID/app_versions/upload

Fixed this by stepping in to the directory before zipping it.
cd "/tmp/Archive.xcarchive/Products/Applications/"

Related

How Do You Pass a Variable to Curl in Bash Script

How Do You Pass a Variable to Curl in Bash Script
I'm not able to get this curl to work in a bash script using an environment variable. The API key gets misinterpreted somehow when passed in via a variable and I'm getting authentication errors on submit. If I plug in the API key with no surrounding quotes as plaintext, this works just fine. I've tried various forms of escaping quotes and other combinations. Any help would be great.
Code
#!/bin/bash
source .env
curl -X POST https://api.easypost.com/v2/shipments \
-u "$EASYPOST_TEST_API_KEY": \
-d 'shipment[to_address][name]=Dr. Steve Brule' \
-d 'shipment[to_address][street1]=179 N Harbor Dr' \
-d 'shipment[to_address][city]=Redondo Beach' \
-d 'shipment[to_address][state]=CA' \
-d 'shipment[to_address][zip]=90277' \
-d 'shipment[to_address][country]=US' \
-d 'shipment[to_address][phone]=8573875756' \
-d 'shipment[to_address][email]=dr_steve_brule#gmail.com' \
-d 'shipment[from_address][name]=EasyPost' \
-d 'shipment[from_address][street1]=417 Montgomery Street' \
-d 'shipment[from_address][street2]=5th Floor' \
-d 'shipment[from_address][city]=San Francisco' \
-d 'shipment[from_address][state]=CA' \
-d 'shipment[from_address][zip]=94104' \
-d 'shipment[from_address][country]=US' \
-d 'shipment[from_address][phone]=4153334445' \
-d 'shipment[from_address][email]=support#easypost.com' \
-d 'shipment[parcel][length]=20.2' \
-d 'shipment[parcel][width]=10.9' \
-d 'shipment[parcel][height]=5' \
-d 'shipment[parcel][weight]=65.9' \
Per Gordon Davisson's suggestion to break it down into a minimal request, it started sending right. Then I rebuilt it just as in my question above and for whatever reason it worked like a charm. The -x flag was also incredibly helpful in troubleshooting this but come to find out there wasn't anything inherently wrong with it in the first place. Thanks for everyone's responses!

Windows curl Batch file

I want to make a mailgun curl call using windows batch file. Since windows shell doesn't support multiple lines, how can I execute the below curl function in windows batch file?
curl -s --user 'api:key-xxxxxxxxxx' \
https://api.mailgun.net/v3/sandboxbxxxxxxxxxxxxx.mailgun.org/messages \
-F from='user <email#gmail.com>' \
-F to='user <email#live.com>' \
-F subject='Hello' \
-F text='body!' \
-F attachment=#test.txt \
Update
When I tried to execute the command after removing the multiple lines it returned this error:
curl -s --user 'api:key-xxxxxxxxxx' https://api.mailgun.net/v3/sandboxbxxxxxxxxxxxxx.mailgun.org/messages -F from='user -F to='user -F subject='Hello' -F text='body!' -F attachment=#test.txt 0<email#live.com 1>'
The system cannot find the file specified.
PS: The attachment file is in the same directory
Thanks!
simply on one line and put the <> redirection char between " or escape it with ^:
curl -s --user 'api:key-xxxxxxxxxx' https://api.mailgun.net/v3/sandboxbxxxxxxxxxxxxx.mailgun.org/messages -F from="user <email#gmail.com>" -F to="user <email#live.com>" -F subject='Hello' -F text='body!' -F attachment=#test.txt
You can also create variable for each element :
set "$ApiKey=api:key-xxxxxxxxxx"
set "$Url=https://api.mailgun.net/v3/sandboxbxxxxxxxxxxxxx.mailgun.org/messages"
set "$From=email#gmail.com"
....
and then
curl -s --user '%$ApiKey%' %$Url% -F from="user <%$From%>" -F to= ....

curl call with parameters into variable doesn't work

I'm working with installr API.
I'm trying to do the following curl request via a script :
curl -H "X-InstallrAppToken: mytoken" https://www.installrapp.com/apps.json/ \
-F 'qqfile=#'$APKPATH \
-F 'releaseNotes=These are my release notes' \
-F 'notify=true'
and it works perfectly.
However, when I try to get my release notes from a file with a variable like this :
RELEASENOTES=`cat "release_notes/test.md"`
curl -H "X-InstallrAppToken: mytoken" https://www.installrapp.com/apps.json/ \
-F 'qqfile=#'$APKPATH \
-F 'releaseNotes='$RELEASENOTES \
-F 'notify=true' > /dev/null
it doesn't work at all, only the first word is sent. For the others, I have the error Could not resolve host: xxx.
I did a echo on these two curl request and the exact same thing is printed.
is that the catcommand which return a specific format ?
Probably an issue with the quotes and spaces. You can use double-quotes around a variable to allow variable expansion in the shell.
RELEASENOTES=$(cat "release_notes/test.md")
curl -H "X-InstallrAppToken: mytoken" https://www.installrapp.com/apps.json/ \
-F "qqfile=#${APKPATH}" \
-F "releaseNotes=${RELEASENOTES}" \
-F 'notify=true' > /dev/null

How to get the file size on Unix in a Makefile?

I would like to implement this as a Makefile task:
# step 1:
curl -u username:password -X POST \
-d '{"name": "new_file.jpg","size": 114034,"description": "Latest release","content_type": "text/plain"}' \
https://api.github.com/repos/:user/:repo/downloads
# step 2:
curl -u username:password \
-F "key=downloads/octocat/Hello-World/new_file.jpg" \
-F "acl=public-read" \
-F "success_action_status=201" \
-F "Filename=new_file.jpg" \
-F "AWSAccessKeyId=1ABCDEF..." \
-F "Policy=ewogIC..." \
-F "Signature=mwnF..." \
-F "Content-Type=image/jpeg" \
-F "file=#new_file.jpg" \
https://github.s3.amazonaws.com/
In the first part however, I need to get the file size (and content type if it's easy, not required though), so some variable:
{"name": "new_file.jpg","size": $(FILE_SIZE),"description": "Latest release","content_type": "text/plain"}
I tried this but it doesn't work (Mac 10.6.7):
$(shell du path/to/file.js | awk '{print $1}')
Any ideas how to accomplish this?
If you have GNU coreutils:
FILE_SIZE=$(stat -L -c %s $filename)
The -L tells it to follow symlinks; without it, if $filename is a symlink it will give you the size of the symlink rather than the size of the target file.
The MacOS stat equivalent appears to be:
FILE_SIZE=$(stat -L -f %z)
but I haven't been able to try it. (I've written this as a shell command, not a make command.) You may also find the -s option useful:
Display information in "shell output", suitable for initializing variables.
For reference, an alternative method is using du with -b bytes output and -s for summary only. Then cut to only keep the first element of the return string
FILE_SIZE=$(du -sb $filename | cut -f1)
This should return the same result in bytes as #Keith Thompson answer, but will also work for full directory sizes.
Extra: I usually use a macro for this.
define sizeof
$$(du -sb \
$(1) \
| cut -f1 )
endef
Which can then be called like,
$(call sizeof,$filename_or_dirname)
I think this is a case where parsing the output of ls is legitimate:
% FILE_SIZE=`ls -l $filename | awk '{print $5}'`
(no it's not: use stat, as noted by Keith Thompson)
For the type, you can use
% FILE_TYPE=`file --mime-type --brief $filename`

Installing Magento automatically

I'm thinking about installing magento in automatical way. I suppose that I need to create some script or something... but I guess I'm not first person whom need it. So do you know about any good resource or solution how to it? It would work in Windows and Linux OS. Thanks. Jaro.
There are probably others out there but here is a quick and dirty script I use form time to time to install Magento checkout my svn repo and initialise modman. It could be extended to create database if required etc, but it works fine for me as is:
#!/bin/bash
# Required Script Variables
DB_NAME=
DB_USER=
DB_HOST=
DB_PASS=
URL=
MAGENTO_VERSION="1.7.0.0"
ADMIN_FIRSTNAME=
ADMIN_SURNAME=
ADMIN_EMAIL=
ADMIN_USER=
ADMIN_PASS=
SVN_REPO=
# Download and install Magento
wget http://www.magentocommerce.com/downloads/assets/$MAGENTO_VERSION/magento-$MAGENTO_VERSION.tar.gz
printf "\n\nUnpacking and preparing to install Magento...\n"
tar -zxvf magento-$MAGENTO_VERSION.tar.gz
mv magento/* magento/.htaccess .
chmod -R o+w media var
chmod o+w app/etc
rm -rf downloader/pearlib/cache/* downloader/pearlib/download/*
rm -rf magento/ magento-$MAGENTO_VERSION.tar.gz
printf "\n\nInstalling Magento...\n"
/usr/local/bin/php -f install.php -- \
--license_agreement_accepted "yes" \
--locale "en_GB" \
--timezone "Europe/London" \
--default_currency "GBP" \
--db_host "$DB_HOST" \
--db_name "$DB_NAME" \
--db_user "$DB_USER" \
--db_pass "$DB_PASS" \
--url "$URL" \
--use_rewrites "yes" \
--use_secure "no" \
--secure_base_url "" \
--use_secure_admin "no" \
--skip_url_validation "yes" \
--admin_firstname "$ADMIN_FIRSTNAME" \
--admin_lastname "$ADMIN_SURNAME" \
--admin_email "$ADMIN_EMAIL" \
--admin_username "$ADMIN_USER" \
--admin_password "$ADMIN_PASS"
# Setup svn and modman
modman init
mkdir .modman/modules
svn co $SVN_REPO .modman/modules
modman update-all

Resources