2 # pdt: post to FSF social media via command line
3 # Copyright (C) 2021 Ian Kelling
4 # SPDX-License-Identifier: AGPL-3.0-or-later
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Affero General Public License for more details.
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 # This is meant to be sourced.
21 PATH
="$HOME/.local/bin:$PATH"
23 # usage: rbow [-PROFILE_NAME] [COMMAND]
25 # Wrapper for rainbowstream to use multiple logins and tweet directly
26 # from the command line. PROFILE_NAME can be anything you want.
29 oath
=$HOME/.rainbow_oauth
30 if [[ $1 == -* ]]; then
35 source ~
/src
/rainbowstream
/venv
/bin
/activate
39 # adds a short delay after each send for more reliable operation
40 set force_conservative 1
43 expect -nocase timeout {exit 1} "@*]: "
44 set cmd [lindex $argv 0];
46 expect -nocase timeout {exit 1} "@*]: "
47 # this may not be needed. didnt test
52 expect
$f "$*" ||
{ echo error
: expect failed
; deactivate
; rm -f $f; return 1; }
60 # usage: toot [-PROFILE_NAME] [TOOT_ARGS]
63 source ~
/src
/toot
/venv
/bin
/activate
64 if [[ $1 == -* ]]; then
67 command toot activate
--quiet $account ||
{ deactivate
; return 1; }
69 command toot
"$@" ||
{ deactivate
; return 1; }
74 # post to mastodon + twitter + gnu social post
76 # If posting video, it only goes to twitter. Other accounts can be
77 # posted to manually with free software.
79 # usage: pdt [--dbd] [-m MEDIA_FILE] [-v VIDEO_PATH] [POST]
81 local video media rbow_account gs_account mastodon_account dbd video rbow_arg toot_arg dia_arg gs_arg
82 if [[ $pdttest ]]; then
85 mastodon_account
=iank@hostux.social
89 mastodon_account
=fsf@hostux.social
93 while [[ $1 == -* ]]; do
98 rbow_arg
=" --i $media"
99 toot_arg
="--media $media"
101 gs_arg
="-F media=@$media"
107 mastodon_account
=endDRM@hostux.social
117 if [[ $media ]]; then
118 if [[ ! -e $media ]]; then
119 echo "error: file not found $media"
122 if [[ $media == *\
* ]]; then
123 echo "error: file path contains a space. move it to non-space path"
127 # if we have no argument
129 read -r -p "input PDT text: " input
132 if [[ $
- == *i
* ]]; then
133 echo "About to PDT the following line. Press enter to confirm or ctrl-c to quit:"
139 oath
=$HOME/.rainbow_oauth
145 ln -s ${oath}-$account $oath
146 python3 ~
/src
/video-tweet
/async-upload.py
"$media" "$*"
150 if ! rbow
-$rbow_account t
"$*" $rbow_arg; then
153 if ! toot
-$mastodon_account post
"$*" $toot_arg; then
156 # https://gnusocial.net/doc/twitterapi
157 if ! curl
-o /dev
/null
-sS -u "$gs_account:$(cat ~/.gnusocial_login-$gs_account)" \
158 $gs_arg -F "status=$*" https
://status.fsf.org
/api
/statuses
/update.xml
; then
161 if (( ${#fails[@]} )); then
162 printf "$(tput setaf 5)█$(tput sgr0)%.0s" $
(eval echo "{1..${COLUMNS:-60}}"); echo
163 echo "FSF ERROR: ${fails[*]} might not have posted" >&2
169 if [[ $pdttest ]]; then
170 mastodon_accounts
=(iank
)
172 mastodon_accounts
=(fsf endDRM
)
177 for repo
in errhandle rainbowstream video-tweet
; do
178 if [[ -e $repo ]]; then
181 git
reset --hard origin
/master
185 git clone https
://vcs.fsf.org
/git
/$repo.git
188 source ~
/src
/errhandle
/err
189 cp ~
/src
/rainbowstream
/rainbowstream
/colorset
/config ~
/.rainbow_config.json
191 if [[ ! -e ~
/.local
/bin
/pip
]]; then
193 pyver
=$
(python3
--version |
sed -r 's/.*(3\.[0-9]+).*/\1/')
194 echo fyi
: detected pyver
: $pyver. this should
look something like
3.6
195 # the bootstrap script at https://bootstrap.pypa.io/get-pip.py requires 3.7+
197 wget
-O$tmp https
://bootstrap.pypa.io
/pip
/$pyver/get-pip.py
202 python3
-m pip
install --user -U virtualenv
204 cd ~
/src
/rainbowstream
205 python3
-m virtualenv
-p python3 venv
206 source venv
/bin
/activate
207 python3
-m pip
install -r requirements.txt
208 python3
-m pip
install -e .
215 python3
-m virtualenv
-p python3 venv
216 source venv
/bin
/activate
217 # pip freeze after a pip install.
218 cat >requirements.txt
<<'EOF'
219 beautifulsoup4==4.8.2
230 python3
-m pip
install -r requirements.txt
233 for account
in dbd fsf
; do
234 if [[ ! -s ~
/.rainbow_oauth-
$account ]]; then
235 printf "$(tput setaf 5)█$(tput sgr0)%.0s" $
(eval echo "{1..${COLUMNS:-60}}");
236 echo "Please login to $account on twitter in your main browser then press enter. After rainbowstream prompt loads, quit with command q"
240 if [[ ! -s ~
/.gnusocial_login-
$account ]]; then
241 printf "$(tput setaf 5)█$(tput sgr0)%.0s" $
(eval echo "{1..${COLUMNS:-60}}");
242 read -r -p "please enter the password for $account@status.fsf.org > " pass
243 touch ~
/.gnusocial_login-
$account
244 chmod 600 ~
/.gnusocial_login-
$account
245 printf "%s\n" "$pass" > ~
/.gnusocial_login-
$account
249 for account
in ${mastodon_accounts[@]}; do
250 if ! toot activate
$account@hostux.social
&>/dev
/null
; then
251 printf "$(tput setaf 5)█$(tput sgr0)%.0s" $
(eval echo "{1..${COLUMNS:-60}}");
252 echo "Please login to $account on https://hostux.social in your main browser then press enter."
254 toot login
-i hostux.social
258 echo "pdt-setup complete"