aboutsummarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorbobpaul2020-02-16 22:58:50 -0600
committerbobpaul2020-02-16 22:58:50 -0600
commit016495dfb3b448bc40445f23845b5ec867c6518c (patch)
tree26355468f9f2243198093397be52e8d508b4edc8
downloadaur-016495dfb3b448bc40445f23845b5ec867c6518c.tar.gz
Initial commit
-rw-r--r--.SRCINFO27
-rw-r--r--PKGBUILD68
-rw-r--r--README41
-rw-r--r--config-paths.patch35
-rw-r--r--hangups_manual_login.py16
-rw-r--r--matrix-puppet-hangouts@.service18
-rw-r--r--setup.sh55
7 files changed, 260 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO
new file mode 100644
index 000000000000..b80f142e294c
--- /dev/null
+++ b/.SRCINFO
@@ -0,0 +1,27 @@
+pkgbase = matrix-puppet-hangouts-git
+ pkgdesc = Single user Node.js Hangouts bridge for Matrix
+ pkgver = r57.b055642
+ pkgrel = 1
+ arch = any
+ license = Apache
+ makedepends = npm
+ makedepends = git
+ depends = nodejs
+ depends = hangups-git
+ optdepends = python: for maintenance scripts
+ conflicts = matrix-puppet-hangouts
+ source = matrix-puppet-hangouts::git+https://github.com/matrix-hacks/matrix-puppet-hangouts
+ source = README
+ source = setup.sh
+ source = config-paths.patch
+ source = hangups_manual_login.py
+ source = matrix-puppet-hangouts@.service
+ sha256sums = SKIP
+ sha256sums = 69aaa542079a8fa4a4ac73a0598acef5d2991a24b657af987c13014ee96e21e0
+ sha256sums = d59a393341a1b4a9843cb61374ddad42ed9d2790acb7903f8dd1619c73b81515
+ sha256sums = 7e17b23c7f23558e1cdee0bd3e3c0820c91ac1f05a2b7ce7edcbc750413aa371
+ sha256sums = 39ef6f75eed3c743bafc3974e83a8916446120985a5e2b39f9c6aa70abfbe585
+ sha256sums = e80f54718c308237eeae039326c69e6b599c6578db3ed72ab7b79d2f8e1c38d6
+
+pkgname = matrix-puppet-hangouts-git
+
diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644
index 000000000000..5f7f3572f8c1
--- /dev/null
+++ b/PKGBUILD
@@ -0,0 +1,68 @@
+# Maintainer: bobpaul
+
+_pkgbase=matrix-puppet-hangouts
+pkgname=${_pkgbase}-git
+pkgver=r57.b055642
+pkgrel=1
+pkgdesc="Single user Node.js Hangouts bridge for Matrix"
+arch=(any)
+conflicts=(matrix-puppet-hangouts)
+license=(Apache)
+depends=(nodejs hangups-git)
+makedepends=(npm git)
+optdepends=('python: for maintenance scripts')
+source=("${_pkgbase}::git+https://github.com/matrix-hacks/${_pkgbase}"
+ "README"
+ "setup.sh"
+ "config-paths.patch"
+ "hangups_manual_login.py"
+ "${_pkgbase}@.service")
+sha256sums=('SKIP'
+ '69aaa542079a8fa4a4ac73a0598acef5d2991a24b657af987c13014ee96e21e0'
+ 'd59a393341a1b4a9843cb61374ddad42ed9d2790acb7903f8dd1619c73b81515'
+ '7e17b23c7f23558e1cdee0bd3e3c0820c91ac1f05a2b7ce7edcbc750413aa371'
+ '39ef6f75eed3c743bafc3974e83a8916446120985a5e2b39f9c6aa70abfbe585'
+ 'e80f54718c308237eeae039326c69e6b599c6578db3ed72ab7b79d2f8e1c38d6')
+
+pkgver() {
+ cd "$srcdir/${_pkgbase}"
+ printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
+}
+
+prepare() {
+ cd "$srcdir/${_pkgbase}"
+ git reset --hard
+ patch < ../config-paths.patch
+}
+
+build() {
+ cd "$srcdir/${_pkgbase}"
+ npm install
+}
+
+package() {
+ cd "$srcdir/${_pkgbase}"
+ npm install --cache ./npm-cache -g --user root --prefix "${pkgdir}"/usr
+
+ # Apparently it now symlinks to the source folder…
+ rm -f "${pkgdir}"/usr/lib/node_modules/${_pkgbase}
+ mkdir -p "${pkgdir}"/usr/lib/node_modules/${_pkgbase}
+ cp -r * "${pkgdir}"/usr/lib/node_modules/${_pkgbase}/
+ chmod -R go-w "${pkgdir}"/usr/lib/
+ chown -R root:root "${pkgdir}"/usr
+ mkdir -p "${pkgdir}"/var/lib/${_pkgbase}/
+ # touch "${pkgdir}"/var/lib/${_pkgbase}/.pkg
+ chmod -R go-w "${pkgdir}"/var/lib/
+ chown -R root:root "${pkgdir}"/var
+ chown -R synapse:synapse "${pkgdir}"/var/lib/${_pkgbase}
+
+ #TODO: make synapse user and chown these files so we aren't dependent on synapse package
+ mkdir -p "${pkgdir}"/etc/synapse/"${_pkgbase}"/
+ install -Dm644 config.sample.json -t "${pkgdir}"/etc/synapse/"${_pkgbase}"/
+
+ cd "$srcdir/"
+ install -Dm644 hangups_manual_login.py -t "${pkgdir}"/usr/lib/node_modules/${_pkgbase}/
+ install -Dm644 README -t "${pkgdir}"/etc/synapse/"${_pkgbase}"/
+ install -Dm644 setup.sh -t "${pkgdir}"/etc/synapse/"${_pkgbase}"/
+ install -Dm644 ${_pkgbase}@.service -t "${pkgdir}"/usr/lib/systemd/system/
+}
diff --git a/README b/README
new file mode 100644
index 000000000000..67d44a41e22f
--- /dev/null
+++ b/README
@@ -0,0 +1,41 @@
+To facilitate running multiple bridges, a systemd template service has been provided.
+
+The template started as matrix-puppet-hangouts@FOO expects to find the following files:
+ /etc/synapse/matrix-puppet-hangouts/
+ config-FOO.yaml
+ registration-FOO.yaml
+ refresh_token-FOO.txt
+ /var/lib/matrix-puppet-hangouts/
+ room-store-FOO.db
+ user-store-FOO.db
+
+Unfortunately, matrix-puppet-hangouts has hard-coded paths, so there's currently
+a lot of symlinks and a fake home folder (gross). A setup.sh script helps create
+the expected structure and perform the registration
+
+Another problem is the login procedure for hangups is currently rather unfriendly.
+
+Quick Setup (assuming bridge and synapse are on the same computer):
+0. Change to the config directory
+ cd /etc/synapse/matrix-puppet-hangouts/
+1. Run setup.sh [user] to make a bunch of folders and symlinks. Ex:
+ ./setup.sh FOO
+2. Edit the config json to suite your needs.
+3. Login to hangups
+ sudo -u synapse hangups --token-path refresh_token-FOO.txt --manual
+ follow the onscreen instructions. after pasting your token, an ncurses hangouts client will show; press Ctrl+C to exit
+ See https://github.com/tdryer/hangups/issues/350#issuecomment-323553771 for more details.
+4. Generate the registration file. Ex:
+ ./setup.sh FOO --register http://localhost:8090
+5. Include the registration-*.yaml file in your synapse config
+ # homeserver.yaml
+ app_service_config_files:
+ - /etc/synapse/matrix-puppet-hangouts/registration-FOO.yaml
+6. Restart the home server and start the appservice. Ex:
+ systemctl start matrix-puppet-hangouts@FOO
+ systemctl restart synapse
+
+NOTE: If you run multiple instances, be sure to change the port
+
+For further documentation look to the upstream project:
+https://github.com/matrix-org/matrix-appservice-irc
diff --git a/config-paths.patch b/config-paths.patch
new file mode 100644
index 000000000000..86bf28a4d62c
--- /dev/null
+++ b/config-paths.patch
@@ -0,0 +1,35 @@
+diff --git a/config.sample.json b/config.sample.json
+index 57cb3ce..a4c47d3 100644
+--- a/config.sample.json
++++ b/config.sample.json
+@@ -1,9 +1,9 @@
+ {
+- "registrationPath": "hangouts-registration.yaml",
++ "registrationPath": "/etc/synapse/matrix-puppet-hangouts/registration-FOO.yaml",
+ "port": 8090,
+ "bridge": {
+- "homeserverUrl": "https://your-home-server.example.org",
++ "homeserverUrl": "http://localhost",
+ "domain": "example.org",
+- "registration": "hangouts-registration.yaml"
++ "registration": "/etc/synapse/matrix-puppet-hangouts/registration-FOO.yaml"
+ }
+ }
+diff --git a/index.js b/index.js
+index 141065e..d7b1818 100644
+--- a/index.js
++++ b/index.js
+@@ -5,10 +5,11 @@ const {
+ Puppet,
+ MatrixPuppetBridgeBase
+ } = require("matrix-puppet-bridge");
++const home = require('os').homedir()
+ const HangoutsClient = require('./client');
+-const config = require('./config.json');
++const config = require(home + '/config.json');
+ const path = require('path');
+-const puppet = new Puppet(path.join(__dirname, './config.json' ));
++const puppet = new Puppet(path.join(home, './config.json' ));
+ const debug = require('debug');
+ const debugVerbose = debug('verbose:matrix-puppet:hangouts:index');
+
diff --git a/hangups_manual_login.py b/hangups_manual_login.py
new file mode 100644
index 000000000000..09c93f71ae58
--- /dev/null
+++ b/hangups_manual_login.py
@@ -0,0 +1,16 @@
+import os, hangups, requests, appdirs
+
+print('Open this URL:')
+print(hangups.auth.OAUTH2_LOGIN_URL)
+
+authorization_code = input('Enter oauth_code cookie value: ')
+
+with requests.Session() as session:
+ session.headers = {'user-agent': hangups.auth.USER_AGENT}
+ access_token, refresh_token = hangups.auth._auth_with_code(
+ session, authorization_code
+ )
+
+dirs = appdirs.AppDirs('hangups', 'hangups')
+token_path = os.path.join(dirs.user_cache_dir, 'refresh_token.txt')
+hangups.auth.RefreshTokenCache(token_path).set(refresh_token)
diff --git a/matrix-puppet-hangouts@.service b/matrix-puppet-hangouts@.service
new file mode 100644
index 000000000000..f09ceacf1d1e
--- /dev/null
+++ b/matrix-puppet-hangouts@.service
@@ -0,0 +1,18 @@
+# /usr/lib/systemd/system/matrix-puppet-hangouts@.service
+# /etc/systemd/system/hangouts-puppet.service
+[Unit]
+Description=Hangouts Matrix Puppet
+
+[Service]
+Type=simple
+Environment=DEBUG=verbose:matrix-puppet:*
+Environment=HOME=/var/lib/matrix-puppet-hangouts/%i/
+User=synapse
+Group=synapse
+WorkingDirectory=/var/lib/matrix-puppet-hangouts/%i/
+ExecStart=/usr/bin/node /usr/lib/node_modules/matrix-puppet-hangouts/index.js
+Restart=always
+RestartSec=3
+
+[Install]
+WantedBy=multi-user.target
diff --git a/setup.sh b/setup.sh
new file mode 100644
index 000000000000..2464837841a2
--- /dev/null
+++ b/setup.sh
@@ -0,0 +1,55 @@
+#!/bin/bash
+
+USER=${1:-none}
+REG=${2:-no}
+URL=${3:-http://localhost:8090}
+RUNAS=${RUNAS:-synapse}
+
+if [[ "${USER}" = "none" ]] || [[ "${USER}" = "" ]] || [[ "${USER}" = "--register" ]]; then
+ echo 'USER required'
+ echo ''
+ echo 'usage $0 USER [--register [URL]]'
+ echo '--register - generates registation.yaml file. Must edit config json first!!'
+ echo ' URL tells synapse how to reach the puppet daemon.'
+ echo ' defaults to http://localhost:8090'
+ echo ''
+ echo 'Sets up some folders/symlinks to make up for a lack of configurability'
+ echo 'in matrix-puppet-hangouts. After running this script, edit '
+ echo ' /etc/synapse/matrix-puppet-hangouts/config-USER.json'
+ echo 'Log into hangups and place the token in '
+ echo ' /etc/synapse/matrix-puppet-hangouts/refresh_token-USER.txt'
+ echo 'And place registration in'
+ echo ' /etc/synapse/matrix-puppet-hangouts/registration-USER.yaml'
+ echo 'Note that the registration path also goes in config-USER.json'
+ exit 1
+fi
+
+if [[ ${REG} = "--register" ]]; then
+echo "Registering a puppet on ${URL}"
+sudo -u synapse HOME=/var/lib/matrix-puppet-hangouts/${USER}/ \
+ node /usr/lib/node_modules/matrix-puppet-hangouts/index.js -r -u "${URL}"
+else
+
+echo Running initial setup
+#Real conf files should be in /etc
+#Real databases in /var/lib
+#Goofy fake home folder in /var/lib, but only containing simlinks
+sudo -u ${RUNAS} mkdir -p /var/lib/matrix-puppet-hangouts/${USER}/.cache/hangups/
+sudo touch /etc/synapse/matrix-puppet-hangouts/registration-${USER}.yaml
+sudo chown ${RUNAS}:${RUNAS} /etc/synapse/matrix-puppet-hangouts/registration-${USER}.yaml
+sudo ln -s /etc/synapse/matrix-puppet-hangouts/refresh_token-${USER}.txt /var/lib/matrix-puppet-hangouts/${USER}/.cache/hangups/refresh_token.txt
+sudo ln -s /etc/synapse/matrix-puppet-hangouts/config-${USER}.json /var/lib/matrix-puppet-hangouts/${USER}/config.json
+if [[ ! -e /etc/synapse/matrix-puppet-hangouts/config-${USER}.json ]]; then
+ sudo cp /etc/synapse/matrix-puppet-hangouts/config{.sample,-${USER}}.json
+fi
+sudo touch /etc/synapse/matrix-puppet-hangouts/refresh_token-${USER}.txt
+sudo chown ${RUNAS}:${RUNAS} /etc/synapse/matrix-puppet-hangouts/{config-${USER}.json,refresh_token-${USER}.txt}
+sudo -u ${RUNAS} chmod 600 /etc/synapse/matrix-puppet-hangouts/refresh_token-${USER}.txt
+
+sudo -u ${RUNAS} touch /var/lib/matrix-puppet-hangouts/{user,room}-store-${USER}.db
+sudo -u ${RUNAS} chmod 600 /var/lib/matrix-puppet-hangouts/{user,room}-store-${USER}.db
+sudo ln -s /var/lib/matrix-puppet-hangouts/room-store-${USER}.db /var/lib/matrix-puppet-hangouts/${USER}/room-store.db
+sudo ln -s /var/lib/matrix-puppet-hangouts/user-store-${USER}.db /var/lib/matrix-puppet-hangouts/${USER}/user-store.db
+sudo ln -s /usr/lib/node_modules/matrix-puppet-hangouts/hangups_client.py /var/lib/matrix-puppet-hangouts/${USER}/
+echo 'Now edit the config json file, then run setup with --register'
+fi