#!/bin/bash if [ $# -lt 1 ]; then echo "usage: pairing [socketname]" echo "starts up a tmux session available for the specified user." echo "if socketname is specified, uses a custom socket name." echo "else, it will generate a random name" exit 1 fi id $1 USEREXISTS=$? if [ $USEREXISTS -eq 1 ]; then echo "user does not exist" exit 1 fi if [ ! -d "/tmp/pairs" ]; then # Shouldn't need to run unless tilde.town rebooted mkdir /tmp/pairs chmod 0777 /tmp/pairs fi if [ $# -lt 2 ]; then # I know, useless use of cat but it's nicer to read RANDOMSTR=$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 8) PAIR="/tmp/pairs/$RANDOMSTR" else PAIR="/tmp/pairs/$(basename $2)" # Checkmate, ../ usage fi if [ -d $PAIR ]; then echo "specified pair already exists, or rng gave a duplicate :o" exit 1 fi echo "starting session" tmux -S $PAIR new-session -d echo "granting $1 access to the socket" setfacl -m u:$1:rw $PAIR echo "Success!" echo "Please terminate the session once you're done to minimize socket usage." echo "Attach using:" echo "tmux -S $PAIR attach" echo "You may now send this command to $1."