From 89ea4d27868636f27241dbcd23dda9b4d73592f7 Mon Sep 17 00:00:00 2001
From: Britney Fransen <brfransen@gmail.com>
Date: Thu, 22 Dec 2022 16:26:40 -0500
Subject: linhes-system: add_storage.py: remove old LH8 installer things

---
 linhes/linhes-system/PKGBUILD           |  16 +--
 linhes/linhes-system/add_storage.py     | 201 ++++++++------------------------
 linhes/linhes-system/be_check.py        |  25 +---
 linhes/linhes-system/diskspace.sh       |   4 +-
 linhes/linhes-system/find_orphans.py    |   2 +-
 linhes/linhes-system/lh_notify-send     |  12 ++
 linhes/linhes-system/lh_system_start.sh |   9 +-
 7 files changed, 78 insertions(+), 191 deletions(-)
 create mode 100755 linhes/linhes-system/lh_notify-send

diff --git a/linhes/linhes-system/PKGBUILD b/linhes/linhes-system/PKGBUILD
index ae993b7..5e4eace 100755
--- a/linhes/linhes-system/PKGBUILD
+++ b/linhes/linhes-system/PKGBUILD
@@ -1,6 +1,6 @@
 pkgname=linhes-system
 pkgver=9.0.0
-pkgrel=11
+pkgrel=13
 arch=('x86_64')
 #install=$pkgname.install
 pkgdesc="Everything that makes LinHES a system"
@@ -8,7 +8,8 @@ license=('GPL2')
 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
+          checkXFSfrag.sh enableIRWake.sh idle.py lh_system_start.sh lh_notify-send
+          jobqueue_helper.py
           diskspace.sh find_orphans.py optimize_mythdb.py
           create_media_dirs.sh be_check.py
           myth2mkv myth2mp3"
@@ -19,20 +20,21 @@ source=($binfiles
     '10-monitor.conf' 'x11vnc.override.conf'
     'system-sudo.rules' 'linhes-profile.sh'
     'lh_system_start.sh.desktop')
-sha256sums=('979a916cb54ca8f481a045867b0c77c06cf184a3e8d962df52525dd893e1ace4'
+sha256sums=('7f91d2afcb76e8e9063c6bbe05f5c3d134a6f67541aead8894d342c32d34ad98'
             'b0e8fe4d04e1f779d52a28156489fb51efc13e173efccba2d6d458044bf35904'
             '4ab36bbabf0964f666278c225f4c2d41f4277acb42e9023163fa3a9599282466'
             'ff261f41efec8a9963f9f59100cbe75f015028a2ed3a863ce0cb473f2ebb7b76'
             '11168c9cd3b117decaab6bc665c183b4aab917cf0a976bce4c1b5e4686a27bc9'
             'ae34515e144830f424d3bd3f6b1b446892d62beed20bca6f0fb19b0bbb779f27'
             '23358a7bff4968eccd469613b81b1415c2ae0ebe77f14f74426697333e4d88d7'
-            '5698b2899ecb8a9cce610aecb4deaa17078cee37b0f6d8e262e360b20f27efe3'
+            '5910646ba0dba090c35ad3cfb7b8eed374bd761517807eeda3fb8007613cb127'
+            '6d4fb0ed1a5ed961b3a3884dce093118e50c2981a9cd5837d20abc5a6d4fd8aa'
             '91bdec992bb2c933e15625c181f2195c402060b879168ebf35944cb064c904b9'
-            'cedd34e448d3d45ab0f9fff40c115401f45bdea5b99215d0aff514a759ae2b7c'
-            '76f023c0cde7fea269234f1b29c32b117b91769217d4b1b8a3922daceb25f9f8'
+            'ebdb3ee0212e0cc72526bb5e50a032573e1894acb7bf75617243b0b49aa1f8f2'
+            '4d006f0fe3b13e67de1b961d611e81911905a30d140849dfdb8e5c0dc4da2f7c'
             'e371c6a289c68fe200d7da856c20a8c579efa23178f4d62235f7359d7f6e49a1'
             'bffcc13e4b480f720feb2b3c781bc4247c63303250c3d885022c699573d45a33'
-            '0254a21644473ba7953501a223f13b9b55d7ec290c80a567724ca1ac13e02e30'
+            '51093acab5e5a4de51a55f4bdf7b935f4f69edf3d84f1c37db710853ec95eca8'
             '9ea1b5583cd38f53bb79d9e4ccae91a028db0b6850162d7991b19122c564b9c9'
             'cab7724cd7c792adae79ba11cf59a0908edf197c437ae6b356ce86c6a365f0da'
             '9e97b4d68c9e8988daacadd40f1de9f0b5945d870eba596a2ceb5e0c023fa9c0'
diff --git a/linhes/linhes-system/add_storage.py b/linhes/linhes-system/add_storage.py
index e210bf1..e880884 100755
--- a/linhes/linhes-system/add_storage.py
+++ b/linhes/linhes-system/add_storage.py
@@ -5,7 +5,7 @@
 #Disks that are mounted, in fstab, size < 5000 bytes, optical or
 #have already been seen will not be presented as an option.
 #
-# Version 2.0.1
+# Version 2.0.2
 
 import dbus
 import pickle
@@ -188,7 +188,6 @@ class disk_device:
         return
 
     def get_fsmap(self):
-        #block,point,fs
         fs_map=[]
 
         f = open('/proc/mounts','r')
@@ -243,7 +242,7 @@ class disk_device:
         tmpuuid = runcmd(cmd)[1]
         splituuid = tmpuuid.partition("=")
         uuid = splituuid[2].replace('"', "")
-       # logging.info("The uuid is %s", uuid)
+        #logging.info("The uuid is %s", uuid)
         if uuid == '':
             print("Could not find a UUID for device: %s" %partition)
             sys.exit(1)
@@ -272,38 +271,38 @@ class disk_device:
         return options,i
 
 
-    def add_fstab(self,bind=False):
-        new_fstab_list=['UUID=', 'mount_point', 'auto', 'defaults', '0', '1']
+    def add_fstab(self):
+        #new_fstab_list=['UUID=', 'mount_point', 'auto', 'defaults', '0', '1']
+        new_fstab_list=['UUID=', 'mount_point', self.new_fstype, 'defaults', '0', '1']
         fstab=self.read_fstab()
         new_fstab=[]
 
         #determine mount_path
         self.new_mount_point="%s/%s_%s" %(self.top_mount_dir,self.model.replace(' ',''),self.serial_number.replace(' ',''))
 
-        if bind:
-            new_fstab_list=["/data/storage/disk0" , self.new_mount_point , "none" , "rw,bind", '0', '0']
-            uuid=self.find_uuid(self.block_partition)
-        else:
-            #check for old mount point and comment out
-            for line in fstab:
-                if not line.startswith("#"):
-                    if line.find(self.new_mount_point) > -1:
-                        print("      Found old mount %s in fstab, commenting out" %self.new_mount_point)
-                        line = "#"+line
+        #check for old mount point and comment out
+        for line in fstab:
+            if not line.startswith("#"):
+                if line.find(self.new_mount_point) > -1:
+                    print("      Found old mount %s in fstab, commenting out" %self.new_mount_point)
+                    line = "#"+line
                 new_fstab.append(line)
-            fstab=new_fstab
+        fstab=new_fstab
 
-            #determine options
-            new_options = self.find_options_type(fstab)[0]
+        #determine options
+        #new_options = self.find_options_type(fstab)[0]
+        new_options = "nofail,x-systemd.device-timeout=1"
 
-            #find blkid
-            self.block_partition="%s1" %self.block_path
-            uuid=self.find_uuid(self.block_partition)
+        #find blkid
+        self.block_partition="%s1" %self.block_path
+        uuid=self.find_uuid(self.block_partition)
 
-            #construct new line
-            new_fstab_list[0]="UUID=%s" %uuid
-            new_fstab_list[1]=self.new_mount_point
-            new_fstab_list[3]=new_options
+        #construct new line
+        new_fstab_list[0]="UUID=%s" %uuid
+        new_fstab_list[1]=self.new_mount_point
+        new_fstab_list[3]=new_options
+        if self.new_fstype == "xfs":
+            new_fstab_list[5]="0"
 
         new_fstab_line='\t'.join(new_fstab_list)
         new_fstab_line="%s\n" %new_fstab_line
@@ -311,10 +310,8 @@ class disk_device:
 
         #add line to fstab
         f = open('/etc/fstab', 'w')
-        #f = open('/tmp/fstab', 'w')
         for i in fstab:
             f.write(i)
-            #f.write("\n")
         f.close()
         return
 
@@ -416,15 +413,6 @@ class disk_device:
         cmd = "ln -s %s %s" %(self.new_mount_point,disk_ln)
         runcmd(cmd)
 
-    def symlink(self):
-        pass
-        print("    Creating symlink for /myth")
-        if not os.path.exists("/myth"):
-            cmd = "ln -s %s/media /myth " %(self.new_mount_point)
-            runcmd(cmd)
-        else:
-            print("       Skipping symlink, /myth already exists")
-
 
 #end of class
 
@@ -672,7 +660,7 @@ def main(scan_only, destruction, no_mount, install_call, dir_sg):
             print("    Unknown or Unmounted Disks:")
             f = open('/tmp/scan_report', 'w')
             for i in process_list:
-                f.write("disk: %s , location: %s ,size: %s \n" %(i.model,i.block_path,i.device_size))
+                f.write("disk: %s, location: %s, size: %s\n" %(i.model,i.block_path,i.device_size))
                 print("\n")
                 print("    ---------------------------------------------------------")
                 print("    Found New Disk:")
@@ -695,12 +683,6 @@ def main(scan_only, destruction, no_mount, install_call, dir_sg):
     else:
         print("\nThere are no disks to add to your system.\n\nFor more options: add_storage.py --help\n")
         write_known_drive_list(system_drive_list)
-            #BE = MythBE(db=DB)
-
-
-    #save new list to disk_device
-    #write_known_drive_list(system_drive_list)
-    #disk_num = last_disk_num()
 
 
     if len(process_list) > 0:
@@ -719,7 +701,6 @@ def main(scan_only, destruction, no_mount, install_call, dir_sg):
                     i.format_disk()
                 i.add_fstab()
                 i.mount_disk(no_mount)
-                #if destruction == True:
 
                 if dir_sg == True:
                     i.mkdirs(FS_LIST)
@@ -736,72 +717,6 @@ def main(scan_only, destruction, no_mount, install_call, dir_sg):
                     i.add_sg(DB,host,SG_MAP)
 
                 print("-----")
-            #cmd = "systemconfig.py -m fileshare"
-            #runcmd(cmd)
-        #i.add_sg(DB,host,SG_MAP)
-
-def myth_main(no_mount,install_call,dir_sg):
-    global bus
-    bus = dbus.SystemBus()
-    #search for root
-    f = open('/etc/fstab', 'r')
-    fstab=f.readlines()
-    f.close()
-    for i in fstab:
-        split_line=i.split()
-        if not split_line:
-            continue
-
-        try:
-            if split_line[1] ==  "/" :
-                uuid_device = split_line[0]
-                break
-        except:
-            print("Couldn't find / in fstab")
-            sys.exit(1)
-    if uuid_device.startswith("UUID"):
-        uuid_device = uuid_device.split("=")[1]
-        cmd = "blkid -U %s" %uuid_device
-        device = runcmd(cmd)[1]
-    else:
-        device = uuid_device.strip()
-    #should have something like /dev/sda1
-    #remove all the digits
-    device = ''.join([letter for letter in device if not letter.isdigit()])
-
-
-    system_drive_list = scan_system()
-    for i in system_drive_list:
-        if i.block_path == device:
-            break
-    else:
-        print("Couldn't find root device in block list")
-        sys.exit(1)
-    if not install_call == True:
-        DB = MythDB()
-        host=gethostname()
-    else:
-        DB = None
-        host=gethostname()
-
-
-    print("    Disk: %s" %(i.get_name()))
-    i.set_mmount(True)
-    i.set_dir_sg(dir_sg)
-    i.set_partition("7")
-    i.set_disk_num(0)
-    i.lookup_format()
-    i.add_fstab(True)
-    #if not install_call:
-    i.mount_disk(no_mount)
-    i.write_config()
-    #no need to make the sub directories because the install process has taken care of it.
-    if dir_sg == True:
-        i.add_sg(DB,host,SG_MAP,'99',install_call)
-
-    i.symlink()
-    cmd = "systemconfig.py -m fileshare"
-    runcmd(cmd)
 
 def reconstruct_storagegroups():
     print("\nRecreating storage groups from contents of /etc/storage.d/\n")
@@ -833,7 +748,7 @@ def reconstruct_storagegroups():
         except configparser.NoOptionError as err:
             print("SG not found in conf, get setting from DB")
             dir_sg = False
-            # Get storage sroup directories from DB
+            # Get storage group directories from DB
             recs = DB.getStorageGroup(groupname="Default")
             for record in recs:
                 if record.dirname.startswith(mount_point):
@@ -908,8 +823,6 @@ class reconstruct_path:
         self.uuid = parser.get('storage', 'uuid')
         self.mount_point = parser.get('storage', 'mountpoint')
         self.shareable = parser.get('storage', 'shareable')
-        self.myth_mount = parser.get('storage', 'mmount')
-        self.bind = self.myth_mount
         self.disk_num = parser.get('storage', 'disk_num')
         self.top_mount_dir = os.path.dirname(self.mount_point)
         try:
@@ -989,19 +902,9 @@ class reconstruct_path:
         new_fstab_line="%s\n" %new_fstab_line
 
         f = open('/etc/fstab', 'a')
-        #f = open('/tmp/fstab', 'a')
         f.write(new_fstab_line)
-        #f.write("\n")
         f.close()
 
-    def symlink(self):
-        print("    Creating symlink for /myth")
-        if not os.path.exists("/myth"):
-            cmd = "ln -s %s/media /myth " %(self.mount_point)
-            runcmd(cmd)
-        else:
-            print("       Skipping symlink, /myth already exists")
-
     def symlink_disk(self):
         print("    Creating symlink for disk%s" %self.disk_num)
         disk_ln="%s/disk%s" %(self.top_mount_dir,self.disk_num)
@@ -1013,38 +916,29 @@ class reconstruct_path:
         new_fstab_list=['UUID=', 'mount_point', self.fstype, 'defaults', '0', '1']
         fstab=self.read_fstab()
 
-        if self.bind == "True":
-            self.symlink()
-
         if self.check_in_fstab(fstab,self.uuid) == True:
             print("    Found UUID of disk in fstab, will not add it")
         else:
             print("    Adding storage to fstab")
-            if self.bind == "True" :
-                print("    Bind mount")
-                new_fstab_list=["/data/storage/disk0" , self.mount_point , "none" , "rw,bind", '0', '0']
-                if self.check_in_fstab(fstab,self.mount_point) == False:
-                    self.append_fstab(new_fstab_list)
-                else:
-                    print("    Found bind storage in fstab, will not add it")
+            #check for old mount point and comment out
+            f = open('/etc/fstab', 'w')
+            for line in fstab:
+                if not line.startswith("#"):
+                    if line.find(self.mount_point) > -1:
+                        print("      Found old mount %s in fstab, commenting out" %self.mount_point)
+                        line = "#"+line
+                f.write(line)
+            f.close()
 
-            else:
-                #check for old mount point and comment out
-                f = open('/etc/fstab', 'w')
-                for line in fstab:
-                    if not line.startswith("#"):
-                        if line.find(self.mount_point) > -1:
-                            print("      Found old mount %s in fstab, commenting out" %self.mount_point)
-                            line = "#"+line
-                    f.write(line)
-                f.close()
-
-                #construct new line
-                new_options = self.find_options_type(fstab)[0]
-                new_fstab_list[0]="UUID=%s" %self.uuid
-                new_fstab_list[1]=self.mount_point
-                new_fstab_list[3]=new_options
-                self.append_fstab(new_fstab_list)
+            #construct new line
+            #new_options = self.find_options_type(fstab)[0]
+            new_options = "nofail,x-systemd.device-timeout=1"
+            new_fstab_list[0]="UUID=%s" %self.uuid
+            new_fstab_list[1]=self.mount_point
+            new_fstab_list[3]=new_options
+            if self.fstype == "xfs":
+                new_fstab_list[5]="0"
+            self.append_fstab(new_fstab_list)
 
     def mount_disk(self,no_mount=False):
         try:
@@ -1124,7 +1018,6 @@ def usage():
             (if user enables MythTV storage groups)
         Write out the disk config file to /etc/storage.d/
         Create disk# symlink at /data/storage/
-        Create /myth symlink (if applicable)
         Create MythTV storage group paths in MythTV database
             (if user enables MythTV storage groups)
 
@@ -1142,7 +1035,7 @@ def usage():
                            partition on a disk and ignores all others.
     --no_mount:         Do not mount the disk.
                            All other normal operations will be performed.
-    --reconstruct:      Recreate mount point, /myth symlink, fstab entry,
+    --reconstruct:      Recreate mount point, fstab entry,
                            /data/storage/disk# symlink, and mount the disk.
                            --no_mount is the only option that works with
                            --reconstruct.
@@ -1215,9 +1108,7 @@ if __name__ == "__main__":
     if "--reconstruct_sg" in sys.argv:
         reconstruct_sg = True
 
-    if "--double_myth" in sys.argv:
-        myth_main(no_mount, install_call, dir_sg)
-    elif reconstruct == True:
+    if reconstruct == True:
         reconstruct_mounts(no_mount)
     elif reconstruct_sg == True:
         reconstruct_storagegroups()
diff --git a/linhes/linhes-system/be_check.py b/linhes/linhes-system/be_check.py
index b5f7a64..1a8dc58 100755
--- a/linhes/linhes-system/be_check.py
+++ b/linhes/linhes-system/be_check.py
@@ -2,33 +2,10 @@
 #simple program to check if mythbackend is up and running
 #exit code of 0 is success, anything else means it can't connect
 import sys
-class Logger(object):
-    def __init__(self, filename="/tmp/Default.log"):
-        #self.terminal = sys.stdout
-        try:
-            self.log = open(filename, "a")
-        except:
-            pass
-
-    def write(self, message):
-        try:
-            #self.terminal.write(message)
-            self.log.write(message)
-        except:
-            pass
-
-sys.stdout = Logger("/tmp/be_check.log")
-
-
 from MythTV import MythBE,MythDB
-#import datetime,time,sys,subprocess
-
-
-
-
 
 try:
-    be=MythBE()
+    be = MythBE()
     db = MythDB()
 except:
     sys.exit(1)
diff --git a/linhes/linhes-system/diskspace.sh b/linhes/linhes-system/diskspace.sh
index f28cf46..1ab6dd7 100755
--- a/linhes/linhes-system/diskspace.sh
+++ b/linhes/linhes-system/diskspace.sh
@@ -17,7 +17,7 @@ AWK='/usr/bin/awk'
 CUT='/usr/bin/cut'
 HOSTNAME='/usr/bin/hostnamectl hostname'
 DATE='/usr/bin/date'
-MSG_CLIENT='/usr/bin/notify-send'
+MSG_CLIENT='/usr/bin/lh_notify-send'
 
 #
 # Static System Variables
@@ -59,7 +59,7 @@ $DF -HPl | $GREP -E "^/dev/" | $AWK '{ print $5 " " $6 " " $1 }' | while read OU
     if [ ${USED_PCENT} -ge $ALERT ]; then
         echo "WARNING: Partition (${PARTITION}) on (${DEVICE}) is ${USED_PCENT}% full on ${THIS_HOST}"
         if [ $OSD = true ] && { [ ${PARTITION} = / ] || [ ${PARTITION} = /home ] || [ ${PARTITION} = /data/srv/mysql ]; } then
-            $MSG_CLIENT "Disk Space WARNING" "Partition (${PARTITION}) on (${DEVICE}) is ${USED_PCENT}% full."
+            $MSG_CLIENT --app-name="Disk Space WARNING" "Partition (${PARTITION}) on (${DEVICE}) is ${USED_PCENT}% full."
         fi
     fi
 done
diff --git a/linhes/linhes-system/find_orphans.py b/linhes/linhes-system/find_orphans.py
index 964d6e4..8072b8f 100755
--- a/linhes/linhes-system/find_orphans.py
+++ b/linhes/linhes-system/find_orphans.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python
 
 from MythTV import MythDB, MythBE, Recorded, MythError
 from socket import timeout
diff --git a/linhes/linhes-system/lh_notify-send b/linhes/linhes-system/lh_notify-send
new file mode 100755
index 0000000..dd98ede
--- /dev/null
+++ b/linhes/linhes-system/lh_notify-send
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+#Detect the name of the display in use
+display=":$(ls /tmp/.X11-unix/* | sed 's#/tmp/.X11-unix/X##' | head -n 1)"
+
+#Detect the user using such display
+user=$(who | grep '('$display')' | awk '{print $1}' | head -n 1)
+
+#Detect the id of the user
+uid=$(id -u $user)
+
+sudo -u $user DISPLAY=$display DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$uid/bus notify-send "$@"
diff --git a/linhes/linhes-system/lh_system_start.sh b/linhes/linhes-system/lh_system_start.sh
index 24c35d5..42f4b67 100755
--- a/linhes/linhes-system/lh_system_start.sh
+++ b/linhes/linhes-system/lh_system_start.sh
@@ -5,7 +5,7 @@
 #SystemType=Masterbackend
 
 function msg(){
-    /usr/bin/notify-send --app-name="LinHES" --icon=dialog-information "$1" "$2"
+    /usr/bin/lh_notify-send --app-name="LinHES" --icon=dialog-information "$1" "$2"
 }
 
 function check_installer_user(){
@@ -55,6 +55,7 @@ function nanorc_setup(){
 }
 
 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
@@ -107,10 +108,14 @@ function first_configure(){
     fi
 }
 
-
+function start_myth() {
+    STARTCMD="/usr/bin/mythfrontend
+    $STARTCMD 2>&1 &
+}
 
 #-------MAIN-------
 check_installer_user
 first_configure
 /usr/bin/enableIRWake.sh &
 storage_scan
+start_myth
-- 
cgit v0.12

