telelog/install

75 lines
1.8 KiB
Plaintext
Raw Normal View History

2021-11-28 00:34:40 +01:00
#!/bin/sh
2022-01-02 04:23:43 +01:00
# Preliminary sanity checks
[ $(id -u) != 0 ] && echo "Please run this installer as root." && exit 1
[ $0 != ./install ] && echo "Not launched from repository root." && exit 1
2021-11-28 00:34:40 +01:00
# Functions
mkconfig(){
echo "Please get your credentials from https://my.telegram.org."
2021-12-06 04:45:57 +01:00
echo "See readme.md for more info."
2021-11-28 00:34:40 +01:00
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-12-06 04:45:57 +01:00
2021-11-28 00:34:40 +01:00
echo "api_id = $api_id" >> config.py
echo "api_hash = '$api_hash'" >> config.py
echo "myid = $myid" >> config.py
}
2022-01-02 04:23:43 +01:00
mkuser(){
# Create user account, distro mess awaits here...
# Debian has both useradd and adduser
if [ -e /sbin/useradd ]
then
useradd -r telelog
return 0
fi
# Alpine only has adduser (Busybox)
if [ -e /sbin/adduser ]
then
adduser -S telelog
addgroup -S telelog
2022-01-02 04:23:43 +01:00
return 0
fi
}
addfiles(){
# Install executable and config
install -dm770 -o root -g telelog /var/telelog
install -m640 -o root -g telelog config.py /var/telelog/config.py
2022-01-02 04:23:43 +01:00
install -m755 -o root -g root bin/telelog /usr/bin/telelog
2021-11-28 00:34:40 +01:00
2022-01-02 04:23:43 +01:00
# Install service files on installed inits
if [ -e /sbin/openrc ]
then
install -m755 init/openrc /etc/init.d/telelog
ln -s /sbin/openrc /etc/periodic/15min/openrc
rc-update add telelog default
elif [ -e /lib/systemd/systemd ]
then
install -m644 init/systemd /etc/systemd/system/telelog.service
systemctl enable telelog
fi
}
# Install dependencies
[ $(which apt) ] && apt install python3-pip
[ $(which apk) ] && apk add py3-pip
pip3 install -U telethon
# Generate config if not built yet
2021-11-28 00:34:40 +01:00
[ ! -f config.py ] && mkconfig
2022-01-02 04:23:43 +01:00
# Create a new user
mkuser
# Install files if config is (now) present
[ -f config.py ] && addfiles
# Run Telethon for the first time
umask 0077
2022-01-02 04:29:08 +01:00
[ -f setup.py ] && su bot -s /usr/bin/python3 $PWD/setup
2022-01-02 04:23:43 +01:00
# Start the service
service telelog start
2021-11-28 00:34:40 +01:00
return 0