85 lines
2.1 KiB
Bash
Executable File
85 lines
2.1 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# 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
|
|
|
|
# Functions
|
|
mkconfig(){
|
|
echo "Please get your credentials from https://my.telegram.org."
|
|
echo "See readme.md for more info."
|
|
read -p "App API ID (api_id): " api_id
|
|
read -p "App API hash (api_hash): " api_hash
|
|
read -p "Your user ID: " myid
|
|
|
|
echo "api_id = $api_id" >> config.py
|
|
echo "api_hash = '$api_hash'" >> config.py
|
|
echo "myid = $myid" >> config.py
|
|
}
|
|
|
|
mkuser(){
|
|
# Create user account, distro mess awaits here...
|
|
# Debian has both useradd and adduser
|
|
if [ -e /usr/sbin/useradd ]
|
|
then
|
|
useradd -r telelog
|
|
return 0
|
|
fi
|
|
# Alpine only has adduser (Busybox)
|
|
if [ -e /usr/sbin/adduser ]
|
|
then
|
|
adduser -S telelog
|
|
addgroup -S telelog
|
|
addgroup telelog telelog
|
|
return 0
|
|
fi
|
|
}
|
|
|
|
addfiles(){
|
|
# Install executable and config
|
|
install -dm770 -o root -g telelog /var/telelog
|
|
install -dm770 -o root -g telelog /var/telelog/logs
|
|
install -m640 -o root -g telelog config.py /var/telelog/config.py
|
|
install -m755 -o root -g root bin/telelog /usr/bin/telelog
|
|
echo '{}' > /var/telelog/settings.json
|
|
chown telelog:telelog /var/telelog/settings.json
|
|
|
|
# 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
|
|
}
|
|
|
|
setup(){
|
|
install -m500 -o telelog -g telelog bin/setup /tmp/setup
|
|
su telelog -s /usr/bin/python3 /tmp/setup
|
|
rm /tmp/setup
|
|
}
|
|
|
|
# Install dependencies
|
|
[ $(which apt) ] && apt install python3-pip
|
|
[ $(which apk) ] && apk add py3-pip
|
|
pip3 install -U telethon
|
|
# Generate config if not built yet
|
|
[ ! -f config.py ] && mkconfig
|
|
# Create a new user
|
|
mkuser
|
|
# Install files if config is (now) present
|
|
[ -f config.py ] && addfiles
|
|
|
|
# Run Telethon for the first time
|
|
umask 0077
|
|
[ -f bin/setup ] && setup
|
|
|
|
# Start the service
|
|
service telelog start
|
|
|
|
return 0
|