summaryrefslogtreecommitdiff
path: root/autologin.sh
blob: 41cae8fcaa4833dec6cd10335104679b87f8de04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
#This script makes an application run automatically on boot as user "pi"
#Created by Luca Tringali - www.codice-sorgente.it
#It is made for the thermostat project you find here: https://codice-sorgente.it/cgit/termostato-raspberry.git/
#Thanks to Dalen, this code is partially based on his answer: https://stackoverflow.com/questions/44186905/how-to-replace-the-desktop-interface-with-a-python-application

username="pi"
cat <<EOF > /etc/systemd/system/tty1.service
[Service]
Type=simple
ExecStart=/sbin/getty -a pi 38400 tty1
StandardInput=tty
StandardOutput=tty
TTYPath=/dev/tty1
TTYReset=yes
Restart=always
[Install]
WantedBy=multi-user.target
EOF

systemctl enable tty1.service
systemctl start tty1.service

cat <<EOF > /home/$username/.xinitrc
#! /bin/bash
cat
EOF
chown $username:$username /home/$username/.xinitrc

cat <<EOF > /home/$username/.bashrc
if [ \$(tty | sed s:^/dev/::) == "tty1" ]; then
export DISPLAY=:0
/home/$username/appstart &
startx
fi
EOF
chown $username:$username /home/$username/.bashrc

cat <<EOF > /home/$username/appstart
#! /bin/bash

# Wait a second for X server to start:
sleep 1
# use this if Xorg starts on tty7
# sudo chvt 7
/usr/bin/python3 /home/$username/termostato-raspberry/termostato.py
EOF
chmod +x /home/$username/appstart
chmod +x /home/$username/termostato-raspberry/termostato.py
chown $username:$username /home/$username/appstart

#This thermostat app also needs the following libraries:
sudo apt-get update
sudo aptitude install python3-rpi.gpio
sudo pip3 install w1thermsensor

#Disable old autologins, give user access to tty
sudo systemctl disable sddm.service
sudo systemctl disable getty.target
sudo systemctl disable getty@tty1.service
sudo usermod -a -G tty $username
sudo usermod -a -G video $username

echo "Don't forget to turn off Splash Screen under Boot section"
read
sudo raspi-config