mirror of
https://github.com/nicolabs/nicobot.git
synced 2025-09-07 05:14:01 +02:00
+ added options to configure signal & jabber conf/data directories
~ moved entrypoint script into the PATH ~ using /var/nicobot as the working directory with default configuration files
This commit is contained in:
parent
1885dfdaa7
commit
18e2d97673
|
@ -163,13 +163,14 @@ Here are the main application files and directories from within the images :
|
||||||
┃ ┗ 📂 .local/
|
┃ ┗ 📂 .local/
|
||||||
┃ ┣ 📂 bin/ - - - - - - - - - - - - - -> shortcuts
|
┃ ┣ 📂 bin/ - - - - - - - - - - - - - -> shortcuts
|
||||||
┃ ┃ ┣ 📜 askbot
|
┃ ┃ ┣ 📜 askbot
|
||||||
|
┃ ┃ ┣ 📜 docker-entrypoint.sh
|
||||||
┃ ┃ ┣ 📜 transbot
|
┃ ┃ ┣ 📜 transbot
|
||||||
┃ ┃ ┗ 📜 ...
|
┃ ┃ ┗ 📜 ...
|
||||||
┃ ┣ 📂 lib/pythonX.X/site-packages/ - -> Python packages (nicobot & dependencies)
|
┃ ┗ 📂 lib/pythonX.X/site-packages/ - -> Python packages (nicobot & dependencies)
|
||||||
┃ ┗ 📂 share/signal-cli/ - - - - - - - -> signal-cli configuration files
|
┗ 📂 var/nicobot/ - - - - - - - - - - - -> Configuration files & data (contains secret stuff !)
|
||||||
┗ 📂 usr/src/app/ - - - - - - - - - - - -> app's working directory, default configuration files, ...
|
|
||||||
┣ 📂 .omemo/ - - - - - - - - - - - - - -> OMEMO keys (XMPP)
|
┣ 📂 .omemo/ - - - - - - - - - - - - - -> OMEMO keys (XMPP)
|
||||||
┣ 📜 docker-entrypoint.sh
|
┣ 📂 .signal-cli/ - - - - - - - - - - -> signal-cli configuration files
|
||||||
|
┣ 📜 config.yml
|
||||||
┣ 📜 i18n.en.yml
|
┣ 📜 i18n.en.yml
|
||||||
┗ 📜 ...
|
┗ 📜 ...
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ RUN python3 -m pip install --no-cache-dir --user .
|
||||||
# - glibc
|
# - glibc
|
||||||
FROM python:3-alpine
|
FROM python:3-alpine
|
||||||
|
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /var/nicobot
|
||||||
|
|
||||||
# Runtime packages requirements
|
# Runtime packages requirements
|
||||||
#
|
#
|
||||||
|
@ -85,6 +85,7 @@ RUN apk add --no-cache libressl-dev bash
|
||||||
|
|
||||||
# Required by slixmpp-omemo plugin
|
# Required by slixmpp-omemo plugin
|
||||||
RUN mkdir -p .omemo
|
RUN mkdir -p .omemo
|
||||||
|
# Signal-cli also creates .signal-cli/
|
||||||
|
|
||||||
# Not used currently (we just copy the /root/.local directory which has everyting thanks to the --user option)
|
# Not used currently (we just copy the /root/.local directory which has everyting thanks to the --user option)
|
||||||
#COPY --from=builder /usr/src/app/wheels ./wheels
|
#COPY --from=builder /usr/src/app/wheels ./wheels
|
||||||
|
@ -102,5 +103,6 @@ COPY --from=builder /root/.local /root/.local/
|
||||||
# - also adds extra command line options for Signal device linking
|
# - also adds extra command line options for Signal device linking
|
||||||
# Otherwise the ENTRYPOINT would simply be [ "python"]
|
# Otherwise the ENTRYPOINT would simply be [ "python"]
|
||||||
# Also copying some default configuration files
|
# Also copying some default configuration files
|
||||||
COPY docker/docker-entrypoint.sh docker/default-conf/* .
|
COPY docker/docker-entrypoint.sh /root/.local/bin/
|
||||||
ENTRYPOINT [ "./docker-entrypoint.sh" ]
|
COPY docker/default-conf/* .
|
||||||
|
ENTRYPOINT [ "docker-entrypoint.sh" ]
|
||||||
|
|
|
@ -57,10 +57,11 @@ RUN python3 -m pip install --no-cache-dir --user .
|
||||||
# - glibc
|
# - glibc
|
||||||
FROM python:3-slim
|
FROM python:3-slim
|
||||||
|
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /var/nicobot
|
||||||
|
|
||||||
# Required by slixmpp-omemo plugin
|
# Required by slixmpp-omemo plugin
|
||||||
RUN mkdir -p .omemo
|
RUN mkdir -p .omemo
|
||||||
|
# Signal-cli also creates .signal-cli/
|
||||||
|
|
||||||
# Not used currently (we just copy the /root/.local directory which has everyting thanks to the --user option)
|
# Not used currently (we just copy the /root/.local directory which has everyting thanks to the --user option)
|
||||||
#COPY --from=builder /usr/src/app/wheels ./wheels
|
#COPY --from=builder /usr/src/app/wheels ./wheels
|
||||||
|
@ -78,5 +79,6 @@ COPY --from=builder /root/.local /root/.local/
|
||||||
# - also adds extra command line options for Signal device linking
|
# - also adds extra command line options for Signal device linking
|
||||||
# Otherwise the ENTRYPOINT would simply be [ "python"]
|
# Otherwise the ENTRYPOINT would simply be [ "python"]
|
||||||
# Also copying some default configuration files
|
# Also copying some default configuration files
|
||||||
COPY docker/docker-entrypoint.sh docker/default-conf/* .
|
COPY docker/docker-entrypoint.sh /root/.local/bin/
|
||||||
ENTRYPOINT [ "./docker-entrypoint.sh" ]
|
COPY docker/default-conf/* .
|
||||||
|
ENTRYPOINT [ "docker-entrypoint.sh" ]
|
||||||
|
|
|
@ -34,6 +34,9 @@ EOF
|
||||||
opt_signal_register=
|
opt_signal_register=
|
||||||
opt_qrcode_options=
|
opt_qrcode_options=
|
||||||
opt_bot=
|
opt_bot=
|
||||||
|
SIGNALCLI_CONFIG_DIR=/var/nicobot/.signal-cli
|
||||||
|
JABBER_CONFIG_DIR=/var/nicobot/.omemo
|
||||||
|
|
||||||
|
|
||||||
# Parses the command line for options to execute before running the bot
|
# Parses the command line for options to execute before running the bot
|
||||||
# TODO Enhance CLI handling with getopt
|
# TODO Enhance CLI handling with getopt
|
||||||
|
@ -70,7 +73,8 @@ fi
|
||||||
case "${opt_bot}" in
|
case "${opt_bot}" in
|
||||||
askbot|transbot)
|
askbot|transbot)
|
||||||
#exec python3 -m "nicobot.${opt_bot}" "$@"
|
#exec python3 -m "nicobot.${opt_bot}" "$@"
|
||||||
exec "${opt_bot}" "$@"
|
# TODO Allow to override config dirs with the docker command line
|
||||||
|
exec "${opt_bot}" "--signal-config-dir" ${SIGNALCLI_CONFIG_DIR} "--jabber-config-dir" ${JABBER_CONFIG_DIR} "$@"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Unknown bot : '*{opt_bot}'" >2
|
echo "Unknown bot : '*{opt_bot}'" >2
|
||||||
|
|
|
@ -121,12 +121,15 @@ class ArgsHelper:
|
||||||
recipients = args.jabber_recipients + args.recipients
|
recipients = args.jabber_recipients + args.recipients
|
||||||
if len(recipients)==0:
|
if len(recipients)==0:
|
||||||
raise ValueError("Missing --jabber-recipient")
|
raise ValueError("Missing --jabber-recipient")
|
||||||
|
data_dir = args.jabber_config_dir
|
||||||
|
if not data_dir:
|
||||||
|
data_dir = os.path.join(args.config_dir,".omemo")
|
||||||
# TODO allow multiple recipients
|
# TODO allow multiple recipients
|
||||||
return JabberChatter(
|
return JabberChatter(
|
||||||
jid=username,
|
jid=username,
|
||||||
password=args.jabber_password,
|
password=args.jabber_password,
|
||||||
recipient=recipients[0],
|
recipient=recipients[0],
|
||||||
data_dir=os.path.join(args.config_dir,".omemo")
|
data_dir=data_dir
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -143,13 +146,17 @@ class ArgsHelper:
|
||||||
recipients = args.signal_recipients + args.recipients
|
recipients = args.signal_recipients + args.recipients
|
||||||
if len(recipients)==0 and not args.signal_group:
|
if len(recipients)==0 and not args.signal_group:
|
||||||
raise ValueError("Either --signal-recipient or --signal-group must be provided")
|
raise ValueError("Either --signal-recipient or --signal-group must be provided")
|
||||||
|
config_dir = args.signal_config_dir
|
||||||
|
if not config_dir:
|
||||||
|
config_dir = os.path.join(args.config_dir,".signal-cli")
|
||||||
# TODO allow multiple recipients
|
# TODO allow multiple recipients
|
||||||
return SignalChatter(
|
return SignalChatter(
|
||||||
username=username,
|
username=username,
|
||||||
recipient=recipients[0],
|
recipient=recipients[0],
|
||||||
group=args.signal_group,
|
group=args.signal_group,
|
||||||
signal_cli=args.signal_cli,
|
signal_cli=args.signal_cli,
|
||||||
stealth=args.signal_stealth
|
stealth=args.signal_stealth,
|
||||||
|
config_dir=config_dir
|
||||||
)
|
)
|
||||||
# TODO :timeout=args.timeout
|
# TODO :timeout=args.timeout
|
||||||
|
|
||||||
|
|
|
@ -338,5 +338,6 @@ def arg_parser():
|
||||||
parser.add_argument('--jabber-username', '--jabberid', '--jid', dest='jabber_username', help="Username when using the Jabber/XMPP backend (overrides --username)")
|
parser.add_argument('--jabber-username', '--jabberid', '--jid', dest='jabber_username', help="Username when using the Jabber/XMPP backend (overrides --username)")
|
||||||
parser.add_argument('--jabber-recipient', dest='jabber_recipients', action='append', default=[], help="Recipient when using the Jabber/XMPP backend (overrides --recipient)")
|
parser.add_argument('--jabber-recipient', dest='jabber_recipients', action='append', default=[], help="Recipient when using the Jabber/XMPP backend (overrides --recipient)")
|
||||||
parser.add_argument('--jabber-password', dest='jabber_password', help="Senders's password")
|
parser.add_argument('--jabber-password', dest='jabber_password', help="Senders's password")
|
||||||
|
parser.add_argument('--jabber-config-dir', dest='jabber_config_dir', default=None, help='Directory where to store OMEMO keys')
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
|
@ -30,7 +30,7 @@ class SignalChatter(Chatter):
|
||||||
A signal bot relying on signal-cli
|
A signal bot relying on signal-cli
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__( self, username, recipient=None, group=None, signal_cli=shutil.which("signal-cli"), stealth=False, send_timeout=SEND_TIMEOUT, receive_timeout=RECEIVE_TIMEOUT ):
|
def __init__( self, username, recipient=None, group=None, signal_cli=shutil.which("signal-cli"), stealth=False, send_timeout=SEND_TIMEOUT, receive_timeout=RECEIVE_TIMEOUT, config_dir=None ):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
stealth: if True, will connect and listen to messages but instead of sending answers, will print them
|
stealth: if True, will connect and listen to messages but instead of sending answers, will print them
|
||||||
|
@ -47,6 +47,7 @@ class SignalChatter(Chatter):
|
||||||
self.recipient = recipient
|
self.recipient = recipient
|
||||||
self.group = group
|
self.group = group
|
||||||
self.signal_cli = signal_cli
|
self.signal_cli = signal_cli
|
||||||
|
self.config_dir = config_dir
|
||||||
self.stealth = stealth
|
self.stealth = stealth
|
||||||
if self.stealth:
|
if self.stealth:
|
||||||
logging.debug("Stealth mode : will not send message")
|
logging.debug("Stealth mode : will not send message")
|
||||||
|
@ -75,6 +76,8 @@ class SignalChatter(Chatter):
|
||||||
def send( self, message ):
|
def send( self, message ):
|
||||||
|
|
||||||
cmd = [ self.signal_cli, "-u", self.username, "send", "-m", message ]
|
cmd = [ self.signal_cli, "-u", self.username, "send", "-m", message ]
|
||||||
|
if self.config_dir:
|
||||||
|
cmd = cmd + [ "--config", self.config_dir ]
|
||||||
if self.recipient:
|
if self.recipient:
|
||||||
cmd = cmd + [ self.recipient ]
|
cmd = cmd + [ self.recipient ]
|
||||||
elif self.group:
|
elif self.group:
|
||||||
|
@ -109,6 +112,8 @@ class SignalChatter(Chatter):
|
||||||
timeout = self.receive_timeout
|
timeout = self.receive_timeout
|
||||||
|
|
||||||
cmd = [ self.signal_cli, "-u", self.username, "receive", "--json" ]
|
cmd = [ self.signal_cli, "-u", self.username, "receive", "--json" ]
|
||||||
|
if self.config_dir:
|
||||||
|
cmd = cmd + [ "--config", self.config_dir ]
|
||||||
if timeout:
|
if timeout:
|
||||||
cmd = cmd + [ "-t", str(timeout) ]
|
cmd = cmd + [ "-t", str(timeout) ]
|
||||||
|
|
||||||
|
@ -191,5 +196,6 @@ class ArgsHelper:
|
||||||
parser.add_argument('--signal-group', dest='signal_group', help="Group's ID (for Signal : a base64 string (e.g. 'mPC9JNVoKDGz0YeZMsbL1Q==')")
|
parser.add_argument('--signal-group', dest='signal_group', help="Group's ID (for Signal : a base64 string (e.g. 'mPC9JNVoKDGz0YeZMsbL1Q==')")
|
||||||
parser.add_argument('--signal-recipient', dest='signal_recipients', action='append', default=[], help="Recipient when using the Signal backend (overrides --recipient)")
|
parser.add_argument('--signal-recipient', dest='signal_recipients', action='append', default=[], help="Recipient when using the Signal backend (overrides --recipient)")
|
||||||
parser.add_argument('--signal-stealth', dest='signal_stealth', action="store_true", default=self.signal_stealth, help="Activate Signal chatter's specific stealth mode")
|
parser.add_argument('--signal-stealth', dest='signal_stealth', action="store_true", default=self.signal_stealth, help="Activate Signal chatter's specific stealth mode")
|
||||||
|
parser.add_argument('--signal-config-dir', dest='signal_config_dir', default=None, help="Directory where to store Signal configuration and sensitive data")
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
Loading…
Reference in a new issue