rename to tclip

Signed-off-by: Xe Iaso <xe@tailscale.com>
This commit is contained in:
Xe Iaso 2023-01-16 19:14:45 +00:00
parent 6719a8ae16
commit b4ff6aa03f
7 changed files with 130 additions and 130 deletions

View file

@ -1,4 +1,4 @@
# infinipaste
# tclip
[![status: experimental](https://img.shields.io/badge/status-experimental-blue)](https://tailscale.com/kb/1167/release-stages/#experimental)
@ -11,8 +11,8 @@ number of pastes.
2. Enable flakes
3. `nix develop`
You can then test your changes to infinipaste by running `go run
./cmd/web` or `go run ./cmd/infinipaste` as appropriate.
You can then test your changes to tclip by running `go run
./cmd/web` or `go run ./cmd/tclip` as appropriate.
## Building for prod
@ -34,7 +34,7 @@ nix build .#portable-service
## Deploying
There are several options you can take to deploy infinipaste. The most
There are several options you can take to deploy tclip. The most
basic deployment method is to use [fly.io](https://fly.io), but we
offer a few options so that you can make the decision that is right
for you.
@ -44,7 +44,7 @@ for you.
In order to deploy this service, you will need to get an authkey from
[the admin panel](https://login.tailscale.com/admin/settings/keys). It
is a good idea to associate this with the tag `tag:service` or its own
`tag:infinipaste`. Please also do not set the `ephemeral` tag as that
`tag:tclip`. Please also do not set the `ephemeral` tag as that
will destroy the node when the service shuts down.
Your authkey should start with `tskey-auth`.
@ -56,7 +56,7 @@ You will need to have
### fly.io
In one of your infrastructure management GitHub repositories, create a
folder for infinipaste and then copy the following
folder for tclip and then copy the following
[`fly.toml`](https://fly.io/docs/reference/configuration/) template
into that folder.
@ -64,7 +64,7 @@ into that folder.
app = "FLY_APP_NAME"
[build]
image = "ghcr.io/tailscale-dev/infinipaste:main"
image = "ghcr.io/tailscale-dev/tclip:main"
[deploy]
strategy = "immediate"
@ -73,16 +73,16 @@ strategy = "immediate"
DATA_DIR = "/data"
[mounts]
source = "infinipaste_data"
source = "tclip_data"
destination = "/data"
```
Replace `FLY_APP_NAME` with a name such as `yourorg-infinipaste` and
Replace `FLY_APP_NAME` with a name such as `yourorg-tclip` and
then run these commands with [the `flyctl` command](https://fly.io/docs/hands-on/install-flyctl/):
```console
$ flyctl apps create FLY_APP_NAME
$ flyctl volumes create infinipaste_data
$ flyctl volumes create tclip_data
$ flyctl secrets set TS_AUTHKEY=<key>
$ flyctl deploy
```
@ -97,36 +97,36 @@ To run this service in Docker, run the following command:
```
docker run \
-d \
-v /var/lib/infinipaste:/data \
-v /var/lib/tclip:/data \
-e DATA_DIR=/data \
-e TS_AUTHKEY=<key> \
-n infinipaste \
-n tclip \
--restart always \
ghcr.io/tailscale-dev/infinipaste:main
ghcr.io/tailscale-dev/tclip:main
```
Every so often you should pull a new version of infinipaste and
Every so often you should pull a new version of tclip and
recreate the container:
```
docker pull ghcr.io/tailscale-dev/infinipaste:main
docker rm -f infinipaste
docker pull ghcr.io/tailscale-dev/tclip:main
docker rm -f tclip
```
Then run the above command to recreate the container.
#### Backups
Add the path `/var/lib/infinipaste` to your backup program of choice.
Add the path `/var/lib/tclip` to your backup program of choice.
### Systemd portable service
systemd has a mechanism for [portable
service](https://systemd.io/PORTABLE_SERVICES/) which are like Docker
images mixed with systemd unit configurations. This allows you to
install infinipaste on any Linux distribution with systemd (and the
install tclip on any Linux distribution with systemd (and the
`portablectl` command, install `systemd-container` to get this package
on Ubuntu). This lets you view infinipaste logs with `journalctl` and
on Ubuntu). This lets you view tclip logs with `journalctl` and
manage it like any other systemd service.
Download the portable service image yada yada TODO(Xe) fix this
@ -141,31 +141,31 @@ services:
```console
$ portablectl list
NAME TYPE RO CRTIME MTIME USAGE STATE
infinipaste_0.1.0-20230116 raw yes Mon 2023-01-16 16:49:58 UTC Mon 2023-01-16 16:53:59 UTC 14.8M detached
tclip_0.1.0-20230116 raw yes Mon 2023-01-16 16:49:58 UTC Mon 2023-01-16 16:53:59 UTC 14.8M detached
```
Copy the name of the `infinipaste` service including the
Copy the name of the `tclip` service including the
auto-generated version number to your clipboard (for example:
`infinipaste_0.1.0-20230116`) and pass that to `portablectl attach`:
`tclip_0.1.0-20230116`) and pass that to `portablectl attach`:
```console
$ sudo portablectl attach infinipaste_0.1.0-20230116
$ sudo portablectl attach tclip_0.1.0-20230116
```
Next, create the folder `/etc/systemd/system/infinipaste.service.d`
Next, create the folder `/etc/systemd/system/tclip.service.d`
and create the file `10-ts-auth-key.conf` in it with the following contents:
```systemd
# /etc/systemd/system/infinipaste.service.d/10-ts-auth-key.conf
# /etc/systemd/system/tclip.service.d/10-ts-auth-key.conf
[Service]
Environment=TS_AUTH_KEY=<key>
```
Finally, enable `infinipaste.service` and start it with `systemctl
Finally, enable `tclip.service` and start it with `systemctl
enable --now`:
```console
$ sudo systemctl enable --now infinipaste.service
$ sudo systemctl enable --now tclip.service
```
Wait a moment for it to connect to Tailscale and then check on it with
@ -174,5 +174,5 @@ tailnet.
#### Backups
Add the path `/var/lib/private/infinipaste` to your backup program of
Add the path `/var/lib/private/tclip` to your backup program of
choice.

View file

@ -9,7 +9,7 @@
<body id="top">
<main>
<nav>
<a href="/">Infinipaste</a>{{if .UserInfo}} - <a href="/paste/list">List</a> - <a href="/help">Help</a>{{end}}
<a href="/">tclip</a>{{if .UserInfo}} - <a href="/paste/list">List</a> - <a href="/help">Help</a>{{end}}
{{if .UserInfo}}<div class="right">{{.UserInfo.DisplayName}} <img style="width:32px;height:32px" src="{{.UserInfo.ProfilePicURL}}" /></div>{{end}}
</nav>

View file

@ -13,17 +13,17 @@
<h2 id="cli">Command-line tool</h2>
<p>You can pipe commands or paste files to the pastebin using the command <code>infinipaste</code>. You can install it by installing the <a href="https://go.dev">Go</a> compiler toolkit and then running this command:</p>
<p>You can pipe commands or paste files to the pastebin using the command <code>tclip</code>. You can install it by installing the <a href="https://go.dev">Go</a> compiler toolkit and then running this command:</p>
<pre><code>go get github.com/tailscale-dev/infinipaste/cmd/infinipaste@main</code></pre>
<pre><code>go get github.com/tailscale-dev/tclip/cmd/tclip@main</code></pre>
<p>Once it is installed, invoke it with the command <code>infinipaste</code>:</p>
<p>Once it is installed, invoke it with the command <code>tclip</code>:</p>
<pre><code>infinipaste ./foo.txt</code></pre>
<pre><code>tclip ./foo.txt</code></pre>
<p>and the program will print a URL that you can share with your team. You can also pipe the output from any command to it:</p>
<pre><code>go test &amp;2&lt;1 | infinipaste -n go-test.txt</code></pre>
<pre><code>go test &amp;2&lt;1 | tclip -n go-test.txt</code></pre>
<h2 id="api">API</h2>
@ -52,13 +52,13 @@
<h3 id="emacs">Emacs package</h3>
<p>The default distribution of infinipaste ships with a package for <a href="https://www.gnu.org/software/emacs/">GNU Emacs</a>. This package will let you submit pastes from your editor. It requires the <a href="https://github.com/tkf/emacs-request"><code>request</code></a> package and exposes two interactive functions:</p>
<p>The default distribution of tclip ships with a package for <a href="https://www.gnu.org/software/emacs/">GNU Emacs</a>. This package will let you submit pastes from your editor. It requires the <a href="https://github.com/tkf/emacs-request"><code>request</code></a> package and exposes two interactive functions:</p>
<ul>
<li><code>M-x infinipaste-submit-region</code> - submits the currently highlighted region to infinipaste</li>
<li><code>M-x infinipaste-submit-buffer</code> - submits the contents of the current buffer to infinipaste</li>
<li><code>M-x tclip-submit-region</code> - submits the currently highlighted region to tclip</li>
<li><code>M-x tclip-submit-buffer</code> - submits the contents of the current buffer to tclip</li>
</ul>
<p>You can download this package <a href="https://github.com/tailscale-dev/infinipaste/blob/main/contrib/infinipaste.el">from the infinipaste repository</a>. You can install it by using <code>M-x package-install-file</code> or by opening it in Emacs and running <code>M-x package-install-from-buffer</code>. Please be sure that <code>request</code> is installed.</p>
<p>You can download this package <a href="https://github.com/tailscale-dev/tclip/blob/main/contrib/tclip.el">from the tclip repository</a>. You can install it by using <code>M-x package-install-file</code> or by opening it in Emacs and running <code>M-x package-install-from-buffer</code>. Please be sure that <code>request</code> is installed.</p>
{{template "footer" .}}

View file

@ -1,81 +0,0 @@
;;; infinipaste.el --- infinipaste client for Emacs -*- lexical-binding: t; -*-
;; Copyright (C)
;; 2023 Tailscale, Inc.
;; Author: Xe Iaso <xe@tailscale.com>
;; Maintainer: Xe Iaso <xe@tailscale.com>
;; Created: 2023-01-13
;; Version: 0.1
;; Keywords: tailscale, pastebin, sharing
;; Homepage: https://github.com/tailscale-dev/infinipaste
;;; Commentary:
;;
;; This uses request-el to make requests to your tailnet's infinipaste server. You
;; can install request-el with M-x package-install.
;;
;; This package requires that you have a infinipaste server set up. This package
;; reaches out to a infinipaste server over either plain HTTP, or HTTPS should you
;; configure the variable `infinipaste-server'.
;;
;; Usage:
;;
;; To submit the contents of the current buffer to infinipaste:
;; M-x infinipaste-submit-buffer
;; To submit the contents of the currently highlighted region to infinipaste:
;; M-x infinipaste-submit-region
;;
;; Customization:
;;
;; To customize the infinipaste server this package reaches out to:
;; M-x customize-group infinipaste
;;
;; You can customize the infinipaste server URL by changing the value of `infinipaste-server':
;; (setq infinipaste-server "https://paste.shark-harmonic.ts.net")
;;; Code:
(require 'request)
(defgroup infinipaste nil
"Infinipaste server configuration."
:prefix "infinipaste-"
:group 'infinipaste)
(defcustom infinipaste-server "http://paste"
"The server that is running infinipaste or a service with a compatible API to infinipaste. This should NOT end with a trailing slash."
:group 'infinipaste
:type 'string)
(defun infinipaste--send-paste (fname content)
"Internal function that actually fires off the paste with name FNAME and content CONTENT to the infinipaste server."
(request (format "%s/api/post" infinipaste-server)
:type "POST"
:data `(("filename" . ,fname)
("content" . ,content))
:headers '(("Accept" . "text/plain"))
:timeout 60
:success (cl-function
(lambda (&key response &allow-other-keys)
(message "%s" (request-response-data response))))))
(defun infinipaste-submit-buffer ()
"Submits the entire current buffer to infinipaste."
(interactive)
(let ((fname (format "%s.%s"
(file-name-base (buffer-file-name))
(file-name-extension (buffer-file-name))))
(content (buffer-string)))
(infinipaste--send-paste fname content)))
(defun infinipaste-submit-region ()
"Submits the highlighted region to infinipaste."
(interactive)
(let ((fname (format "%s.%s"
(file-name-base (buffer-file-name))
(file-name-extension (buffer-file-name))))
(content (buffer-substring-no-properties (region-beginning) (region-end))))
(infinipaste--send-paste fname content)))
(provide 'infinipaste)
;;; infinipaste.el ends here

81
contrib/tclip.el Normal file
View file

@ -0,0 +1,81 @@
;;; tclip.el --- tclip client for Emacs -*- lexical-binding: t; -*-
;; Copyright (C)
;; 2023 Tailscale, Inc.
;; Author: Xe Iaso <xe@tailscale.com>
;; Maintainer: Xe Iaso <xe@tailscale.com>
;; Created: 2023-01-13
;; Version: 0.1
;; Keywords: tailscale, pastebin, sharing
;; Homepage: https://github.com/tailscale-dev/tclip
;;; Commentary:
;;
;; This uses request-el to make requests to your tailnet's tclip server. You
;; can install request-el with M-x package-install.
;;
;; This package requires that you have a tclip server set up. This package
;; reaches out to a tclip server over either plain HTTP, or HTTPS should you
;; configure the variable `tclip-server'.
;;
;; Usage:
;;
;; To submit the contents of the current buffer to tclip:
;; M-x tclip-submit-buffer
;; To submit the contents of the currently highlighted region to tclip:
;; M-x tclip-submit-region
;;
;; Customization:
;;
;; To customize the tclip server this package reaches out to:
;; M-x customize-group tclip
;;
;; You can customize the tclip server URL by changing the value of `tclip-server':
;; (setq tclip-server "https://paste.shark-harmonic.ts.net")
;;; Code:
(require 'request)
(defgroup tclip nil
"Tclip server configuration."
:prefix "tclip-"
:group 'tclip)
(defcustom tclip-server "http://paste"
"The server that is running tclip or a service with a compatible API to tclip. This should NOT end with a trailing slash."
:group 'tclip
:type 'string)
(defun tclip--send-paste (fname content)
"Internal function that actually fires off the paste with name FNAME and content CONTENT to the tclip server."
(request (format "%s/api/post" tclip-server)
:type "POST"
:data `(("filename" . ,fname)
("content" . ,content))
:headers '(("Accept" . "text/plain"))
:timeout 60
:success (cl-function
(lambda (&key response &allow-other-keys)
(message "%s" (request-response-data response))))))
(defun tclip-submit-buffer ()
"Submits the entire current buffer to tclip."
(interactive)
(let ((fname (format "%s.%s"
(file-name-base (buffer-file-name))
(file-name-extension (buffer-file-name))))
(content (buffer-string)))
(tclip--send-paste fname content)))
(defun tclip-submit-region ()
"Submits the highlighted region to tclip."
(interactive)
(let ((fname (format "%s.%s"
(file-name-base (buffer-file-name))
(file-name-extension (buffer-file-name))))
(content (buffer-substring-no-properties (region-beginning) (region-end))))
(tclip--send-paste fname content)))
(provide 'tclip)
;;; tclip.el ends here

View file

@ -28,23 +28,23 @@
in {
packages = rec {
web = pkgs.buildGoApplication {
pname = "infinipaste-web";
pname = "tclip-web";
version = "0.1.0-${version}";
src = ./.;
subPackages = "cmd/web";
modules = ./gomod2nix.toml;
};
infinipaste = pkgs.buildGoApplication {
pname = "infinipaste";
tclip = pkgs.buildGoApplication {
pname = "tclip";
inherit (web) src version modules;
subPackages = "cmd/infinipaste";
subPackages = "cmd/tclip";
CGO_ENABLED = "0";
};
docker = pkgs.dockerTools.buildLayeredImage {
name = "ghcr.io/tailscale-dev/infinipaste";
name = "ghcr.io/tailscale-dev/tclip";
tag = "main";
config.Cmd = [ "${web}/bin/web" ];
contents = [ pkgs.cacert ];
@ -52,15 +52,15 @@
portable-service = let
web-service = pkgs.substituteAll {
name = "infinipaste.service";
src = ./run/portable-service/infinipaste.service.in;
name = "tclip.service";
src = ./run/portable-service/tclip.service.in;
inherit web;
};
in pkgs.portableService {
inherit (web) version;
pname = "infinipaste";
description = "The infinipaste service";
homepage = "https://github.com/tailscale-dev/infinipaste";
pname = "tclip";
description = "The tclip service";
homepage = "https://github.com/tailscale-dev/tclip";
units = [ web-service ];
symlinks = [{
object = "${pkgs.cacert}/etc/ssl";

2
go.mod
View file

@ -1,4 +1,4 @@
module github.com/tailscale-dev/infinipaste
module github.com/tailscale-dev/tclip
go 1.19