ubot/install

77 lines
1.9 KiB
Plaintext
Raw Permalink Normal View History

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
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
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 15:22:35 +01:00
mkuser(){
2021-12-30 14:29:00 +01:00
# 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
2021-12-30 15:22:35 +01:00
}
2021-12-30 14:29:00 +01:00
2021-12-30 15:22:35 +01:00
addfiles(){
2021-12-30 14:29:00 +01:00
# Install executable and config
2022-01-01 23:25:26 +01:00
install -dm770 -o root -g bot /var/ubot
2022-01-01 22:40:27 +01:00
install -m640 -o root -g bot config.py /var/ubot/config.py
install -m755 -o root -g root 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
2022-01-01 23:25:26 +01:00
[ $(which apt) ] && apt install python3-pip
[ $(which apk) ] && apk add py3-pip
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 15:22:35 +01:00
# Create a new user
mkuser
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
2022-01-01 23:25:26 +01:00
# Run Telethon for the first time
echo "Please log in to Telegram now."
echo "Afterwards you can hit Ctrl-C and start the ubot service."
umask 0077
su bot -s /usr/bin/ubot
2021-03-26 21:51:02 +01:00
return 0