From cc210a0da0f94d323dba6aa12a74ff6a869f73b0 Mon Sep 17 00:00:00 2001 From: Sebastian Hugentobler Date: Tue, 27 Nov 2018 13:12:34 +0100 Subject: [PATCH] initial commit --- .drone.yml | 14 ++++ .editorconfig | 9 +++ .gitignore | 3 + Dockerfile | 27 +++++++ README.md | 23 ++++++ rootfs/etc/confd/conf.d/config.yaml.toml | 6 ++ rootfs/etc/confd/templates/config.yaml.tmpl | 84 +++++++++++++++++++++ rootfs/etc/fix-attrs.d/01-bridge | 2 + rootfs/etc/services.d/whatsapp-bridge/run | 3 + 9 files changed, 171 insertions(+) create mode 100644 .drone.yml create mode 100644 .editorconfig create mode 100755 .gitignore create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 rootfs/etc/confd/conf.d/config.yaml.toml create mode 100644 rootfs/etc/confd/templates/config.yaml.tmpl create mode 100644 rootfs/etc/fix-attrs.d/01-bridge create mode 100644 rootfs/etc/services.d/whatsapp-bridge/run diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..c3f7962 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,14 @@ +pipeline: + docker: + image: plugins/docker + repo: thallian/matrix-appservice-whatsapp + autotag: true + secrets: [ docker_username, docker_password ] + tags: + - ${DRONE_COMMIT_SHA} + - ${DRONE_COMMIT_BRANCH} + - latest + notify: + image: plugins/matrix + secrets: [ matrix_username, matrix_password, matrix_homeserver, matrix_roomid ] + diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..d741e40 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 4 diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..af0faab --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*~ +.DS_Store +*.swp diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c942820 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +FROM golang:alpine as builder + +RUN apk --no-cache add \ + git \ + gcc \ + musl-dev + +RUN go get maunium.net/go/mautrix-whatsapp + +FROM thallian/confd-env:latest + +RUN addgroup -g 2222 matrix-bridge +RUN adduser -h /var/lib/matrix-bridge -u 2222 -D -G matrix-bridge matrix-bridge + +COPY --from=builder /go/bin/mautrix-whatsapp /bin/mautrix-whatsapp + +WORKDIR /var/lib/matrix-bridge + +RUN mkdir /var/lib/matrix-bridge/data + +ADD /rootfs / + +RUN chown -R matrix-bridge:matrix-bridge /var/lib/matrix-bridge +ENV HOME /var/lib/matrix-bridge + +EXPOSE 9005 + diff --git a/README.md b/README.md new file mode 100644 index 0000000..805ae74 --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +[whatsapp bridge](https://github.com/tulir/mautrix-whatsapp) for the [matrix](http://matrix.org/) network. + +# Volumes +- `/var/lib/matrix-bridge/data` + +# Environment Variables +## SERVER_DOMAIN +Domain of the synapse server. + +## SERVER_URL +Full url to the synapse server. + +## AS_TOKEN +Appservice token (from the generated registration) + +## HS_TOKEN +Homeserver token (from the generated registration) + +## ADMIN_USER +Matrix id of the admin user. + +# Ports +- 8080 diff --git a/rootfs/etc/confd/conf.d/config.yaml.toml b/rootfs/etc/confd/conf.d/config.yaml.toml new file mode 100644 index 0000000..214f61d --- /dev/null +++ b/rootfs/etc/confd/conf.d/config.yaml.toml @@ -0,0 +1,6 @@ +[template] +src = "config.yaml.tmpl" +dest = "/var/lib/matrix-bridge/config.yaml" +uid = 2222 +gid = 2222 +mode = "0640" diff --git a/rootfs/etc/confd/templates/config.yaml.tmpl b/rootfs/etc/confd/templates/config.yaml.tmpl new file mode 100644 index 0000000..7bb5083 --- /dev/null +++ b/rootfs/etc/confd/templates/config.yaml.tmpl @@ -0,0 +1,84 @@ +# Homeserver details. +homeserver: + # The address that this appservice can use to connect to the homeserver. + address: "{{ getenv "SERVER_URL" }}" + # The domain of the homeserver (for MXIDs, etc). + domain: "{{ getenv "SERVER_DOMAIN" }}" + +# Application service host/registration related details. +# Changing these values requires regeneration of the registration. +appservice: + # The address that the homeserver can use to connect to this appservice. + address: http://{{getenv "HOSTNAME"}}:8080 + + # The hostname and port where this appservice should listen. + hostname: 0.0.0.0 + port: 8080 + + # Database config. + database: + # The database type. Only "sqlite3" is supported. + type: sqlite3 + # The database URI. Usually file name. https://github.com/mattn/go-sqlite3#connection-string + uri: /var/lib/matrix-bridge/data/mautrix-whatsapp.db + # Path to the Matrix room state store. + state_store_path: /var/lib/matrix-bridge/data/mx-state.json + + # The unique ID of this appservice. + id: whatsapp + # Appservice bot details. + bot: + # Username of the appservice bot. + username: _whatsapp_bot + # Display name and avatar for bot. Set to "remove" to remove display name/avatar, leave empty + # to leave display name/avatar as-is. + displayname: WhatsApp Bridge Bot + avatar: mxc://maunium.net/NeXNQarUbrlYBiPCpprYsRqr + + # Authentication tokens for AS <-> HS communication. Autogenerated; do not modify. + as_token: "" + hs_token: "" + +# Bridge config. Currently unused. +bridge: + # Localpart template of MXIDs for WhatsApp users. + # {{.}} is replaced with the phone number of the WhatsApp user. + username_template: whatsapp_{{.}} + # Displayname template for WhatsApp users. + # {{.Notify}} - nickname set by the WhatsApp user + # {{.Jid}} - phone number (international format) + # The following variables are also available, but will cause problems on multi-user instances: + # {{.Name}} - display name from contact list + # {{.Short}} - short display name from contact list + displayname_template: "{{if .Notify}}{{.Notify}}{{else}}{{.Jid}}{{end}} (WA)" + + # The prefix for commands. Only required in non-management rooms. + command_prefix: "!wa" + + # Permissions for using the bridge. + # Permitted values: + # user - Access to use the bridge to chat with a WhatsApp account. + # admin - User level and some additional administration tools + # Permitted keys: + # * - All Matrix users + # domain - All users on that homeserver + # mxid - Specific user + permissions: + "{{ getenv "SERVER_DOMAIN" }}": user + "{{ getenv "ADMIN_USER" }}": admin + +# Logging config. +logging: + # The directory for log files. Will be created if not found. + directory: /var/lib/matrix-bridge/logs + # Available variables: .Date for the file date and .Index for different log files on the same day. + file_name_format: "{{.Date}}-{{.Index}}.log" + # Date format for file names in the Go time format: https://golang.org/pkg/time/#pkg-constants + file_date_format: 2006-01-02 + # Log file permissions. + file_mode: 0600 + # Timestamp format for log entries in the Go time format. + timestamp_format: Jan _2, 2006 15:04:05 + # Minimum severity for log messages. + # Options: debug, info, warn, error, fatal + print_level: info diff --git a/rootfs/etc/fix-attrs.d/01-bridge b/rootfs/etc/fix-attrs.d/01-bridge new file mode 100644 index 0000000..39e31e9 --- /dev/null +++ b/rootfs/etc/fix-attrs.d/01-bridge @@ -0,0 +1,2 @@ +/var/lib/matrix-bridge/data/ true matrix-bridge 0640 0750 + diff --git a/rootfs/etc/services.d/whatsapp-bridge/run b/rootfs/etc/services.d/whatsapp-bridge/run new file mode 100644 index 0000000..9811fc0 --- /dev/null +++ b/rootfs/etc/services.d/whatsapp-bridge/run @@ -0,0 +1,3 @@ +#!/usr/bin/with-contenv sh + +s6-setuidgid matrix-bridge mautrix-whatsapp -c /var/lib/matrix-bridge/config.yaml