summarylogtreecommitdiffstats
path: root/mhwd-db.install
blob: e2741127fdcd8a2508b15a9ae361a33498dc3eec (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
#!/bin/sh
# arg 1:  the new package version
# arg 2:  the old package version

local_config_dir="/var/lib/mhwd/local/pci"
db_config_dir="/var/lib/mhwd/db/pci"

err() {
    ALL_OFF="\e[1;0m"
    BOLD="\e[1;1m"
    RED="${BOLD}\e[1;31m"
	local mesg=$1; shift
	printf "${RED}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}

msg() {
    ALL_OFF="\e[1;0m"
    BOLD="\e[1;1m"
    GREEN="${BOLD}\e[1;32m"
	local mesg=$1; shift
	printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}

# $1: old config name
# $2: new config name
# $3: new config path
rename_config() {
    if [ -e "${local_config_dir}/${1}/MHWDCONFIG" ] ; then
      msg "Renaming config: '${local_config_dir}/${1}'"
      mkdir -p ${local_config_dir}/${2}
      cp -f ${db_config_dir}/graphic_drivers/${3}/MHWDCONFIG ${local_config_dir}/${2}/MHWDCONFIG
      rm -Rf ${local_config_dir}/${1}
   fi
}

update_configs() {
   local_configs=$(ls ${local_config_dir})
   db_configs="$(ls ${db_config_dir}/graphic_drivers) $(ls ${db_config_dir}/network_drivers)"

   # Rename old configs
   rename_config "video-hybrid-amd-nvidia-dkms-prime-render-offloading" "video-nvidia-prime-render-offload" "nvidia-prime-render-offload"
   rename_config "video-hybrid-intel-nvidia-dkms-prime-render-offloading" "video-nvidia-prime-render-offload" "nvidia-prime-render-offload"
   rename_config "video-hybrid-amd-chaotic-nvidia-dev-dkms-tkg-prime-render-offloading" "video-chaotic-nvidia-dev-tkg-prime-render-offload" "chaotic-nvidia-dev-tkg-prime-render-offload"
   rename_config "video-hybrid-intel-chaotic-nvidia-dev-dkms-tkg-prime-render-offloading" "video-chaotic-nvidia-dev-tkg-prime-render-offload" "chaotic-nvidia-dev-tkg-prime-render-offload"
   rename_config "video-hybrid-amd-chaotic-nvidia-dkms-tkg-prime-render-offloading" "video-chaotic-nvidia-tkg-prime-render-offload" "chaotic-nvidia-tkg-prime-render-offload"
   rename_config "video-hybrid-intel-chaotic-nvidia-dkms-tkg-prime-render-offloading" "video-chaotic-nvidia-tkg-prime-render-offload" "chaotic-nvidia-tkg-prime-render-offload"

   # check for newer configs
   for db_config in ${db_configs} ; do
      if [ -e "${db_config_dir}/graphic_drivers/${db_config}/MHWDCONFIG" ] ; then
         . "${db_config_dir}/graphic_drivers/${db_config}/MHWDCONFIG"
      elif [ -e "${db_config_dir}/network_drivers/${db_config}/MHWDCONFIG" ] ; then
         . "${db_config_dir}/network_drivers/${db_config}/MHWDCONFIG"
      else
         continue
      fi
      db_config_ver=${VERSION}
      if [ -e "${local_config_dir}/${NAME}/MHWDCONFIG" ] ; then
         . "${local_config_dir}/${NAME}/MHWDCONFIG"
         local_config_ver=${VERSION}
         if [ "$(echo ${local_config_ver} | sed -e 's/\.//g')" -lt "$(echo ${db_config_ver} | sed -e 's/\.//g')" ]; then
            msg "Updating Config: '${local_config_dir}/${NAME}'"
            if [ -e "${db_config_dir}/graphic_drivers/${db_config}/MHWDCONFIG" ] ; then
               cp -f ${db_config_dir}/graphic_drivers/${db_config}/MHWDCONFIG ${local_config_dir}/${NAME}
            else
               cp -f ${db_config_dir}/network_drivers/${db_config}/MHWDCONFIG ${local_config_dir}/${NAME}
            fi
         fi
      fi
   done
   # Update outdated configs
   if [ -e "${local_config_dir}/video-nvidia/MHWDCONFIG" ] ; then
      msg "Updating Config: '${local_config_dir}/video-nvidia-430xx'"
      mkdir -p ${local_config_dir}/video-nvidia-430xx
      cp -f ${db_config_dir}/graphic_drivers/nvidia-430xx/MHWDCONFIG ${local_config_dir}/video-nvidia-430xx/MHWDCONFIG
      rm -Rf ${local_config_dir}/video-nvidia
   fi
   if [ -e "${local_config_dir}/video-hybrid-intel-nvidia-bumblebee/MHWDCONFIG" ] ; then
      msg "Updating Config: '${local_config_dir}/video-hybrid-intel-nvidia-430xx-bumblebee'"
      mkdir -p ${local_config_dir}/video-hybrid-intel-nvidia-430xx-bumblebee
      cp -f ${db_config_dir}/graphic_drivers/hybrid-intel-nvidia-430xx-bumblebee/MHWDCONFIG ${local_config_dir}/video-hybrid-intel-nvidia-430xx-bumblebee/MHWDCONFIG
      rm -Rf ${local_config_dir}/video-hybrid-intel-nvidia-bumblebee
   fi
}

post_upgrade() {
   update_configs
}