summaryrefslogtreecommitdiffstats
path: root/linhes/linhes-system/lh_system_start.sh
blob: fb21b92a41984580adeb2d26a1918be16d81ce35 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash

. /etc/profile
#. /etc/systemconfig

HOSTNAME=`/usr/bin/hostnamectl hostname`

function msg(){
    /usr/bin/lh_notify-send --app-name="LinHES" --icon=dialog-information "$1" "$2"
}

function check_installer_user(){
    if [[ "$(whoami)" = 'km' ]]; then
        echo "Running lh_system_start as installer user km. Exiting."
        exit 1
    fi
}

function applyUIsettings(){
    cp /usr/share/linhes/templates/plasma-org.kde.plasma.desktop-appletsrc ~/.config/
    #restart plasma
    kquitapp5 plasmashell
    kstart5 plasmashell > /dev/null 2>&1
    plasma-apply-colorscheme BreezeDark
    kwriteconfig5 --group KDE --key SingleClick false
    kwriteconfig5 --file ~/.config/kscreenlockerrc --group Daemon --key Autolock false
    kwriteconfig5 --file ~/.config/kscreenlockerrc --group Daemon --key LockOnResume false
    kwriteconfig5 --file ~/.config/ksmserverrc --group General --key loginMode emptySession
    #disable file indexing
    balooctl disable
    sleep 2
    plasma-apply-wallpaperimage /usr/share/linhes/templates/lights-bud-abstract-4k-cq.jpg
    msg "Welcome to LinHES 9!"
}

function x11vnc_setup(){
    konsole -e /bin/bash -i -c "echo 'Create VNC password.' && x11vnc --storepasswd"
    mkdir -p ~/.vnc
    touch ~/.vnc/x11vnc.log
    sudo /usr/bin/systemctl enable --now x11vnc.service
}

function bashrc_setup(){
    if ! grep -q 'alias rscp=' ~/.bashrc; then
        echo -e "\nalias rscp='rsync -a --info=progress2'" >> ~/.bashrc
    fi
    if ! grep -q 'alias rsmv=' ~/.bashrc; then
        echo -e "alias rsmv='rsync -a --info=progress2 --remove-source-files'" >> ~/.bashrc
    fi
}

function nanorc_setup(){
    sudo sed -i 's/# set tabsize.*/set tabsize 4/' /etc/nanorc
    sudo sed -i 's/# set tabstospaces.*/set tabstospaces/' /etc/nanorc
    sudo sed -i 's/# include "\/usr\/share\/nano\/\*.nanorc"/include "\/usr\/share\/nano\/\*.nanorc"/' /etc/nanorc
}

function storage_scan(){
    sudo add_storage.py --report > /dev/null
    if [ -e /tmp/scan_report ]; then
        msg "New Storage Found" "Run add_storage.py for details."
    fi
}

function install_lh_apps(){
    #install programs that are not needed on the iso
    msg "Installing apps."
    sudo pacman -Syyy --noconfirm archlinux-keyring
    #sudo pacman -Syyy --noconfirm flatpak firefox glances mlocate mythtv mythplugins-mytharchive mythplugins-mythmusic mythplugins-mythweb ncdu x11vnc
    sudo pacman -Syyy --noconfirm mythtv mythplugins-mytharchive mythplugins-mythmusic mythplugins-mythweb
    status=$?
    [ $status -eq 1 ] && msg "Could not install apps. Check internet connection. Cancelling Setup." && exit 1
    flatpak install tv.plex.PlexHTPC --noninteractive --assumeyes
    gen_lib_xml.py
}

function sql_setup(){
    sudo mkdir -p /data/srv/mysql
    sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/data/srv/mysql
    sudo systemctl enable --now mariadb.service
    mysql_tzinfo_to_sql /usr/share/zoneinfo | sudo mysql -u root mysql
    sudo mariadb -u root < /usr/share/linhes/templates/db/permissions.sql
    mythtv-setup -O theme=LinHES
    sed -e "s/apheleia/${HOSTNAME}/g" /usr/share/linhes/templates/db/custom.sql > /tmp/custom.sql.fixed
    sudo mariadb -u root mythconverg < /tmp/custom.sql.fixed
}

function localweb_setup(){
    sudo pacman -Syyy --noconfirm linhes-web
    sudo cp /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig
    sudo cp /usr/share/linhes/templates/lighttpd.conf.template /etc/lighttpd/lighttpd.conf
    sudo systemctl enable --now lighttpd.service
}

function first_configure(){
    if [ ! -f ~/.config/lh_configured ]; then
        #apply settings for all system types
        applyUIsettings
        msg "New install of LinHES. Starting setup."
        install_lh_apps
        nanorc_setup
        bashrc_setup
        x11vnc_setup
        if [ -f /etc/systemconfig ]; then
            SystemType=$(grep SystemType= /etc/systemconfig | cut -d '"' -f 2)
        else
            SystemType=$(kdialog --title "LinHES System Type" --combobox "Select the LinHES System Type:                               " "MasterBackend" "FrontendOnly" --default "MasterBackend")
            echo "SystemType=\"$SystemType\"" | sudo tee /etc/systemconfig
        fi
        #apply settings for specific system types
        msg "Setup as $SystemType"
        if [ ! $SystemType = "FrontendOnly" ]; then
            # create media directory structure
            sudo mkdir -p /data/storage/disk0
            sudo create_media_dirs.sh /data/storage/disk0
            # setup DB
            sql_setup
            # run mythtv-setup
            # need to run twice for default db install/upgrade
            mythtv-setup
            sudo systemctl enable --now mythbackend.service
            # run mythfilldatabase
            #nice -n 19 mythfilldatabase --quiet &
            #msg "Guide data is being loaded." "Until this completes some shows will appear as unknown in the program guide."
            localweb_setup
        else
            msg "Frontend Only"
            #Frontend_only cmds
        fi
        touch ~/.config/lh_configured
    fi
}

function start_myth() {
    STARTCMD="/usr/bin/mythfrontend --systemd-journal"
    $STARTCMD 2>&1 &
}

#-------MAIN-------
check_installer_user
first_configure
/usr/bin/enableIRWake.sh &
storage_scan
start_myth