2021-03-26 21:51:02 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
2021-12-30 14:29:00 +01:00
|
|
|
# Preliminary sanity checks
|
2021-12-30 14:34:08 +01:00
|
|
|
[ $(id -u) != 0 ] && echo "Please run this installer as root." && exit 1
|
2021-12-30 14:29:00 +01:00
|
|
|
[ $0 != ./install ] && echo "Not launched from repository root." && exit 1
|
|
|
|
|
2021-03-26 21:51:02 +01:00
|
|
|
# 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
|
2021-04-09 20:57:58 +02:00
|
|
|
read -p "Your user ID: " myid
|
2021-03-28 23:17:31 +02:00
|
|
|
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
|
2021-03-26 21:51:02 +01:00
|
|
|
echo "api_id = $api_id" >> config.py
|
|
|
|
echo "api_hash = '$api_hash'" >> config.py
|
2021-04-09 20:57:58 +02:00
|
|
|
echo "myid = $myid" >> config.py
|
2021-03-28 23:17:31 +02:00
|
|
|
echo "logchat = $logchat" >> config.py
|
2021-03-26 21:51:02 +01:00
|
|
|
}
|
|
|
|
|
2021-12-30 14:29:00 +01:00
|
|
|
addfiles(){
|
|
|
|
# Create user account, distro mess awaits here...
|
|
|
|
# Debian has both useradd and adduser
|
|
|
|
if [ -e /sbin/useradd ]
|
|
|
|
then
|
2021-12-30 14:34:08 +01:00
|
|
|
useradd -r bot
|
2021-12-30 14:29:00 +01:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
# Alpine only has adduser (Busybox)
|
|
|
|
if [ -e /sbin/adduser ]
|
|
|
|
then
|
2021-12-30 14:34:08 +01:00
|
|
|
adduser -S bot
|
2021-12-30 14:29:00 +01:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Install executable and config
|
2021-12-30 14:34:08 +01:00
|
|
|
mkdir /etc/ubot
|
|
|
|
install -o root -g bot -m640 config.py /etc/ubot/config.py
|
|
|
|
install -m755 bin/ubot /usr/bin/ubot
|
2021-12-30 14:29:00 +01:00
|
|
|
|
|
|
|
# Install service files on installed inits
|
|
|
|
if [ -e /sbin/openrc ]
|
|
|
|
then
|
2021-12-30 14:34:08 +01:00
|
|
|
install -m755 init/openrc /etc/init.d/ubot
|
|
|
|
ln -s /sbin/openrc /etc/periodic/15min/openrc
|
2021-12-30 14:29:00 +01:00
|
|
|
elif [ -e /lib/systemd/systemd ]
|
|
|
|
then
|
2021-12-30 14:34:08 +01:00
|
|
|
install -m644 init/systemd /etc/systemd/system/ubot.service
|
2021-12-30 14:29:00 +01:00
|
|
|
fi
|
|
|
|
}
|
2021-03-26 21:51:02 +01:00
|
|
|
|
2021-12-30 14:29:00 +01:00
|
|
|
# Install dependencies
|
2021-12-30 14:34:08 +01:00
|
|
|
pip3 install -U telethon
|
2021-12-30 14:29:00 +01:00
|
|
|
# Generate config if not built yet
|
2021-03-26 23:01:07 +01:00
|
|
|
[ ! -f config.py ] && mkconfig
|
2021-12-30 14:29:00 +01:00
|
|
|
# Install files if config is (now) present
|
|
|
|
[ -f config.py ] && addfiles
|
2021-03-26 21:57:06 +01:00
|
|
|
|
2021-03-26 21:51:02 +01:00
|
|
|
return 0
|