Buenas, tengo un .sh de linux, y lo quisiera mirar a otro lenguaje para poder crear un .exe
La verdad que no intiendo un poco de secuencial shell en linux, lo que necesito es poder subir archivos a megaupload.
Código:
#!/bin/bash
#
# Upload a file to megaupload (anonymously or using a registered account).
# Output URL for the uploaded file.
#
# Dependencies: curl
#
# Web: http://code.google.com/p/megaupload-dl
# Contact: Arnau Sanchez <[email protected]>.
#
# License: GNU GPL v3.0: http://www.gnu.org/licenses/gpl-3.0-standalone.html
#
set -e
AGENT="Mozilla Firefox / 3.01"
# Echo text to standard error.
#
debug() { echo "$@" >&2; }
curl() {
while true; do
$(type -P curl) "$@" && DRETVAL=0 || DRETVAL=$?
if [ $DRETVAL -eq 6 -o $DRETVAL -eq 7 ]; then
debug "curl failed with retcode $DRETVAL, trying again"
continue
else
return $DRETVAL
fi
done
}
# Get first line that matches a regular expression and extract string from it.
#
# $1: POSIX-regexp to filter (get only the first matching line).
# $2: POSIX-regexp to match (use parentheses) on the matched line.
#
parse() { sed -n "/$1/ s/^.*$2.*$/\1/p" | head -n1; }
# Login to megaupload and return cookies
#
# $1/$2: User/password
login() {
USER=$1
PASSWORD=$2
LOGINURL="http://www.megaupload.com"
if test "$USER" -a "$PASSWORD"; then
debug "starting login process: $USER/$(sed 's/./*/g' <<< "$PASSWORD")"
COOKIES=$(curl -A "$AGENT" -o /dev/null -c - \
-d "username=$USER&password=$PASSWORD&login=1&redir=1" $LOGINURL)
test "$COOKIES" || { debug "login error"; return 2; }
debug "using cookies: $COOKIES"
echo "$COOKIES"
else
debug "no login info: anonymous upload"
fi
}
# Upload a file to megaupload
#
# $1: File path
# $2: Description
# $3: Cookies contents (optional)
#
upload_file() {
FILE=$1
DESCRIPTION=$2
COOKIES=$3
UPLOADURL="http://www.megaupload.com"
debug "downloading upload page: $UPLOADURL"
DONE=$(curl "$UPLOADURL" | parse "upload_done.php" 'action="\([^\"]*\)"')
test "$DONE" || { debug "can't get upload_done page"; return 2; }
UPLOAD_IDENTIFIER=$(parse "IDENTIFIER" "IDENTIFIER=\([0-9.]\+\)" <<< $DONE)
debug "starting file upload: $DONE"
curl -A "$AGENT" \
-b <(echo "$COOKIES") \
-F "UPLOAD_IDENTIFIER=$UPLOAD_IDENTIFIER" \
-F "sessionid=$UPLOAD_IDENTIFIER" \
-F "file=@$FILE;filename=$(basename "$FILE")" \
-F "message=$DESCRIPTION" \
"$DONE" | parse "downloadurl" "url = '\(.*\)';"
}
# Main
if test $# -lt 2 -o $# -gt 3; then
debug "Upload a file to megaupload (anonymously or using an account)."
debug
debug "Usage: $(basename $0) FILE DESCRIPTION [USER:PASSWORD]"
exit 1
fi
FILE=$1
DESCRIPTION=$2
USERINFO=$3
IFS=":" read USER PASSWORD <<< "$USERINFO"
COOKIES=$(login "$USER" "$PASSWORD")
upload_file "$FILE" "$DESCRIPTION" "$COOKIES"