#!/bin/bash usage() { echo "Usage: $0 -f | --file -d | --directory -F | --remote-file -b | --bucket -k | --key -D | --domain -e | --endpoint -R | --remove remove remote file --noprogress --help" exit 1 } LOCAL_FILE=unset ALI_KEY_FILE="" ALI_BUCKET_NAME='ipfsbit-cdn' ALI_END_POINT='oss-cn-beijing.aliyuncs.com' ALI_DIRECOTRY=unset ALI_REMOTE_FILENAME=unset REMOVE=unset NOPROGRESS="" declare -A DOMAIN_MAP declare -A BUCKET_MAP DOMAIN_MAP["https://cdn.linkfog.cn"]="ipfsbit-cdn" DOMAIN_MAP["https://test-cdn.linkfog.cn"]="ipfsbit-test-bucket" DOMAIN_MAP["https://cdn2.linkfog.cn"]="agent-ipbit" DOMAIN_MAP["https://saas-cdn.linkfog.cn"]="saas-linkfog-bucket" BUCKET_MAP["ipfsbit-cdn"]="https://cdn.linkfog.cn" BUCKET_MAP["ipfsbit-test-bucket"]="https://test-cdn.linkfog.cn" BUCKET_MAP["agent-ipbit"]="https://cdn2.linkfog.cn" BUCKET_MAP["saas-linkfog-bucket"]="https://saas-cdn.linkfog.cn" PARSED_ARUGMENTS=$(getopt -a -n "$0" -o i:b:k:D:e:d:F:R --long help,file:,bucket:,key:,domain:,endpoint:,directory:,remote-file:,remove,noprogress -- "$@") eval set -- "$PARSED_ARUGMENTS" while : do case "$1" in -f | --file) LOCAL_FILE="$2"; shift 2 ;; -b | --bucket) ALI_BUCKET_NAME="$2"; shift 2 ;; -k | --key) ALI_KEY_FILE="$2"; shift 2 ;; -D | --domain) ALI_DOMAIN="$2"; shift 2 ;; -e | --endpoint) ALI_END_POINT="$2"; shift 2 ;; -d | --directory) ALI_DIRECOTRY="$2"; shift 2 ;; -F | --remote-file) ALI_REMOTE_FILENAME="$2"; shift 2 ;; -R | --remove) REMOVE="true"; shift 1;; --noprogress) NOPROGRESS="true"; shift 1;; --help) usage ;; --) shift; break;; *) usage ;; esac done if [[ -n "$ALI_DOMAIN" ]] then if ! echo $ALI_DOMAIN | grep -q "^https://" then ALI_DOMAIN="https://${ALI_DOMAIN}" fi ALI_BUCKET_NAME=${DOMAIN_MAP[$ALI_DOMAIN]} elif [[ -n "$ALI_BUCKET_NAME" ]] then ALI_DOMAIN=${BUCKET_MAP[$ALI_BUCKET_NAME]} [[ -z "$ALI_DOMAIN" ]] && ALI_DOMAIN="https://${ALI_BUCKET_NAME}.oss-cn-beijing.aliyuncs.com" fi if [[ -z "$ALI_DOMAIN" ]] || [[ -z "$ALI_BUCKET_NAME" ]] then >&2 echo "域名或bucket 名字错误。需要用 --domain 传递cdn域名参数 或用 --bucket 传递bucket 名字" >&2 echo "支持以下域名或bucket:" for item in ${DOMAIN_MAP[@]} do >&2 echo ${BUCKET_MAP[$item]} $item done exit 1 fi if [[ "$ALI_KEY_FILE" != "" ]] then ALI_KEY_ID="$(cat $ALI_KEY_FILE | cut -d',' -f1)" ALI_KEY_SECRET="$(cat $ALI_KEY_FILE | cut -d',' -f2)" else ALI_KEY_ID="LTAI4FgkFhkJqvSjuv6Qo5eD" ALI_KEY_SECRET="eu3kMJCVg90NP3hcCUy5aDE0YpAkBM" fi if [[ "$ALI_REMOTE_FILENAME" != "unset" ]] then ALI_REMOTE_FILENAME="$ALI_DIRECOTRY/$ALI_REMOTE_FILENAME" else ALI_REMOTE_FILENAME="$ALI_DIRECOTRY/""$(basename $LOCAL_FILE)" fi if [[ "$REMOVE" == "unset" ]] then if [[ -n "$NOPROGRESS" ]] then args="--noprogress" fi upload -k "$ALI_KEY_ID" \ -s "$ALI_KEY_SECRET" \ -b "$ALI_BUCKET_NAME" \ -e "$ALI_END_POINT" \ -r "$ALI_REMOTE_FILENAME" \ -f "$LOCAL_FILE" \ --domain "$ALI_DOMAIN" $args printf "\n\n" printf "%s/%s\n" $ALI_DOMAIN $ALI_REMOTE_FILENAME else upload -k "$ALI_KEY_ID" \ -s "$ALI_KEY_SECRET" \ -b "$ALI_BUCKET_NAME" \ -e "$ALI_END_POINT" \ -r "$ALI_REMOTE_FILENAME" \ -d fi