diff --git a/man/man1/send-patch.1 b/man/man1/send-patch.1 deleted file mode 100644 index c3d665f..0000000 --- a/man/man1/send-patch.1 +++ /dev/null @@ -1,57 +0,0 @@ -.Dd $Mdocdate: April 29 2023 $ -.Dt SEND-PATCH 1 -.Os Telodendria Project -.Sh NAME -.Nm send-patch -.Nd Submit a patch file to the Telodendria Patches Matrix room -.Sh SYNOPSIS -.Nm -.Op patch -.Sh DESCRIPTION -.Nm -is a simple shell script for submitting patch files to Telodendria's patch -room for review. -.Pp -.Nm -takes a single argument, a patch file. It also reads a number of environment -variables, as described in the following section. This script is designed to be -simple; it only pushes files into a hard-coded Matrix room. Thus, as far as -Matrix clients go, this one is a rather minimal one, and that is by design. -.Pp -This script exists so that users who are working on a machine that doesn't have -a Matrix client installed can still submit work to the Telodendria project. The -goal is to make development as accessible as possible. -.Pp -This script only supports password login, so if your homeserver does not -support password login, it will not work. -.Sh ENVIRONMENT -.Pp -.Nm -utilizes the following environment variables: -.Bl -tag -width Ds -.It Ev MXID -Your Matrix ID in the standard format. This is used to connect to your -homeserver to send the message. -.It Ev MXPW -Your Matrix account's password. If not set, you will be prompted for your -password by the script, unless -.Ev ACCESS_TOKEN -is set. -.It Ev ACCESS_TOKEN -If you already have an access token for your account, such as one from an -existing session, then you can set this environment variable to bypass the -password authentication flow. -.El -.Sh FILES -.Pp -.Nm -does utilize the -.Pa .env -file, just like -.Xr td 1 . -Consult that page for the specifics of the -.Pa .env -file. -.Sh SEE ALSO -.Xr td 1 - diff --git a/man/man1/tp.1 b/man/man1/tp.1 deleted file mode 100644 index f2dea09..0000000 --- a/man/man1/tp.1 +++ /dev/null @@ -1,63 +0,0 @@ -.Dd $Mdocdate: April 29 2023 $ -.Dt TP 1 -.Os Telodendria Project -.Sh NAME -.Nm tp -.Nd Manage the official patch queue. -.Sh SYNOPSIS -.Np -.Op action -.Op patch -.Sh DESCRIPTION -.Pp -This script is probably not going to be very useful for anyone other -than the official project managers, but for completeness, this page -documents it. -.Pp -.Nm -is a simple script that is used to manage the patch queue. It offers a -simple way to fetch patches from the patch Matrix room and queue them -in a patch directory, which is then updated as patches are handled. -Contributions to Telodendria are entirely patch-based, so this script -makes dealing with patch files much more convenient. -.Pp -.Nm -doesn't implement a complex command line interface. It simply takes an -action as the first argument, and a patch file ID as the second -argument to some actions. The actions are as follows: -.Bl -tag -width Ds -.It ingress -Download all new patches from the patches room. This action is intended -to be called periodically from -.Xr cron 8 -to fetch new patches. -.It queue -List all the patches in the queue, printing the first three lines of -each one so they can be easily identified. -.It view -View the specified patch. Note that the specified patch must be in -the queue. Once it is applied or rejected, this script offers no -facility for viewing it. -.It apply -Apply the specified patch to the current working directory. -.It reverse -Reverse the specified patch on the current working directory. -.It accept|reject -Accept or reject the specified patch by moving it to the appropriate -directory. These actions also prompt for a message, into which it is -expected that an explanation for why the patch was accepted or rejected -will be placed. -.El -.Sh ENVIRONMENT -.Pp -The following environment variables are read by the -.Nm -script: -.Bl -tag -width Ds -.It Ev TELODENDRIA_PUB -The base directory inside which the patch directory relies. -.It Ev HOMESERVER -The Matrix homeserver to contact for receiving patches. -.It Ev ACCESS_TOKEN -The access token to use to authenticate with the Matrix homeserver. -.El diff --git a/tools/bin/send-patch b/tools/bin/send-patch deleted file mode 100755 index ca4d416..0000000 --- a/tools/bin/send-patch +++ /dev/null @@ -1,167 +0,0 @@ -#!/usr/bin/env sh -# -# send-patch: "The Telodendria Patch Sender" -# -# This is a simple script for posting patch files to -# a single room(generally the Telodendria patch room.) - -. "$(pwd)/tools/lib/common.sh" - -# Path to the patch to send. -PATCHFILE="$1" - -# Tries to decompose the name and the HS from an MXID using -# sed. -UR_NAME="$(echo "$MXID" | sed "s/\@\(.*\)\:\(.*\)/\1/")" -HS_NAME="$(echo "$MXID" | sed "s/\@\(.*\)\:\(.*\)/\2/")" - -# Prompts the user for a password, while disabling echo-ing. -readpwd() { - printf "$1" - stty -echo -ctlecho - read -r "$2" - echo - stty echo ctlecho -} - -# Makes an HTTP request, setting the RETURN variable for the -# actual reply from the server and the ERROR_CODE variable -# for a HTTP error code. -request() { - RETURN=$(http -i "$@" 2>/dev/null) - ERROR_CODE=$(echo "$RETURN" | head -n1 | awk '{print $2}') - RETURN=$(echo "$RETURN" | sed '1,/^[[:space:]]*$/d') -} - -# Prompts user to login and gives out an access token to use -# in the ACCESS_TOKEN variable -matrix_login() { - # Check authentication methods - echo "Checking authentication methods..." - request "$HS_BASE/_matrix/client/v3/login" - AUTH_METHODS=$RETURN - if [ $ERROR_CODE -ne 200 ]; then - echo "Homeserver does not support login." - exit 1 - fi - if ! echo "$AUTH_METHODS" | grep "m.login.password" >/dev/null; then - echo "Homeserver does not support password authentication." - exit 1 - fi - # Homeserver does support password authentication, so request - # them one. - if [ -z "$MXPW" ]; then - readpwd "Enter your Matrix password: " MXPW - fi - # Tries to login using the "Telodendria Patch Script" device - # name - JSON=$( - printf '{' - printf ' "identifier": {' - printf ' "type": "m.id.user",' - printf ' "user": %s' "$(json -e $UR_NAME)" - printf ' },' - printf ' "initial_device_display_name": "Telodendria Patch Script",' - printf ' "type": "m.login.password",' - printf ' "password": %s' "$(json -e "$MXPW")" - printf '}' - ) - request -X POST -d "$JSON" $HS_BASE/_matrix/client/v3/login - LOGIN="$RETURN" - if [ $ERROR_CODE -ne 200 ]; then - echo "Login failed." - echo "$RETURN" - exit 1 - fi - ACCESS_TOKEN=$(echo "$LOGIN" | json -s "access_token->@decode") -} - -# Logs out of Matrix using the ACFESS_TOKEN environment variable -matrix_logout() { - if [ -z "$ACCESS_TOKEN" ]; then - echo "No access token" - exit 1 - fi - request -X POST -H "Authorization: Bearer $ACCESS_TOKEN" "$HS_BASE/_matrix/client/v3/logout" - LOGOUT=$RETURN - if [ $ERROR_CODE -ne 200 ]; then - echo "Logout failed." - echo "$RETURN" - exit 1 - fi - echo "Logged out." -} - -send_patch() { - if [ -z "$ACCESS_TOKEN" ]; then - matrix_login - DO_LOGOUT=1 - fi - # We are sucessfully logged in as our user, now let's - # try to upload and post our patch - echo "$PATCHFILE" - request -X POST \ - -H "Content-Type: text/x-patch" \ - -H "Authorization: Bearer $ACCESS_TOKEN" \ - -d "@$PATCHFILE" \ - "$HS_BASE/_matrix/media/v3/upload" - MXCID=$RETURN - if [ $ERROR_CODE -ne 200 ]; then - echo "Upload failed." - echo "$RETURN" - matrix_logout - exit 1 - fi - MXCID=$(echo "$MXCID" | json -s "content_uri->@decode") - echo "MXC ID: $MXCID" - JSON=$( - base=$(basename "$PATCHFILE") - printf '{' - printf ' "body": %s,' "$(json -e $base)" - printf ' "filename": %s,' "$(json -e $base)" - printf ' "info": {' - printf ' "mimetype": "text/x-patch",' - printf ' "size": %d' $(wc -c "$PATCHFILE" | awk '{print $1}') - printf ' },' - printf ' "msgtype": "m.file",' - printf ' "url": %s' "$(json -e $MXCID)" - printf '}' - ) - http -X PUT -d "$JSON" -H "Authorization: Bearer $ACCESS_TOKEN" \ - "$HS_BASE/_matrix/client/v3/rooms/$PATCHES_ROOM/send/m.room.message/$(date +%s)" \ - 2>/dev/null >/dev/null && echo "Patch sent." - - # Log out if we generated an access token - if [ "$DO_LOGOUT" -eq "1" ]; then - matrix_logout - fi -} - -# Check if the patch file is valid. -if [ "$(basename "$PATCHFILE" .patch)" = "$PATCHFILE" ] || [ ! -f "$PATCHFILE" ]; then - echo "Format: $0 file.patch" - exit 1 -fi -echo "Sending file '$PATCHFILE'" -echo "Checking homeserver's real address using .well-known..." -request "https://$HS_NAME/.well-known/matrix/client" -case "$ERROR_CODE" in - "200") - WELL_KNOWN=$RETURN - if [ -z "$WELL_KNOWN" ]; then - echo "well-known test returned 200 but no correct input was given." - exit 1 - fi - # well-known entry is correct, we can now store our base endpoint - HS_BASE=$(printf "$WELL_KNOWN" | json -s "m.homeserver->base_url->@decode") && send_patch - ;; - *) - echo "$ERROR_CODE" - - echo "well-known test failed." - printf "Please enter your homeserver base URL: " - read -r HS_BASE - echo - send_patch - ;; -esac diff --git a/tools/bin/tp b/tools/bin/tp deleted file mode 100755 index fad2d87..0000000 --- a/tools/bin/tp +++ /dev/null @@ -1,148 +0,0 @@ -#!/usr/bin/env sh -# -# tp: "Telodendria Patch" -# -# This script is used to manage the patch queue. - -. "$(pwd)/tools/lib/common.sh" - -if [ -z "$TELODENDRIA_PUB" ]; then - echo "TELODENDRIA_PUB not set." - exit 1 -fi - -TP_DIR="$TELODENDRIA_PUB/patches" - -if [ ! -d "$TP_DIR" ]; then - echo "$TP_DIR does not exist." - exit 1 -fi - -matrix_send() { - msg="$1" - if [ ! -z "$msg" ]; then - ( - printf '{' - printf '"body":' - json -e "$msg" - printf ',"formatted_body":' - json -e "$msg" - printf ',"format":"org.matrix.custom.html",' - printf '"msgtype":"m.text"' - printf '}' - ) > /tmp/tp-$$ - http -X PUT -d @/tmp/tp-$$ "$HOMESERVER/client/v3/rooms/$PATCHES_ROOM/send/m.room.message/$(date +%s)?access_token=$ACCESS_TOKEN" - rm /tmp/tp-$$ - fi -} - -case "$1" in - "ingress") - timeline="/tmp/timeline.json" - http "$HOMESERVER/client/v3/sync?access_token=$ACCESS_TOKEN" | - json -s "rooms->join->${PATCHES_ROOM}->timeline" >"$timeline" - - length=$(cat "$timeline" | json -s "events->@length") - - i=0 - while [ $i -lt $length ]; do - content=$(cat "$timeline" | json -s "events[$i]->content->^body->^formatted_body") - i=$((i + 1)) - - type=$(echo "$content" | json -s "msgtype->@decode") - if [ "$type" != "m.file" ]; then - continue - fi - - size=$(echo "$content" | json -s "info->size") - if [ "$size" -gt "$MAX_SIZE" ]; then - continue - fi - - file=$(echo "$content" | json -s "filename->@decode") - ext=$(echo "$file" | rev | cut -d '.' -f 1 | rev) - if [ "$ext" != "patch" ]; then - continue - fi - - url=$(echo "$content" | json -s "url->@decode") - id=$(echo "$url" | cut -d '/' -f 4) - - if [ -f "$TP_DIR/ingress/$id.patch" ]; then - continue - fi - - server=$(echo "$url" | cut -d '/' -f 3) - - if ! http "$HOMESERVER/media/v3/download/$server/$id" > "$TP_DIR/ingress/$id.patch"; then - rm "$TP_DIR/ingress/$id.patch" - echo "Failed to fetch mxc://$server/$id." - echo "Will try again next time." - continue - fi - - count=$(cat "$TP_DIR/count.txt") - count=$((count + 1)) - cp "$TP_DIR/ingress/$id.patch" "$TP_DIR/p/$count.patch" - ( - cd "$TP_DIR/queued" - ln -s "../p/$count.patch" "$count.patch" - ) - - echo "$count" >"$TP_DIR/count.txt" - - matrix_send "Queued $file as #$count" >/dev/null - done - ;; - "queue") - find "$TP_DIR/queued" -name '*.patch' | while IFS= read -r patch; do - n=$(basename "$patch" .patch) - echo "Patch #$n:" - head -n3 "$patch" - echo - done - ;; - "view") - if [ -f "$TP_DIR/queued/$2.patch" ]; then - less "$TP_DIR/queued/$2.patch" - else - echo "Patch #$2 doesn't exist in the queue." - exit 1 - fi - ;; - "apply") - if [ -f "$TP_DIR/queued/$2.patch" ]; then - patch <"$TP_DIR/queued/$2.patch" - else - echo "Patch #$2 doesn't exist in the queue." - exit 1 - fi - ;; - "reverse") - if [ -f "$TP_DIR/queued/$2.patch" ]; then - patch -R <"$TP_DIR/queued/$2.patch" - else - echo "Patch #$2 doesn't exist in the queue." - exit 1 - fi - ;; - "accept" | "reject") - if [ -f "$TP_DIR/queued/$2.patch" ]; then - mv "$TP_DIR/queued/$2.patch" "$TP_DIR/${1}ed/$2.patch" - msg="Patch #$2 was marked as ${1}ed." - msgFile="/tmp/patchmsg-$(date +%s).txt" - $EDITOR "$msgFile" - if [ -f "$msgFile" ]; then - msg="$msg
$(cat $msgFile)
—$DISPLAY_NAME ($MXID)
" - fi - matrix_send "$msg" - else - echo "Patch #$2 doesn't exist in the queue." - exit 1 - fi - ;; - *) - echo "No action specified." - exit 1 - ;; -esac