#!/bin/sh # Preliminary sanity checks [ $(id -u) = 0 ] && echo "Please do not run as root." && exit 1 [ $0 != ./install ] && echo "Not launched from repository root." && exit 1 # Functions mkconfig(){ echo "Please get your credentials from https://my.telegram.org." read -p "App API ID (api_id): " api_id read -p "App API hash (api_hash): " api_hash read -p "Your user ID: " myid read -p "Do you wish to use a log chat? (y/n): " logrpl if [ "$logrpl" = "y" ] then read -p "Log chat ID (logchat): " logchat else logchat="'me'" fi echo "api_id = $api_id" >> config.py echo "api_hash = '$api_hash'" >> config.py echo "myid = $myid" >> config.py echo "logchat = $logchat" >> config.py } addfiles(){ # Create user account, distro mess awaits here... # Debian has both useradd and adduser if [ -e /sbin/useradd ] then sudo useradd -r bot return 0 fi # Alpine only has adduser (Busybox) if [ -e /sbin/adduser ] then sudo adduser -S bot return 0 fi # Install executable and config sudo mkdir /etc/ubot sudo install -o root -g bot -m640 config.py /etc/ubot/config.py sudo install -m755 bin/ubot /usr/bin/ubot # Install service files on installed inits if [ -e /sbin/openrc ] then sudo install -m755 init/openrc /etc/init.d/ubot sudo ln -s /sbin/openrc /etc/periodic/15min/openrc elif [ -e /lib/systemd/systemd ] then sudo install -m644 init/systemd /etc/systemd/system/ubot.service fi } # Install dependencies sudo pip3 install -U telethon # Generate config if not built yet [ ! -f config.py ] && mkconfig # Install files if config is (now) present [ -f config.py ] && addfiles return 0