From 5ea7128e4f3cc37a21d8c39c58b6cab7e4352426 Mon Sep 17 00:00:00 2001
From: Britney Fransen <brfransen@gmail.com>
Date: Sun, 11 Dec 2022 15:10:22 -0500
Subject: linhes-system: lh_system_start.sh: more fixes

---
 linhes/linhes-system/PKGBUILD           | 28 ++++++++++++-------------
 linhes/linhes-system/lh_system_start.sh | 37 ++++++++++++++++++++++++++++-----
 2 files changed, 46 insertions(+), 19 deletions(-)

diff --git a/linhes/linhes-system/PKGBUILD b/linhes/linhes-system/PKGBUILD
index 509c722..42492c9 100755
--- a/linhes/linhes-system/PKGBUILD
+++ b/linhes/linhes-system/PKGBUILD
@@ -1,11 +1,12 @@
 pkgname=linhes-system
 pkgver=9.0.0
-pkgrel=6
+pkgrel=9
 arch=('x86_64')
 #install=$pkgname.install
 pkgdesc="Everything that makes LinHES a system"
 license=('GPL2')
-depends=('cronie' 'dbus-python' 'libnotify' 'linhes-templates' 'pacman-contrib' 'openssh' 'ttf-overlock')
+depends=('cronie' 'dbus-python' 'kdialog' 'libnotify' 'linhes-templates' 'pacman-contrib'
+         'openssh' 'ttf-overlock')
 binfiles="add_storage.py balance_storage_groups.py empty_storage_groups.py remove_storage.py
           checkXFSfrag.sh enableIRWake.sh idle.py lh_system_start.sh jobqueue_helper.py
           diskspace.sh find_orphans.py optimize_mythdb.py
@@ -25,7 +26,7 @@ sha256sums=('96f67b5428debb7dac909893c56a7637bf6545c068732822981d4080125c53d9'
             '11168c9cd3b117decaab6bc665c183b4aab917cf0a976bce4c1b5e4686a27bc9'
             'ae34515e144830f424d3bd3f6b1b446892d62beed20bca6f0fb19b0bbb779f27'
             '23358a7bff4968eccd469613b81b1415c2ae0ebe77f14f74426697333e4d88d7'
-            '0dfa7930dd403b1141480c21b2ab6747258d6d0fba496f3f5ea35034588eac15'
+            'a664ca7d13373f5fe6eb7747939624d7342039f04a19c06d602e83f89b30de16'
             '91bdec992bb2c933e15625c181f2195c402060b879168ebf35944cb064c904b9'
             'cedd34e448d3d45ab0f9fff40c115401f45bdea5b99215d0aff514a759ae2b7c'
             '76f023c0cde7fea269234f1b29c32b117b91769217d4b1b8a3922daceb25f9f8'
@@ -63,21 +64,21 @@ package() {
     done
 
     #startup files
-    install -D -m600 "$srcdir/lh_system_start.sh.desktop" "$pkgdir/home/mythtv/.config/autostart/lh_system_start.sh.desktop"    
+    install -Dm644 "$srcdir/lh_system_start.sh.desktop" "$pkgdir/etc/skel/.config/autostart/lh_system_start.sh.desktop"
 
     #systemd files
-    install -m644 -D $srcdir/x11vnc.override.conf $pkgdir/etc/systemd/system/x11vnc.service.d/override.conf
+    install -Dm644 $srcdir/x11vnc.override.conf $pkgdir/etc/systemd/system/x11vnc.service.d/override.conf
 
     #readme files
-    install -m644 -D $srcdir/readme_is_xml $pkgdir/etc/gen_is_xml.d/readme_is_xml
-    install -m644 -D $srcdir/readme_is_xml $pkgdir/etc/gen_lib_xml.d/readme_gen_xml
-    install -m644 -D $srcdir/readme_is_xml $pkgdir/etc/gen_game_xml.d/readme_gen_xml
-    install -m644 -D $srcdir/add_storage.readme $pkgdir/etc/storage.d/readme
+    install -Dm644 $srcdir/readme_is_xml $pkgdir/etc/gen_is_xml.d/readme_is_xml
+    install -Dm644 $srcdir/readme_is_xml $pkgdir/etc/gen_lib_xml.d/readme_gen_xml
+    install -Dm644 $srcdir/readme_is_xml $pkgdir/etc/gen_game_xml.d/readme_gen_xml
+    install -Dm644 $srcdir/add_storage.readme $pkgdir/etc/storage.d/readme
 
     #cron files
-    install -m755 -D $srcdir/paccache.cron $pkgdir/etc/cron.weekly/paccache.cron
-    install -m755 -D $srcdir/xfs_defrag.cron $pkgdir/etc/cron.weekly/xfs_defrag
-    install -m755 -D $srcdir/myth_mtc.cron $pkgdir/etc/cron.hourly/myth_mtc
+    install -Dm755 $srcdir/paccache.cron $pkgdir/etc/cron.weekly/paccache.cron
+    install -Dm755 $srcdir/xfs_defrag.cron $pkgdir/etc/cron.weekly/xfs_defrag
+    install -Dm755 $srcdir/myth_mtc.cron $pkgdir/etc/cron.hourly/myth_mtc
 
     #hooks
 	install -Dm0644 $srcdir/79-cronie.hook "${pkgdir}"/usr/share/libalpm/hooks/79-cronie.hook
@@ -88,9 +89,8 @@ package() {
     mkdir -p $pkgdir/etc/sudoers.d/
     chmod 750 $pkgdir/etc/sudoers.d/
     chown -R root:root $pkgdir/etc/sudoers.d
-    install -o root -g root -m 0750 $srcdir/system-sudo.rules $pkgdir/etc/sudoers.d/system_sudo
+    install -o root -g root -m0750 $srcdir/system-sudo.rules $pkgdir/etc/sudoers.d/system_sudo
 
     #disable dpms
     install -m644 -D $srcdir/10-monitor.conf $pkgdir/etc/X11/xorg.conf.d/10-monitor.conf
-
 }
diff --git a/linhes/linhes-system/lh_system_start.sh b/linhes/linhes-system/lh_system_start.sh
index a74805a..24c35d5 100755
--- a/linhes/linhes-system/lh_system_start.sh
+++ b/linhes/linhes-system/lh_system_start.sh
@@ -2,12 +2,19 @@
 
 . /etc/profile
 #. /etc/systemconfig
-SystemType=Masterbackend
+#SystemType=Masterbackend
 
 function msg(){
     /usr/bin/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
@@ -55,7 +62,10 @@ function storage_scan(){
 
 function install_lh_apps(){
     #install programs that are not needed on the iso
-    sudo pacman -Syyy --noconfirm firefox glances mythtv ncdu x11vnc
+    msg "Installing apps..."
+    sudo pacman -Syyy --noconfirm firefox glances mythtv mythplugins-mytharchive mythplugins-mythmusic mythplugins-mythweb ncdu x11vnc
+    status=$?
+    [ $status -eq 1 ] && msg "Could not install apps. Check internet connection." && exit 1
 }
 
 function first_configure(){
@@ -67,12 +77,28 @@ function first_configure(){
         nanorc_setup
         bashrc_setup
         x11vnc_setup
+        SystemType=$(kdialog --title "LinHES System Type" --combobox "Select the LinHES System Type:                               " "MasterBackend" "FrontendOnly" --default "MasterBackend")
 
         #apply settings for specific system types
-        if [ ! $SystemType = "Frontend_only" ]; then
-            # only run mythfilldatabase for masterbackends
+        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
+            sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
+            sudo systemctl enable --now mariadb.service
+            sudo mariadb -u root < /usr/share/linhes/templates/db/permissions.sql
+            mysql_tzinfo_to_sql /usr/share/zoneinfo | sudo mysql -u root mysql
+            # run mythtv-setup
+            #export DISPLAY=:0
+            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."
+            #msg "Guide data is being loaded." "Until this completes some shows will appear as unknown in the program guide."
         else
             msg "Frontend Only"
             #Frontend_only cmds
@@ -84,6 +110,7 @@ function first_configure(){
 
 
 #-------MAIN-------
+check_installer_user
 first_configure
 /usr/bin/enableIRWake.sh &
 storage_scan
-- 
cgit v0.12

