Commit | Line | Data |
---|---|---|
c0e2704f IK |
1 | #!/bin/bash |
2 | # Copyright (C) 2019 Ian Kelling | |
3 | # SPDX-License-Identifier: AGPL-3.0-or-later | |
4 | ||
5 | # meant to be sourced. | |
6 | ||
7 | PATH="$HOME/.local/bin:$PATH" | |
8 | ||
9 | # usage: rbow [-PROFILE_NAME] [COMMAND] | |
10 | # | |
11 | # Wrapper for rainbowstream to use multiple logins and tweet directly | |
12 | # from the command line. PROFILE_NAME can be anything you want. | |
13 | rbow() { | |
14 | local oath | |
15 | oath=$HOME/.rainbow_oauth | |
16 | if [[ $1 == -* ]]; then | |
17 | rm -f $oath | |
18 | ln -s $oath$1 $oath | |
19 | shift | |
20 | fi | |
21 | source ~/src/rainbowstream/venv/bin/activate | |
22 | if (($#)); then | |
23 | f=$(mktemp) | |
24 | cat >$f <<'EOF' | |
25 | # adds a short delay after each send for more reliable operation | |
26 | set force_conservative 0 | |
27 | spawn "rainbowstream" | |
28 | # wait for prompt | |
29 | expect -nocase timeout {exit 1} "@*]: " | |
30 | set cmd [lindex $argv 0]; | |
31 | send "$cmd\r\rq\r" | |
32 | interact | |
33 | EOF | |
34 | expect $f "$*" || { deactivate; rm -f $f; return 1; } | |
35 | rm -f $f | |
36 | else | |
37 | rainbowstream | |
38 | fi | |
39 | deactivate | |
40 | } | |
41 | ||
42 | diaspora() { | |
43 | source ~/src/diaspy/venv/bin/activate | |
44 | python3 ~/src/jan-pona-mute/jan-pona-mute.py "$@" || { deactivate; return 1; } | |
45 | deactivate | |
46 | } | |
47 | ||
48 | # usage: toot [-PROFILE_NAME] [TOOT_ARGS] | |
49 | toot() { | |
50 | source ~/src/toot/venv/bin/activate | |
51 | if [[ $1 == -* ]]; then | |
52 | account=${1#-} | |
53 | shift | |
54 | command toot activate --quiet $account || { deactivate; return 1; } | |
55 | fi | |
56 | command toot "$@" || { deactivate; return 1; } | |
57 | deactivate | |
58 | } | |
59 | ||
60 | ||
61 | # post to mastodon + twitter + gnu social post + diaspora | |
62 | # | |
9c8eb6e7 | 63 | # usage: pdt [--dbd] [-m MEDIA_FILE] [-v VIDEO_PATH] [POST] |
c0e2704f IK |
64 | pdt() { |
65 | if [[ $pdttest ]]; then | |
66 | rbow_account=iank | |
67 | gs_account=fsfes | |
68 | mastodon_account=iank@hostux.social | |
69 | else | |
70 | rbow_account=fsf | |
71 | gs_account=fsf | |
72 | mastodon_account=fsf@hostux.social | |
73 | fi | |
74 | dbd=false | |
9c8eb6e7 | 75 | video=false |
c0e2704f IK |
76 | while [[ $1 == -* ]]; do |
77 | case $1 in | |
78 | -m) | |
79 | media="$2" | |
80 | shift 2 | |
c0e2704f IK |
81 | rbow_arg=" --i $media" |
82 | toot_arg="--media $media" | |
83 | dia_arg="-p $media " | |
84 | gs_arg="-F media=@$media" | |
85 | ;; | |
86 | --dbd) | |
87 | dbd=true | |
88 | rbow_account=dbd | |
89 | gs_account=dbd | |
90 | mastodon_account=endDRM@hostux.social | |
91 | shift | |
92 | ;; | |
9c8eb6e7 IK |
93 | -v) |
94 | video=true | |
95 | media="$2" | |
96 | shift 2 | |
97 | ;; | |
c0e2704f IK |
98 | esac |
99 | done | |
9c8eb6e7 IK |
100 | if [[ $media ]]; then |
101 | if [[ ! -e $media ]]; then | |
102 | echo "error: file not found $media" | |
103 | return 1 | |
104 | fi | |
105 | if [[ $media == *\ * ]]; then | |
106 | echo "error: file path contains a space. move it to non-space path" | |
107 | return 1 | |
108 | fi | |
109 | fi | |
c0e2704f IK |
110 | # if we have no argument |
111 | if (( ! $# )); then | |
112 | read -r -p "input PDT text: " input | |
113 | set -- "$input" | |
114 | fi | |
115 | if [[ $- == *i* ]]; then | |
116 | echo "About to PDT the following line. Press enter to confirm or ctrl-c to quit:" | |
117 | echo "$input" | |
118 | read | |
119 | fi | |
9c8eb6e7 IK |
120 | if $video; then |
121 | local oath | |
122 | oath=$HOME/.rainbow_oauth | |
123 | account=fsf | |
124 | if $dbd; then | |
125 | account=dbd | |
126 | fi | |
127 | rm -f $oath | |
128 | ln -s ${oath}-$account $oath | |
129 | python3 ~/src/async-upload.py "$media" "$*" | |
130 | return | |
131 | fi | |
c0e2704f IK |
132 | fails=() |
133 | if ! rbow -$rbow_account t "$*" $rbow_arg; then | |
134 | fails+=(tweet) | |
135 | fi | |
136 | if ! toot -$mastodon_account post "$*" $toot_arg; then | |
137 | fails+=(toot) | |
138 | fi | |
c5176a05 | 139 | if ! $dbd; then |
c0e2704f IK |
140 | if ! printf "post %s\n" "${dia_arg}$*" | diaspora; then |
141 | fails+=(diaspora) | |
142 | fi | |
143 | fi | |
144 | # https://gnusocial.net/doc/twitterapi | |
145 | if ! curl -o /dev/null -sS -u "$gs_account:$(cat ~/.gnusocial_login-$gs_account)" \ | |
146 | $gs_arg -F "status=$*" https://status.fsf.org/api/statuses/update.xml; then | |
147 | fails+=(gnu-social) | |
148 | fi | |
149 | if (( ${#fails[@]} )); then | |
150 | printf "$(tput setaf 5)█$(tput sgr0)%.0s" $(eval echo "{1..${COLUMNS:-60}}"); echo | |
151 | echo "FSF ERROR: ${fails[*]} might not have posted" >&2 | |
152 | fi | |
153 | } | |
154 | ||
155 | pdt-setup() { | |
156 | ||
157 | if [[ $pdttest ]]; then | |
158 | mastodon_accounts=(iank) | |
159 | else | |
160 | mastodon_accounts=(fsf endDRM) | |
161 | fi | |
162 | ||
163 | mkdir -p ~/src | |
164 | cd ~/src | |
9c8eb6e7 | 165 | for repo in errhandle rainbowstream diaspy jan-pona-mute video-tweet; do |
c0e2704f IK |
166 | if [[ -e $repo ]]; then |
167 | cd $repo | |
168 | git fetch | |
169 | git reset --hard origin/master | |
170 | git clean -xfffd | |
171 | cd .. | |
172 | else | |
173 | git clone https://vcs.fsf.org/git/$repo.git | |
174 | fi | |
175 | done | |
176 | source ~/src/errhandle/err | |
177 | cp ~/src/rainbowstream/rainbowstream/colorset/config ~/.rainbow_config.json | |
178 | ||
179 | if [[ ! -e ~/.local/bin/pip ]]; then | |
180 | tmp=$(mktemp) | |
181 | wget -O$tmp https://bootstrap.pypa.io/get-pip.py | |
182 | python3 $tmp --user | |
183 | hash -r | |
184 | fi | |
185 | ||
186 | ||
187 | if [[ ! -e ~/.local/bin/virtualenv ]]; then | |
188 | python3 -m pip install --user virtualenv | |
189 | fi | |
190 | ||
191 | cd ~/src/rainbowstream | |
192 | python3 -m virtualenv -p python3 venv | |
193 | source venv/bin/activate | |
194 | python3 -m pip install -r requirements.txt | |
195 | python3 -m pip install -e . | |
196 | deactivate | |
197 | ||
198 | ||
199 | # This repo's upstream is https://alexschroeder.ch/cgit/diaspy which is | |
200 | # recommended in the install instructions here: | |
201 | # https://alexschroeder.ch/cgit/jan-pona-mute/about/ | |
202 | cd ~/src/diaspy | |
203 | python3 -m virtualenv -p python3 venv | |
204 | source venv/bin/activate | |
205 | python3 -m pip install -r requirements.txt | |
206 | python3 -m pip install -e . | |
207 | deactivate | |
208 | ||
209 | rm -rf ~/src/toot | |
210 | mkdir -p ~/src/toot | |
211 | cd ~/src/toot | |
212 | python3 -m virtualenv -p python3 venv | |
213 | source venv/bin/activate | |
214 | # pip freeze after a pip install. | |
215 | cat >requirements.txt <<'EOF' | |
216 | beautifulsoup4==4.8.2 | |
217 | certifi==2019.11.28 | |
218 | chardet==3.0.4 | |
219 | idna==2.8 | |
220 | requests==2.22.0 | |
221 | soupsieve==1.9.5 | |
222 | toot==0.25.2 | |
223 | urllib3==1.25.8 | |
224 | urwid==2.1.0 | |
225 | wcwidth==0.1.8 | |
226 | EOF | |
227 | python3 -m pip install -r requirements.txt | |
228 | deactivate | |
229 | ||
230 | ||
231 | if [[ ! -s ~/.config/jan-pona-mute/login ]]; then | |
232 | mkdir ~/.config/jan-pona-mute | |
233 | account=fsf@framasphere.org | |
234 | read -r -p "enter the password for $account > " pass | |
235 | # background: format for this found using the save command | |
236 | cat >~/.config/jan-pona-mute/login <<EOF | |
237 | account $account | |
238 | password $pass | |
239 | login | |
240 | EOF | |
241 | fi | |
242 | ||
243 | for account in dbd fsf; do | |
244 | if [[ ! -s ~/.rainbow_oauth-$account ]]; then | |
245 | printf "$(tput setaf 5)█$(tput sgr0)%.0s" $(eval echo "{1..${COLUMNS:-60}}"); | |
246 | echo "Please login to $account on twitter in your main browser then press enter. After rainbowstream prompt loads, quit with command q" | |
247 | read -r | |
248 | rbow -$account | |
249 | fi | |
250 | if [[ ! -s ~/.gnusocial_login-$account ]]; then | |
251 | printf "$(tput setaf 5)█$(tput sgr0)%.0s" $(eval echo "{1..${COLUMNS:-60}}"); | |
252 | read -r -p "please enter the password for $account@status.fsf.org > " pass | |
253 | touch ~/.gnusocial_login-$account | |
254 | chmod 600 ~/.gnusocial_login-$account | |
255 | printf "%s\n" "$pass" > ~/.gnusocial_login-$account | |
256 | fi | |
257 | done | |
258 | ||
259 | for account in ${mastodon_accounts[@]}; do | |
260 | if ! toot activate $account@hostux.social &>/dev/null; then | |
261 | printf "$(tput setaf 5)█$(tput sgr0)%.0s" $(eval echo "{1..${COLUMNS:-60}}"); | |
262 | echo "Please login to $account on https://hostux.social in your main browser then press enter." | |
263 | read -r | |
264 | toot login -i hostux.social | |
265 | fi | |
266 | done | |
267 | err-allow | |
268 | } |