Files
shell_sequencer/seqs/matrix-commander.sh

135 lines
3.8 KiB
Bash
Executable File

#!/bin/bash
readonly toolName=matrix-commander
readonly toolCloneUrl='https://github.com/8go/matrix-commander.git'
readonly toolDeps="python3-pip python3-venv libolm-dev"
toolCredentialDir=
toolEncStoreDir=
sq_aptOpt=
seq_config() {
## or to use sequencer api with global config file:
if ! initSeqConfig "${seq_configName:?}" "${seq_configTemplate:?}" ; then
# End if no configuration file exists
dry || return -1
fi
toolCredentialDir="$MACO_BASE_DIR/.config/matrix-commander"
toolEncStoreDir="$MACO_BASE_DIR/.local/share/matrix-commander"
## Apt cmdline option to suppress user interaction
quiet && sq_aptOpt="-y"
## Return of non zero value will abort the sequence
return 0
}
step_1_info() { echo "Run $toolName"; }
step_1_alias() { echo "run"; }
step_1() {
shift
exe "$MACO_BASE_DIR/bin/python3" "$MACO_DIR/matrix_commander/matrix_commander.py" "$@"
}
step_3_info() {
echo "Send message"
echoinfo "Each string ([MESSAGE]) is send as separate message"
}
step_3_options() { echo "[MESSAGE] [MESSAGE] ..."; }
step_3_alias() { echo "message"; }
step_3() {
shift
step run -m "$@"
}
step_50_info() { echo "Install $toolName dependencies"; }
step_50_alias() { echo "install"; }
step_50() {
apt install $toolDeps $sq_aptOpt
}
step_51_info() { echo "Add system user ${MACO_USER:-}"; }
step_51() {
id $MACO_USER >/dev/null 2>&1
[ $? -eq 0 ] && endReturn -o 1 "User $MACO_USER already exists"
exe adduser --system $MACO_USER --group --home "${MACO_BASE_DIR}" --no-create-home
}
step_52_info() { echo "Create venv and install $toolName"; }
step_52() {
[ -e "$MACO_BASE_DIR" ] && endReturn -o 1 "$toolName already installed"
exe python3 -m venv "$MACO_BASE_DIR"
endReturn "Creating virtual environment failed"
exe git clone $toolCloneUrl "$MACO_DIR"
exe chown -R $MACO_USER: "$MACO_BASE_DIR"
exe sudo -u $MACO_USER ${MACO_BASE_DIR}/bin/pip install --upgrade pip
}
step_53_info() { echo "Install python requirements"; }
step_53() {
cat <<NOTES_END
# Remove following packages for headless servers
dbus-python
notify2
NOTES_END
exe read -p "Enter to continue..."
exe editor "$MACO_DIR/requirements.txt"
exe sudo -u $MACO_USER ${MACO_BASE_DIR}/bin/pip install -r ${MACO_DIR}/requirements.txt
}
step_55_info() {
echo "Create systemd service for $toolName"
echoinfo "(Make sure to modify the service content in the step configuration)"
}
step_55_alias() { echo "service"; }
step_55() {
local macommanderServiceLoc="/etc/systemd/system/matrix-commander.service"
addConf -s "$MACO_SERVICE" "$macommanderServiceLoc"
exe systemctl daemon-reload
}
step_57_info() { echo "First run to create credential file and encryption store"; }
step_57_alias() { echo "firstrun"; }
step_57() {
exe sudo -u "$MACO_USER" mkdir -p "$toolCredentialDir" "$toolEncStoreDir"
exe cd "$toolCredentialDir"
step run
[ -e ./store ] && exe mv store "$toolEncStoreDir"
info "use \"$SEQ_NAME run --verify\" to verify against an existing session (like Element)"
}
step_60_alias() { echo "notes"; }
step_60() {
color green
cat <<NOTES_EOF
# Verify matrix-commander "device"
For emoji verification to work, the matrix-commander user needs to be at least in one room.
Enter the room on Element and goto
* Room Info -> People -> select matrix commander user -> Security -> sessions -> matrix-commander session
* verify with emojis
## Credential information location
matrix-commander expects the following files to be in place for the user to be able to
send/receive messages
credentials.json - $MACO_BASE_DIR/.config/matrix-commander/credentials.json
store - $MACO_BASE_DIR/.local/share/matrix-commander/store
NOTES_EOF
}
# shellcheck disable=SC2034 # Appears unused
readonly sqr_minVersion=16
# shellcheck disable=SC1091 # Don't follow this source
. /usr/local/bin/sequencer.sh