Bash脚本-无法解决代码“帮助”错误

时间:2019-02-22 15:57:35

标签: linux bash windows-subsystem-for-linux

我在这里使用的bash脚本用于将应用程序推送到Hockey App,以将其发送给测试人员。 我的bash脚本代码在这里有问题:

#!/bin/bash
# locations of various tools
CURL=curl
SERVER_ENDPOINT=https://rink.hockeyapp.net/api/2/
# Put your HockeyApp APP_TOKEN here. Find it in your HockeyApp account settings.
APP_TOKEN=0343e6b12808457581147d56fb5ad4bd
# ipa required, "file data of the .ipa for iOS, .app.zip for OS X, or .apk file for Android
IPA=$2
# dsym optional,file data of the .dSYM.zip file (iOS and OS X) or mapping.txt (Android);
# note that the extension has to be .dsym.zip (caseinsensitive) for iOS and OS X and the file nam
DSYM=""
# notes optional, release notes as Textile or Markdown (after 5k characters note are truncated)
NOTES=$3
# echo $NOTES
# notes_type optional, ntype of release notes:
# 0 for Textile
# 1 for Markdown
NOTES_TYPE=""
# optional, notify testers (can only be set with fullaccess tokens):
# 0 to not notify testers
# 1 to notify all testers that can install this app
# 2 Notify all testers
NOTIFY=$4
echo $NOTIFY
# status optional, download status (can only be set with fullaccess tokens):
# 1 to not allow users to download the version
# 2 to make the version available for download
STATUS="2"
# strategy optional, replace or add build with same build number
# add to add the build as a new build to even if it has the same build number (default)
# replace to replace to a build with the same build number
STRATEGY="replace"
# tags optional, restrict download to commaseparated list of tags
TAGS=""
# teams optional, restrict download to commaseparated list of team IDs; example:
# 12,23,42 with 12, 23, and 42 being the database IDs of your teams
TEAMS=""
# users optional, restrict download to commaseparated list of user IDs; example:
# 1224,5678 with 1224 and 5678 being the database IDs of your users
USERS=""
# mandatory optional, set version as mandatory:
# 0 for not mandatory
# 1 for mandatory
MANDATORY=""
# release_type optional, set the release type of the app:
# 2 for alpha
# 0 for beta [default]
# 1 for store
# 3 for enterprise
RELEASE_TYPE=""
# private optional, set to true to enable the private download page (default is true)
PRIVATE=""
# owner_id optional, set to the ID of your organization
OWNER_ID=""
# commit_sha optional, set to the git commit sha for this build
COMMIT_SHA=""
# build_server_url optional, set to the URL of the build job on your build server
BUILD_SERVER_URL=""
# repository_url optional, set to your source repository
REPOSITORY_URL=""
usage() {
echo "Usage: hockeyappuploader.sh IPA"
echo
}
verify_tools() {
# Windows users: this script requires curl. If not installed please get from http://cygwin
# Check 'curl' tool
"${CURL}" help
>/dev/null
if [ $? ne 0 ]; then
echo "Could not run curl tool, please check settings"
exit 1
fi
}
verify_settings() {
if [ z "${APP_TOKEN}" ]; then
usage
echo "Please update APP_TOKEN with your private API key, as noted in the Settings"
exit 1
fi
}
# if [ $# ne 1 ];then
# usage
# exit 1
# fi
# before even going on, make sure all tools work
verify_tools
verify_settings
if [ ! f "${IPA}" ]; then
usage
echo "Can't find file: ${IPA}"
exit 2
fi
/bin/echo n "Uploading ${IPA} to HockeyApp.. "

JSON=$( "${CURL}" \s
${SERVER_ENDPOINT}/apps/upload \H
"XHockeyAppToken: ${APP_TOKEN}" \F
"ipa=@${IPA}" \F
"dsym=@${DSYM}" \F
"notes=${NOTES}" \F
"notes_type=${NOTES_TYPE}" \F
"notify=${NOTIFY}" \F
"status=${STATUS}" \F
"strategy=${STRATEGY}" \F
"tags=${TAGS}" \F
"teams=${TEAMS}" \F
"users=${USERS}" \F
"mandatory=${MANDATORY}" \F
"release_type=${RELEASE_TYPE}" \F
"private=${PRIVATE}" \F
"owner_id=${OWNER_ID}" \F
"commit_sha=${COMMIT_SHA}" \F
"build_server_url=${BUILD_SERVER_URL}" \F
"repository_url=${REPOSITORY_URL}" \)
URL=$( echo ${JSON} | sed 's/\\\//\//g' | sed n 's/.*"public_url"\s*:\s*"\([^"]*\)".*/\1/p' )
if [ z "$URL" ]; then
echo "FAILED!"
echo
echo "Build uploaded, but no reply from server!  Please contact support."
exit 1
fi
echo "OK!"
echo
echo "Build was successfully uploaded to HockeyApp and is available at:"
echo ${URL}

出现以下错误:

curl: (6) Could not resolve host: H
curl: (3) Port number ended with 'e'
curl: (6) Could not resolve host: F
curl: (3) Illegal characters found in URL
curl: (6) Could not resolve host: F
curl: (7) Failed to connect to  port 80: Connection refused
curl: (6) Could not resolve host: F
curl: (6) Could not resolve host: notes=2
curl: (6) Could not resolve host: F
curl: (6) Could not resolve host: notes_type=0
curl: (6) Could not resolve host: F
curl: (6) Could not resolve host: notify=
curl: (6) Could not resolve host: F
curl: (6) Could not resolve host: status=2
curl: (6) Could not resolve host: F
curl: (6) Could not resolve host: strategy=replace
curl: (6) Could not resolve host: F
curl: (6) Could not resolve host: tags=
curl: (6) Could not resolve host: F
curl: (6) Could not resolve host: teams=
curl: (6) Could not resolve host: F
curl: (6) Could not resolve host: users=
curl: (6) Could not resolve host: F
curl: (6) Could not resolve host: mandatory=
curl: (6) Could not resolve host: F
curl: (6) Could not resolve host: release_type=
curl: (6) Could not resolve host: F
curl: (6) Could not resolve host: private=
curl: (6) Could not resolve host: F
curl: (6) Could not resolve host: owner_id=
curl: (6) Could not resolve host: F
curl: (6) Could not resolve host: commit_sha=
curl: (6) Could not resolve host: F
curl: (6) Could not resolve host: build_server_url=
curl: (6) Could not resolve host: F
curl: (6) Could not resolve host: repository_url=
curl: (6) Could not resolve host:  
sed: s/.*"public_url"\s*:\s*"\([^"]*\)".*/\1/p: No such file or directory

curl: (6) Could not resolve host: help
./UploadFile.sh: line 71: [: ne: binary operator expected
./UploadFile.sh: line 76: [: z: unary operator expected
./UploadFile.sh: line 89: [: f: unary operator expected
./UploadFile.sh: line 97: [: z: unary operator expected

以下错误将由这些代码行引起:

卷曲:(6)无法解析主机:帮助:

"${CURL}" help
>/dev/null

第71行:

if [ $? ne 0 ]; then

第76行:

if [ z "${APP_TOKEN}" ]; then

第89行:

if [ ! f "${IPA}" ]; then

第97行:

${SERVER_ENDPOINT}/apps/upload \H

任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

您是否尝试正确引用curl命令?

JSON=$( "${CURL}" \s
"${SERVER_ENDPOINT}/apps/upload" "\H
XHockeyAppToken: ${APP_TOKEN} \F
ipa=@${IPA} \F
dsym=@${DSYM} \F
notes=${NOTES} \F
notes_type=${NOTES_TYPE} \F
notify=${NOTIFY} \F
status=${STATUS} \F
strategy=${STRATEGY} \F
tags=${TAGS} \F
teams=${TEAMS} \F
users=${USERS} \F
mandatory=${MANDATORY} \F
release_type=${RELEASE_TYPE} \F
private=${PRIVATE} \F
owner_id=${OWNER_ID} \F
commit_sha=${COMMIT_SHA} \F
build_server_url=${BUILD_SERVER_URL} \F
repository_url=${REPOSITORY_URL}" )

(此外,您可以从SERVER_ENDPOINT=https://rink.hockeyapp.net/api/2/中删除最后一个斜杠,因为它会在curl命令中添加另一个斜杠)

答案 1 :(得分:0)

脚本文件在很多方面都严重乱码。稍作搜索后,我猜您是从this Innominds.com blog entry复制过来的,它具有类似(但不相同)的乱码。我不确定该脚本的规范/最佳版本是什么,但是有一个in Alexandr Dascal's github版本看起来合理。

您遇到的大多数特定错误均来自实际执行上传的部分。这是Alexandr Dascal版本的比较片段:

/bin/echo -n "Uploading ${IPA} to HockeyApp.. "
JSON=$( "${CURL}" \
        -s ${SERVER_ENDPOINT}/apps/upload \
        -H "X-HockeyAppToken: ${APP_TOKEN}" \
        -F "ipa=@${IPA}" \
        -F "dsym=@${DSYM}" \

以及Innominds博客版本:

/bin/echo n
"Uploading ${IPA} to HockeyApp.. "
JSON=$( "${CURL}" \
s
${SERVER_ENDPOINT}/apps/upload \
H
"XHockeyAppToken:
${APP_TOKEN}" \
F
"ipa=@${IPA}" \
F
"dsym=@${DSYM}" \
F

您的版本:

/bin/echo n "Uploading ${IPA} to HockeyApp.. "

JSON=$( "${CURL}" \s
${SERVER_ENDPOINT}/apps/upload \H
"XHockeyAppToken: ${APP_TOKEN}" \F
"ipa=@${IPA}" \F
"dsym=@${DSYM}" \F

无论如何,无论是什么原因,您的版本都被严重搞砸了。为该脚本找到一个更好的来源(以及可能从同一来源获得的其他任何来源)。