Last active
August 6, 2019 14:44
-
-
Save nexus166/2b0f14d4f895e6128c5d456c52e045cc to your computer and use it in GitHub Desktop.
bash upload custom emojis to Rocket.Chat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| : ' | |
| Get your yamls at https://github.com/amtypaldos/rocketchat-emoji-upload#emoji-packs | |
| Create Personal Access Token at https://rocketchat.example.com/account/tokens | |
| Usage: ./rocketchat_emoji_upload.sh $LINK_TO_YAML $RC_URL $RC_AUTHTOKEN $RC_USERID | |
| Details https://rocket.chat/docs/developer-guides/rest-api/emoji-custom/ | |
| ' | |
| set -euo pipefail | |
| command -v curl | |
| command -v jq | |
| command -v yq | |
| YAML_PACK="${1}" | |
| RC_URL="${2}" | |
| RC_AUTHTOKEN="${3}" | |
| RC_USERID="${4}" | |
| pack_to_json() { curl -fsSLo- ${1} | yq read - -j; } | |
| post_new_emoji() { | |
| EMOJI_NAME=${1} | |
| EMOJI_FILE=${2} | |
| EMOJI_PACK=${3} | |
| curl -fS \ | |
| --header "X-Auth-Token: ${RC_AUTHTOKEN}" \ | |
| --header "X-User-Id: ${RC_USERID}" \ | |
| --form "emoji=@${EMOJI_FILE}" \ | |
| --form "name=${EMOJI_NAME}" \ | |
| --form "aliases=${EMOJI_PACK}-${EMOJI_NAME}" \ | |
| "${RC_URL}/api/v1/emoji-custom.create" | |
| } | |
| JSON_PACK="$(pack_to_json ${YAML_PACK})" | |
| EMOJI_PACK="$(echo $JSON_PACK | jq -cr '.title')" | |
| _TMPDIR="$(mktemp -d)" | |
| for _emoji_json in $(echo ${JSON_PACK} | jq -cr '.emojis[]'); do | |
| _name="$(echo ${_emoji_json} | jq -cr '.name')" | |
| _link="$(echo ${_emoji_json} | jq -cr '.src')" | |
| _fname="$(basename ${_link})" | |
| echo -e "Downloading ${_name} from ${_link}..\\n" | |
| curl -fsSLo "${_TMPDIR}/${_fname}" "${_link}" | |
| echo -e "Uploading ${_name} to Rocket.Chat..\\n" | |
| post_new_emoji "$_name" "${_TMPDIR}/${_fname}" "${EMOJI_PACK}" || echo "FAILED" | |
| echo | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment