Skip to content

Instantly share code, notes, and snippets.

@mohemohe
Last active January 25, 2019 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohemohe/d74dd8eeb7724d6f760d6014508f0974 to your computer and use it in GitHub Desktop.
Save mohemohe/d74dd8eeb7724d6f760d6014508f0974 to your computer and use it in GitHub Desktop.
#!/bin/bash
CMDS='
curl
jq
'
for cmd in $CMDS; do {
if [[ ! $(command -v "$cmd") ]]; then {
echo "'$cmd' コマンドがありません" 1>&2
exit 1
} fi
} done
if [[ ! -r "${HOME}/.butimilirc" ]]; then {
cat <<EOS > "${HOME}/.butimilirc"
# https://butimi.li のログインユーザー
BUTIMILI_USERNAME=
# https://butimi.li のログインパスワード
BUTIMILI_PASSWORD=
# 自インスタンスのドメイン https:// は要らない
MASTODON_HOST=mstdn.plusminus.io
# mastodonのアクセストークン
MASTODON_ACCESS_TOKEN=
EOS
echo "'${HOME}/.butimilirc' を作成しました" 1>&2
echo "設定してから実行してください" 1>&2
exit 9
} fi
source "${HOME}/.butimilirc"
AUTH_RESULT="$(curl -Ls \
https://butimi.li/api/v1/auth \
-X POST \
-H "Content-Type: application/json" \
-d "{\"username\":\"${BUTIMILI_USERNAME}\",\"password\":\"${BUTIMILI_PASSWORD}\"}")"
if [[ "$(echo "${AUTH_RESULT}" | jq -r '.error' )" != "0" ]]; then {
echo "https://butimi.li にログインできませんでした" 1>&2
exit 2
} fi
BUTIMILI_TOKEN="$(echo "${AUTH_RESULT}" | jq -r '.data.token')"
BUTIMILI_TEXT="$(curl -Ls \
https://butimi.li/api/v1/butimili \
-X GET \
-H "Authorization: Bearer ${BUTIMILI_TOKEN}")"
TOOT_RESULT="$(curl -Ls \
"https://${MASTODON_HOST}/api/v1/statuses" \
-X POST \
-H "Authorization: Bearer ${MASTODON_ACCESS_TOKEN}" \
-d "status=${BUTIMILI_TEXT}" \
-d "visibility=unlisted")"
if [[ "$(echo "${TOOT_RESULT}" | jq -r '.id' )" != "" ]]; then {
echo "ブチミりました" 1>&2
exit 0
} fi
echo "ブチミれませんでした" 1>&2
exit 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment