Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • applications/mhwd
  • johann-koebbe/mhwd
  • yochananmarqos1/mhwd
3 results
Show changes
Commits on Source (117)
...@@ -2,3 +2,5 @@ Main developers: ...@@ -2,3 +2,5 @@ Main developers:
Roland Singer <roland@manjaro.org> Roland Singer <roland@manjaro.org>
Code refactoring: Code refactoring:
Łukasz Matysiak <december0123@gmail.com> Łukasz Matysiak <december0123@gmail.com>
Developers / Contributors:
Filipe Marques <eagle.software3@gmail.com>
## Manjaro HardWare Detection (mhwd)
#### Copyright © 2012-2018 Manjaro Developers
#### Project licensed under GNU GPL v.3 - Check COPYING file
#### The Manjaro HardWare Detection (mhwd) command is a unique feature of [Manjaro Linux](http://manjaro.org/) operating system.
#### There are currently two types of mhwd command:
1. mhwd: Enables the automatic detection and configuration of computer hardware the system is running on. This includes both hardware connected internally via PCI (e.g. graphics cards), and connected externally via [USB](http://en.wikipedia.org/wiki/USB) (e.g. flashdrives).
2. mhwd-kernel: Enables the installation and easy management of multiple kernels on your system.
#### For more info about mhwd go to [mhwd wiki page](https://wiki.manjaro.org/index.php?title=Manjaro_Hardware_Detection_Overview).
#### TODO list
- [ ] allow to set the base lib dir
- [ ] force to remove db config
- [ ] show detailed info for one config
- [ ] set architecture from library not from bash
- [ ] pass ids and bus ids to script
- [ ] don't remove packages on reinstallation...
- [ ] add option similar to pacman --root ...
### Contribute
#### Code Convention
The code convention used in this project is CamelCase. For example:
Instead of:
```c++
void Mhwd::set_version_mhwd(std::string version_of_software, std::string year_copyright)
{
}
```
write:
```c++
void Mhwd::setVersionMhwd(std::string versionOfSoftware, std::string yearCopyright)
{
}
```
#### Indentation of Code
Don't use tabs, instead use spaces and count 4 characters.
#### Software need for coding or testing
* C++ tool chain: [g++](https://gcc.gnu.org/) or [clang](http://clang.llvm.org/), [cmake](http://www.cmake.org/), [make](http://www.gnu.org/software/make/)
* Good Knowledge of [C++11](http://isocpp.org/)
* [git](http://git-scm.com/)
#### Building
In a terminal window do:
```shell
[your-name@your-name mhwd]$ mkdir build
[your-name@your-name mhwd]$ cd build/
[your-name@your-name build]$ cmake ..
[your-name@your-name build]$ make
```
now you have the mhwd program in the folder mhwd/bin/
or
```shell
[your-name@your-name build]$ make install
```
to install the files in linux directories!
#### Have a happy coding ! :thumbsup:
allow to set the base lib dir
force to remove db config
show detailed info for one config
set architecture from library not from bash
pass ids and bus ids to script
don't remove packages on reinstallation...
add option similar to pacman --root ...
...@@ -7,16 +7,7 @@ INSTALL(PROGRAMS mhwd-gpu ...@@ -7,16 +7,7 @@ INSTALL(PROGRAMS mhwd-gpu
INSTALL(PROGRAMS mhwd-kernel INSTALL(PROGRAMS mhwd-kernel
DESTINATION /usr/bin) DESTINATION /usr/bin)
INSTALL(PROGRAMS mhwd-fb
DESTINATION /usr/bin)
FILE(GLOB INCLUDEFILES "include/*") FILE(GLOB INCLUDEFILES "include/*")
INSTALL(PROGRAMS ${INCLUDEFILES} INSTALL(PROGRAMS ${INCLUDEFILES}
DESTINATION /var/lib/mhwd/scripts/include) DESTINATION /var/lib/mhwd/scripts/include)
INSTALL(FILES "initcpio/hooks/mhwd-fb"
DESTINATION /usr/lib/initcpio/hooks)
INSTALL(FILES "initcpio/install/mhwd-fb"
DESTINATION /usr/lib/initcpio/install)
...@@ -25,6 +25,10 @@ DEPENDS_32="..." ...@@ -25,6 +25,10 @@ DEPENDS_32="..."
DEPENDS_64="lib32-..." DEPENDS_64="lib32-..."
DEPKMOD="..." DEPKMOD="..."
# Optional remove dependencies
OPTREMDEPENDS="..."
OPTREMDEPENDS_32="..."
OPTREMDEPENDS_64="lib32-..."
# Conflicts # Conflicts
MHWDCONFLICTS="..." MHWDCONFLICTS="..."
......
...@@ -7,85 +7,85 @@ IDENTIFIERCOUNT=0 ...@@ -7,85 +7,85 @@ IDENTIFIERCOUNT=0
MHWD_ADD_DEVICE_SECTION_FOR_EACH_BUSID() MHWD_ADD_DEVICE_SECTION_FOR_EACH_BUSID()
{ {
local XORGDRIVER="$1" local XORGDRIVER="$1"
local XORGFILE="$2" local XORGFILE="$2"
local VENDORID="$3" local VENDORID="$3"
local PCIBUSIDS="" local PCIBUSIDS=""
if [ "$VENDORID" != "" ]; then if [ "$VENDORID" != "" ]; then
PCIBUSIDS="$(MHWD_DEVICE_BUS_ID "0300" "$VENDORID" "false")" PCIBUSIDS="$(MHWD_DEVICE_BUS_ID "0300" "$VENDORID" "false")"
fi fi
if [ "$PCIBUSIDS" == "" ]; then if [ "$PCIBUSIDS" == "" ]; then
MHWD_ADD_DEVICE_SECTION "$XORGDRIVER" "$XORGFILE" "$4" MHWD_ADD_DEVICE_SECTION "$XORGDRIVER" "$XORGFILE" "$4"
return return
fi fi
while read BUSID; do while read BUSID; do
MHWD_ADD_DEVICE_SECTION "$XORGDRIVER" "$XORGFILE" "BusID \"PCI:$BUSID\"|$4" MHWD_ADD_DEVICE_SECTION "$XORGDRIVER" "$XORGFILE" "BusID \"PCI:$BUSID\"|$4"
done <<< "$(echo "$PCIBUSIDS")" done <<< "$(echo "$PCIBUSIDS")"
} }
MHWD_ADD_DEVICE_SECTION() MHWD_ADD_DEVICE_SECTION()
{ {
local XORGDRIVER="$1" local XORGDRIVER="$1"
local XORGFILE="$2" local XORGFILE="$2"
echo 'Section "Device"' >> "$XORGFILE" echo 'Section "Device"' >> "$XORGFILE"
echo " Identifier \"Device${IDENTIFIERCOUNT}\"" >> "$XORGFILE" echo " Identifier \"Device${IDENTIFIERCOUNT}\"" >> "$XORGFILE"
echo " Driver \"$XORGDRIVER\"" >> "$XORGFILE" echo " Driver \"$XORGDRIVER\"" >> "$XORGFILE"
IFS='|' IFS='|'
for i in $3; do for i in $3; do
echo " $i" >> "$XORGFILE" echo " $i" >> "$XORGFILE"
done done
unset IFS unset IFS
echo 'EndSection' >> "$XORGFILE" echo 'EndSection' >> "$XORGFILE"
echo ' ' >> "$XORGFILE" echo ' ' >> "$XORGFILE"
IDENTIFIERCOUNT=$[IDENTIFIERCOUNT + 1] IDENTIFIERCOUNT=$[IDENTIFIERCOUNT + 1]
} }
MHWD_ADD_DRI() MHWD_ADD_DRI()
{ {
# only for free drivers # only for free drivers
sed -i /'Section "Device"'/,/'EndSection'/s/'EndSection'/"\tOption \"DRI\" \"true\"\nEndSection"/g "$1" sed -i /'Section "Device"'/,/'EndSection'/s/'EndSection'/"\tOption \"DRI\" \"true\"\nEndSection"/g "$1"
echo ' ' >> "$1" echo ' ' >> "$1"
echo 'Section "DRI"' >> "$1" echo 'Section "DRI"' >> "$1"
echo ' Group "video"' >> "$1" echo ' Group "video"' >> "$1"
echo ' Mode 0666' >> "$1" echo ' Mode 0666' >> "$1"
echo 'EndSection' >> "$1" echo 'EndSection' >> "$1"
echo ' ' >> "$1" echo ' ' >> "$1"
} }
MHWD_ADD_COMPOSITING() MHWD_ADD_COMPOSITING()
{ {
echo ' ' >> "$1" echo ' ' >> "$1"
echo 'Section "Extensions"' >> "$1" echo 'Section "Extensions"' >> "$1"
echo ' Option "Composite" "Enable"' >> "$1" echo ' Option "Composite" "Enable"' >> "$1"
echo ' Option "RENDER" "Enable"' >> "$1" echo ' Option "RENDER" "Enable"' >> "$1"
echo 'EndSection' >> "$1" echo 'EndSection' >> "$1"
echo ' ' >> "$1" echo ' ' >> "$1"
} }
MHWD_ADD_BACKSPACE() MHWD_ADD_BACKSPACE()
{ {
echo ' ' >> "$1" echo ' ' >> "$1"
echo 'Section "InputClass"' >> "$1" echo 'Section "InputClass"' >> "$1"
echo ' Identifier "Keyboard Defaults"' >> "$1" echo ' Identifier "Keyboard Defaults"' >> "$1"
echo ' MatchIsKeyboard "yes"' >> "$1" echo ' MatchIsKeyboard "yes"' >> "$1"
echo ' Option "XkbOptions" "terminate:ctrl_alt_bksp"' >> "$1" echo ' Option "XkbOptions" "terminate:ctrl_alt_bksp"' >> "$1"
echo 'EndSection' >> "$1" echo 'EndSection' >> "$1"
echo ' ' >> "$1" echo ' ' >> "$1"
} }
......
# Global variables
ARG_FB_DRIVER=""
ARG_RESOLUTION=""
# kernel_cmdline <param> <default>
# Looks for a parameter on the kernel's boot-time command line.
#
# returns: 0 if param was found. Also prints its value if it was a K=V param.
# 1 if it was not. Also prints value passed as <default>
#
kernel_cmdline()
{
for param in $(/bin/cat /proc/cmdline); do
case "${param}" in
$1=*) echo "${param##*=}"; return 0 ;;
$1) return 0 ;;
*) continue ;;
esac
done
[ -n "${2}" ] && echo "${2}"
return 1
}
init_args() {
local ARGS="$(kernel_cmdline mhwdfb):" # additional ':' if f2 isn't set -> empty string
ARG_FB_DRIVER="$(echo "${ARGS}" | cut -d: -f1)"
ARG_RESOLUTION="$(echo "${ARGS}" | cut -d: -f2)"
}
run_earlyhook()
{
init_args
if [ "${ARG_FB_DRIVER}" != "kms" ]; then
# Disable KMS modules
for module in radeon nouveau i915 via-agp sis-agp intel-agp amd64-agp ati-agp sworks-agp ali-agp amd-k7-agp nvidia-agp efficeon-agp
do
echo "blacklist ${module}" >> "/etc/modprobe.d/mhwd-kms.conf"
done
fi
}
run_latehook()
{
init_args
if [ "${ARG_FB_DRIVER}" == "uvesafb" ]; then
if [ "${ARG_RESOLUTION}" == "" ]; then
/sbin/modprobe uvesafb
else
case "${ARG_RESOLUTION}" in
*-*) ;;
*) ARG_RESOLUTION="${ARG_RESOLUTION}-32" ;;
esac
/sbin/modprobe uvesafb mode_option=${ARG_RESOLUTION}
fi
fi
}
#!/bin/bash
build() {
# Add KMS modules
add_module "radeon"
add_module "nouveau"
add_module "i915"
add_module "via-agp"
add_module "sis-agp"
add_module "intel-agp"
if [[ $(uname -m) == i686 ]]; then
add_module "amd64-agp"
add_module "ati-agp"
add_module "sworks-agp"
add_module "ali-agp"
add_module "amd-k7-agp"
add_module "nvidia-agp"
add_module "efficeon-agp"
fi
# Add uvesafb
add_module 'uvesafb'
add_binary "v86d"
add_file "/usr/lib/modprobe.d/uvesafb.conf"
add_dir "/etc/modprobe.d"
add_runscript
}
help() {
echo "This hook sets up the right framebuffer on boot."
}
# vim: set ft=sh ts=4 sw=4 expandtab:
...@@ -6,102 +6,102 @@ MHWDDEVICES=() ...@@ -6,102 +6,102 @@ MHWDDEVICES=()
MHWD_HEADING() MHWD_HEADING()
{ {
echo '##' > "$1" echo '##' > "$1"
echo '## Generated by mhwd - Manjaro Hardware Detection' >> "$1" echo '## Generated by mhwd - Manjaro Hardware Detection' >> "$1"
echo '##' >> "$1" echo '##' >> "$1"
echo ' ' >> "$1" echo ' ' >> "$1"
echo ' ' >> "$1" echo ' ' >> "$1"
} }
MHWD_IS_DEVICE() MHWD_IS_DEVICE()
{ {
local CCLASSID="$1" local CCLASSID="$1"
local CVENDORID="$2" local CVENDORID="$2"
local CDEVICEID="$3" local CDEVICEID="$3"
for device in ${MHWDDEVICES[@]}; do for device in ${MHWDDEVICES[@]}; do
while read CLASSID VENDORID DEVICEID BUSID; do while read CLASSID VENDORID DEVICEID BUSID; do
if [ "$CCLASSID" == "$CLASSID" ] && [ "$CVENDORID" == "$VENDORID" ] && [ "$CDEVICEID" == "$DEVICEID" ]; then if [ "$CCLASSID" == "$CLASSID" ] && [ "$CVENDORID" == "$VENDORID" ] && [ "$CDEVICEID" == "$DEVICEID" ]; then
return 0 return 0
fi fi
done <<< "$(echo "$device" | sed 's/|/ /g')" done <<< "$(echo "$device" | sed 's/|/ /g')"
done done
return 1 return 1
} }
MHWD_FUNC_ON_MATCH() MHWD_FUNC_ON_MATCH()
{ {
local CCLASSID="$1" local CCLASSID="$1"
local CVENDORID="$2" local CVENDORID="$2"
local CDEVICEIDS="$3" local CDEVICEIDS="$3"
local RUNFUNC="$4" local RUNFUNC="$4"
for device in ${MHWDDEVICES[@]}; do for device in ${MHWDDEVICES[@]}; do
while read CLASSID VENDORID DEVICEID BUSID; do while read CLASSID VENDORID DEVICEID BUSID; do
if [ "$CCLASSID" == "$CLASSID" ] && [ "$CVENDORID" == "$VENDORID" ]; then if [ "$CCLASSID" == "$CLASSID" ] && [ "$CVENDORID" == "$VENDORID" ]; then
for d in $CDEVICEIDS; do for d in $CDEVICEIDS; do
if [ "$d" == "$DEVICEID" ]; then if [ "$d" == "$DEVICEID" ]; then
$RUNFUNC $RUNFUNC
return return
fi fi
done done
fi fi
done <<< "$(echo "$device" | sed 's/|/ /g')" done <<< "$(echo "$device" | sed 's/|/ /g')"
done done
} }
MHWD_DEVICE_BUS_ID() MHWD_DEVICE_BUS_ID()
{ {
local CCLASSID="$1" local CCLASSID="$1"
local CVENDORID="$2" local CVENDORID="$2"
local ONLYFIRST="$3" local ONLYFIRST="$3"
for device in ${MHWDDEVICES[@]}; do for device in ${MHWDDEVICES[@]}; do
while read CLASSID VENDORID DEVICEID BUSID; do while read CLASSID VENDORID DEVICEID BUSID; do
if [ "$CVENDORID" == "*" ]; then if [ "$CVENDORID" == "*" ]; then
VENDORID="*" VENDORID="*"
fi fi
if [ "$CCLASSID" == "$CLASSID" ] && [ "$CVENDORID" == "$VENDORID" ]; then if [ "$CCLASSID" == "$CLASSID" ] && [ "$CVENDORID" == "$VENDORID" ]; then
echo "$BUSID" echo "$BUSID"
if [ "$ONLYFIRST" == "true" ] || [ "$ONLYFIRST" == "yes" ]; then if [ "$ONLYFIRST" == "true" ] || [ "$ONLYFIRST" == "yes" ]; then
return return
fi fi
fi fi
done <<< "$(echo "$device" | sed 's/|/ /g')" done <<< "$(echo "$device" | sed 's/|/ /g')"
done done
} }
MHWD_CHECK_KMODS() MHWD_CHECK_KMODS()
{ {
CONKMODS="" CONKMODS=""
DEPKMODS="" DEPKMODS=""
if [ "${CONKMOD}" != "" ]; then if [ "${CONKMOD}" != "" ]; then
for KERNEL in ${KERNELS} ; do for KERNEL in ${KERNELS} ; do
if [ "$(pacman -Qq | grep -o ${KERNEL} -m1)" != "" ]; then if [ "$(pacman -Qq | grep -o ${KERNEL} -m1)" != "" ]; then
for KMOD in ${CONKMOD} ; do for KMOD in ${CONKMOD} ; do
CONKMODS="${CONKMODS} ${KERNEL}-${KMOD}" CONKMODS="${CONKMODS} ${KERNEL}-${KMOD}"
done done
fi fi
done done
fi fi
if [ "${DEPKMOD}" != "" ]; then if [ "${DEPKMOD}" != "" ]; then
for KERNEL in ${KERNELS} ; do for KERNEL in ${KERNELS} ; do
if [ "$(pacman -Qq | grep -o ${KERNEL} -m1)" != "" ]; then if [ "$(pacman -Qq | grep -o ${KERNEL} -m1)" != "" ]; then
for KMOD in ${DEPKMOD} ; do for KMOD in ${DEPKMOD} ; do
DEPKMODS="${DEPKMODS} ${KERNEL}-${KMOD}" DEPKMODS="${DEPKMODS} ${KERNEL}-${KMOD}"
done done
fi fi
done done
fi fi
} }
MHWD_CHECK_PKGS() MHWD_CHECK_PKGS()
{ {
local REMOVEPKGS="" local REMOVEPKGS=""
for PKG in ${PACKAGES} ; do for PKG in ${PACKAGES} ; do
for RMPKG in $(pacman -Qq | grep ${PKG}) ; do for RMPKG in $(pacman -Qq | grep ${PKG}) ; do
...@@ -136,223 +136,272 @@ MHWD64CONF="/etc/mhwd-x86_64.conf" ...@@ -136,223 +136,272 @@ MHWD64CONF="/etc/mhwd-x86_64.conf"
# source lib32 true/false for x86_64 # source lib32 true/false for x86_64
if [ "${ARCH}" == "x86_64" ];then if [ "${ARCH}" == "x86_64" ];then
if [ -f ${MHWD64CONF} ];then if [ -f ${MHWD64CONF} ];then
echo "Sourcing ${MHWD64CONF}" echo "Sourcing ${MHWD64CONF}"
. ${MHWD64CONF} . ${MHWD64CONF}
else else
echo "Using default" echo "Using default"
MHWD64_IS_LIB32="true" MHWD64_IS_LIB32="true"
fi fi
echo "Has lib32 support: ${MHWD64_IS_LIB32}" echo "Has lib32 support: ${MHWD64_IS_LIB32}"
fi fi
if [ "${PARAM}" -lt 1 ]; then if [ "${PARAM}" -lt 1 ]; then
echo "No Arguments!" echo "No Arguments!"
exit 1 exit 1
fi fi
for (( I=1; $I <= $PARAM; I++ ));do for (( I=1; $I <= $PARAM; I++ ));do
case "$1" in case "$1" in
--install) --install)
INSTALL="true" INSTALL="true"
;; ;;
--remove) --remove)
REMOVE="true" REMOVE="true"
;; ;;
--sync) --sync)
SYNC="y" SYNC="y"
;; ;;
--cachedir) --cachedir)
shift shift
CACHEPATH="$1" CACHEPATH="$1"
;; ;;
--config) --config)
shift shift
CONFIGPATH="$1" CONFIGPATH="$1"
;; ;;
--pmconfig) --pmconfig)
shift shift
PMCONFIG="$1" PMCONFIG="$1"
;; ;;
--pmroot) --pmroot)
shift shift
PMROOT="$1" PMROOT="$1"
;; ;;
--device) --device)
shift shift
MHWDDEVICES+=("$1") MHWDDEVICES+=("$1")
;; ;;
"") ;; "") ;;
*) *)
echo "Wrong Argument: $1" echo "Wrong Argument: $1"
exit 1 exit 1
;; ;;
esac esac
shift shift
done done
# Set final variables # Set final variables
PACMAN="${PACMAN} --cachedir ${CACHEPATH} --config ${PMCONFIG} --root ${PMROOT}" PACMAN="${PACMAN} --cachedir ${CACHEPATH} --config ${PMCONFIG} --root ${PMROOT}"
if [ "${CONFIGPATH}" != "" ] && [ -e "${CONFIGPATH}" ]; then if [ "${CONFIGPATH}" != "" ] && [ -e "${CONFIGPATH}" ]; then
echo "Sourcing ${CONFIGPATH}" echo "Sourcing ${CONFIGPATH}"
. "${CONFIGPATH}" . "${CONFIGPATH}"
for classid in ${CLASSIDS} ; do for classid in ${CLASSIDS} ; do
echo "Processing classid: ${classid}" echo "Processing classid: ${classid}"
if [ -e "${INCLUDEPATH}/${classid}" ]; then if [ -e "${INCLUDEPATH}/${classid}" ]; then
echo "Sourcing ${INCLUDEPATH}/${classid}" echo "Sourcing ${INCLUDEPATH}/${classid}"
. "${INCLUDEPATH}/${classid}" . "${INCLUDEPATH}/${classid}"
fi fi
done done
else else
exit 1 exit 1
fi fi
if [ "${INSTALL}" == "true" ]; then if [ "${INSTALL}" == "true" ]; then
# Run preinstall function # Run preinstall function
if [ "`grep "pre_install" "${CONFIGPATH}" | cut -d"#" -f1 | cut -d"(" -f1 | grep "pre_install"`" == "pre_install" ]; then if [ "`grep "pre_install" "${CONFIGPATH}" | cut -d"#" -f1 | cut -d"(" -f1 | grep "pre_install"`" == "pre_install" ]; then
pre_install pre_install
fi fi
PACKAGES="" PACKAGES=""
# Remove conflicts # Remove conflicts
if [ "${CONFLDD}" != "" ]; then if [ "${CONFLDD}" != "" ]; then
PACKAGES="${CONFLDD}" PACKAGES="${CONFLDD}"
fi fi
if [ "${ARCH}" == "x86_64" ] && [ "${CONFLDD_64}" != "" ]; then if [ "${ARCH}" == "x86_64" ] && [ "${CONFLDD_64}" != "" ]; then
if [ "${MHWD64_IS_LIB32}" == "true" ];then if [ "${MHWD64_IS_LIB32}" == "true" ];then
PACKAGES="${PACKAGES} ${CONFLDD_64}" PACKAGES="${PACKAGES} ${CONFLDD_64}"
else else
PACKAGES="${PACKAGES}" PACKAGES="${PACKAGES}"
fi fi
fi fi
# Check if packages are installed # Check if packages are installed
MHWD_CHECK_PKGS MHWD_CHECK_PKGS
if [ "${PACKAGES}" != "" ]; then if [ "${PACKAGES}" != "" ]; then
${PACMAN} -Rdd ${PACKAGES} ${PACMAN} -Rdd ${PACKAGES}
if [ "$?" -ne "0" ]; then if [ "$?" -ne "0" ]; then
echo "Error: pacman failed!" echo "Error: pacman failed!"
exit 1 exit 1
fi fi
fi fi
PACKAGES="" PACKAGES=""
# Check for extramodules # Check for extramodules
MHWD_CHECK_KMODS MHWD_CHECK_KMODS
# Remove conflicts # Remove conflicts
if [ "${CONFLICTS}" != "" ]; then if [ "${CONFLICTS}" != "" ]; then
PACKAGES="${CONFLICTS}" PACKAGES="${CONFLICTS}"
fi fi
if [ "${ARCH}" == "i686" ] && [ "${CONFLICTS_32}" != "" ]; then if [ "${ARCH}" == "i686" ] && [ "${CONFLICTS_32}" != "" ]; then
PACKAGES="${PACKAGES} ${CONFLICTS_32}" PACKAGES="${PACKAGES} ${CONFLICTS_32}"
fi fi
if [ "${ARCH}" == "x86_64" ] && [ "${CONFLICTS_64}" != "" ]; then if [ "${ARCH}" == "x86_64" ] && [ "${CONFLICTS_64}" != "" ]; then
if [ "${MHWD64_IS_LIB32}" == "true" ];then if [ "${MHWD64_IS_LIB32}" == "true" ];then
PACKAGES="${PACKAGES} ${CONFLICTS_64}" PACKAGES="${PACKAGES} ${CONFLICTS_64}"
else else
PACKAGES="${PACKAGES}" PACKAGES="${PACKAGES}"
fi fi
fi fi
if [ "${CONKMODS}" != "" ]; then if [ "${CONKMODS}" != "" ]; then
PACKAGES="${PACKAGES} ${CONKMODS}" PACKAGES="${PACKAGES} ${CONKMODS}"
fi fi
# Check if packages are installed # Check if packages are installed
MHWD_CHECK_PKGS MHWD_CHECK_PKGS
if [ "${PACKAGES}" != "" ]; then if [ "${PACKAGES}" != "" ]; then
${PACMAN} -Rs ${PACKAGES} ${PACMAN} -Rs ${PACKAGES}
if [ "$?" -ne "0" ]; then if [ "$?" -ne "0" ]; then
echo "Error: pacman failed!" echo "Error: pacman failed!"
exit 1 exit 1
fi fi
fi fi
PACKAGES="" PACKAGES=""
# Install dependencies [ "${OPTREMDEPENDS}" != "" ] && DEPENDS="${DEPENDS} ${OPTREMDEPENDS}"
if [ "${DEPENDS}" != "" ]; then [ "${OPTREMDEPENDS_32}" != "" ] && DEPENDS_32="${DEPENDS_32} ${OPTREMDEPENDS_32}"
PACKAGES="${DEPENDS}" [ "${OPTREMDEPENDS_64}" != "" ] && DEPENDS_64="${DEPENDS_64} ${OPTREMDEPENDS_64}"
fi
if [ "${ARCH}" == "i686" ] && [ "${DEPENDS_32}" != "" ]; then # Install dependencies
PACKAGES="${PACKAGES} ${DEPENDS_32}" if [ "${DEPENDS}" != "" ]; then
fi PACKAGES="${DEPENDS}"
if [ "${ARCH}" == "x86_64" ] && [ "${DEPENDS_64}" != "" ]; then fi
if [ "${MHWD64_IS_LIB32}" == "true" ];then if [ "${ARCH}" == "i686" ] && [ "${DEPENDS_32}" != "" ]; then
PACKAGES="${PACKAGES} ${DEPENDS_64}" PACKAGES="${PACKAGES} ${DEPENDS_32}"
else fi
PACKAGES="${PACKAGES}" if [ "${ARCH}" == "x86_64" ] && [ "${DEPENDS_64}" != "" ]; then
fi if [ "${MHWD64_IS_LIB32}" == "true" ];then
fi PACKAGES="${PACKAGES} ${DEPENDS_64}"
if [ "${DEPKMODS}" != "" ]; then else
PACKAGES="${PACKAGES} ${DEPKMODS}" PACKAGES="${PACKAGES}"
fi fi
fi
if [ "${PACKAGES}" != "" ]; then if [ "${DEPKMODS}" != "" ]; then
${PACMAN} --needed -S${SYNC} ${PACKAGES} PACKAGES="${PACKAGES} ${DEPKMODS}"
if [ "$?" -ne "0" ]; then fi
echo "Error: pacman failed!"
exit 1 if [ "${PACKAGES}" != "" ]; then
fi ${PACMAN} --needed -S${SYNC} ${PACKAGES}
fi if [ "$?" -ne "0" ]; then
echo "Error: pacman failed!"
# Run postinstall function exit 1
if [ "`grep "post_install" "${CONFIGPATH}" | cut -d"#" -f1 | cut -d"(" -f1 | grep "post_install"`" == "post_install" ]; then fi
post_install ${PACMAN} -D --asexplicit ${PACKAGES}
fi if [ "$?" -ne "0" ]; then
echo "Error: pacman failed!"
exit 1
fi
elif [ "${SYNC}" != "" ]; then
${PACMAN} -S${SYNC}
fi
# Run postinstall function
if [ "`grep "post_install" "${CONFIGPATH}" | cut -d"#" -f1 | cut -d"(" -f1 | grep "post_install"`" == "post_install" ]; then
post_install
fi
fi fi
if [ "${REMOVE}" == "true" ]; then if [ "${REMOVE}" == "true" ]; then
# Run preremove function # Run preremove function
if [ "`grep "pre_remove" "${CONFIGPATH}" | cut -d"#" -f1 | cut -d"(" -f1 | grep "pre_remove"`" == "pre_remove" ]; then if [ "`grep "pre_remove" "${CONFIGPATH}" | cut -d"#" -f1 | cut -d"(" -f1 | grep "pre_remove"`" == "pre_remove" ]; then
pre_remove pre_remove
fi fi
PACKAGES="" PACKAGES=""
OPTREMPACKAGES=""
# Check for extramodules
MHWD_CHECK_KMODS # Check for extramodules
MHWD_CHECK_KMODS
# Remove dependencies
if [ "${DEPENDS}" != "" ]; then # Remove dependencies
PACKAGES="${DEPENDS}" if [ "${DEPENDS}" != "" ]; then
fi PACKAGES="${DEPENDS}"
if [ "${ARCH}" == "i686" ] && [ "${DEPENDS_32}" != "" ]; then fi
PACKAGES="${PACKAGES} ${DEPENDS_32}" if [ "${ARCH}" == "i686" ] && [ "${DEPENDS_32}" != "" ]; then
fi PACKAGES="${PACKAGES} ${DEPENDS_32}"
if [ "${ARCH}" == "x86_64" ] && [ "${DEPENDS_64}" != "" ]; then fi
if [ "${MHWD64_IS_LIB32}" == "true" ];then if [ "${ARCH}" == "x86_64" ] && [ "${DEPENDS_64}" != "" ]; then
PACKAGES="${PACKAGES} ${DEPENDS_64}" if [ "${MHWD64_IS_LIB32}" == "true" ];then
else PACKAGES="${PACKAGES} ${DEPENDS_64}"
PACKAGES="${PACKAGES}" else
fi PACKAGES="${PACKAGES}"
fi fi
if [ "${DEPKMODS}" != "" ]; then fi
PACKAGES="${PACKAGES} ${DEPKMODS}" if [ "${DEPKMODS}" != "" ]; then
fi PACKAGES="${PACKAGES} ${DEPKMODS}"
fi
# Check if packages are installed
MHWD_CHECK_PKGS
if [ "${PACKAGES}" != "" ]; then
${PACMAN} -Rs ${PACKAGES}
if [ "$?" -ne "0" ]; then
echo "Error: pacman failed!"
exit 1
fi
fi
PACKAGES=""
# Remove OPTREM dependencies
# Has to be run after normal dependencies were removed, since said dependencies may optionally depend on an OPTREM package
if [ "${OPTREMDEPENDS}" != "" ]; then
OPTREMPACKAGES="${OPTREMDEPENDS}"
fi
if [ "${ARCH}" == "i686" ] && [ "${OPTREMDEPENDS_32}" != "" ]; then
OPTREMPACKAGES="${OPTREMPACKAGES} ${OPTREMDEPENDS_32}"
fi
if [ "${ARCH}" == "x86_64" ] && [ "${OPTREMDEPENDS_64}" != "" ]; then
if [ "${MHWD64_IS_LIB32}" == "true" ]; then
OPTREMPACKAGES="${OPTREMPACKAGES} ${OPTREMDEPENDS_64}"
else
OPTREMPACKAGES="${OPTREMPACKAGES}"
fi
fi
if [ "${OPTREMPACKAGES}" != "" ]; then
${PACMAN} -D --asdeps ${OPTREMPACKAGES}
if [ "$?" -ne "0" ]; then
echo "Error: pacman failed!"
exit 1
fi
fi
# Check if packages are installed # Check if packages are installed
MHWD_CHECK_PKGS MHWD_CHECK_PKGS
if [ "${PACKAGES}" != "" ]; then if [ "${PACKAGES}" != "" ]; then
${PACMAN} -Rs ${PACKAGES} ${PACMAN} -Rs ${PACKAGES}
if [ "$?" -ne "0" ]; then if [ "$?" -ne "0" ]; then
echo "Error: pacman failed!" echo "Error: pacman failed!"
exit 1 exit 1
fi fi
fi fi
# Run postremove function # Run postremove function
if [ "`grep "post_remove" "${CONFIGPATH}" | cut -d"#" -f1 | cut -d"(" -f1 | grep "post_remove"`" == "post_remove" ]; then if [ "`grep "post_remove" "${CONFIGPATH}" | cut -d"#" -f1 | cut -d"(" -f1 | grep "post_remove"`" == "post_remove" ]; then
post_remove post_remove
fi fi
fi fi
exit 0 exit 0
#!/bin/bash
PARAM=$#
FBARG=""
FBRESOLUTION=""
GRUBDEFAULT="/etc/default/grub"
UPDATEGRUBCMD="/usr/sbin/update-grub"
MKINITCPIOCONF="/etc/mkinitcpio.conf"
check_system() {
local missing_file=""
[ ! -e "${GRUBDEFAULT}" ] && missing_file="${GRUBDEFAULT}"
[ ! -e "${UPDATEGRUBCMD}" ] && missing_file="${UPDATEGRUBCMD}"
[ ! -e "${MKINITCPIOCONF}" ] && missing_file="${MKINITCPIOCONF}"
if [ "${missing_file}" != "" ]; then
echo "warning: '${missing_file}' does not exists! Abording..."
echo ""
echo "note: mhwd-fb couldn't find grub installed on your system. mhwd-fb sets kernel arguments to tell the mhwd-fb initramfs hook which framebuffer should be loaded. Check the wiki how to add this kernel arguments manually."
exit 1
fi
# Check if mhwd-fb hook is enabled
. "${MKINITCPIOCONF}"
local found="";
for arg in ${HOOKS}
do
if [ "${arg}" == "mhwd-fb" ]; then
found="true"
break
fi
done
if [ "${found}" != "true" ]; then
echo "error: mhwd-fb hook isn't enabled! Abording..."
exit 1
fi
}
get_framebuffer_resolution() {
# Find fitting resolution if not set
[ "${FBRESOLUTION}" == "" ] && FBRESOLUTION="$(LANG=C LC_MESSAGES=C xrandr | grep \* | cut -d' ' -f4 | head -n 1)-32"
[ "${FBRESOLUTION}" == "" ] && FBRESOLUTION="$(LANG=C LC_MESSAGES=C hwinfo --framebuffer | grep -w 'Mode' | cut -d: -f2 | sed 's/^ *//g' | sed 's/ .*//g' | sort -nr | head -n 1)-32"
# Check if resolution is valid
if ! [[ "$(echo "${FBRESOLUTION}" | sed 's/-//' | sed 's/x//')" =~ ^[0-9]+$ ]] || [[ "${FBRESOLUTION}" != *[0-9]"x"[0-9]* ]]; then
echo "error: '${FBRESOLUTION}' isn't a valid framebuffer resolution!"
exit 1
fi
}
# param 1: "kms", "uvesafb" or "none"
set_framebuffer() {
echo ":: setup mhwd-fb"
. "${GRUBDEFAULT}"
local NEW_GRUB_CMDLINE_LINUX=""
for arg in ${GRUB_CMDLINE_LINUX}
do
if [[ "${arg}" != "mhwdfb="* ]]; then
NEW_GRUB_CMDLINE_LINUX="${NEW_GRUB_CMDLINE_LINUX}${arg} "
fi
done
if [ "$1" == "kms" ]; then
NEW_GRUB_CMDLINE_LINUX="${NEW_GRUB_CMDLINE_LINUX}mhwdfb=kms"
echo " using kms framebuffer"
# Enable GRUB_GFXPAYLOAD_LINUX
sed -i '/#[]*GRUB_GFXPAYLOAD_LINUX[ ]*=.*/ s/^.//' "${GRUBDEFAULT}"
elif [ "$1" == "uvesafb" ]; then
get_framebuffer_resolution
if [ ${FBRESOLUTION} == "" ]; then
NEW_GRUB_CMDLINE_LINUX="${NEW_GRUB_CMDLINE_LINUX}mhwdfb=uvesafb"
echo " using uvesafb framebuffer"
else
NEW_GRUB_CMDLINE_LINUX="${NEW_GRUB_CMDLINE_LINUX}mhwdfb=uvesafb:${FBRESOLUTION}"
echo " using uvesafb framebuffer with resolution: ${FBRESOLUTION}"
fi
# Disable GRUB_GFXPAYLOAD_LINUX
sed -i "/#/!s|GRUB_GFXPAYLOAD_LINUX[ ]*=.*|#&|g" "${GRUBDEFAULT}"
elif [ "$1" == "none" ]; then
echo " disabling mhwd-fb framebuffer option"
# Enable GRUB_GFXPAYLOAD_LINUX
sed -i '/#[]*GRUB_GFXPAYLOAD_LINUX[ ]*=.*/ s/^.//' "${GRUBDEFAULT}"
else
echo "error: invalid function argument!"
exit 1
fi
# Adjust grub default file
sed -i "/#/!s|GRUB_CMDLINE_LINUX[ ]*=.*|GRUB_CMDLINE_LINUX=\"${NEW_GRUB_CMDLINE_LINUX}\"|g" "${GRUBDEFAULT}"
# Update grub configuration file
echo ""
echo ":: update-grub output:"
${UPDATEGRUBCMD}
if [ $? != 0 ]; then
echo "error: grub-update failed!"
exit 1
fi
}
print_status() {
. "${GRUBDEFAULT}"
local FB_DRIVER=""
local FB_RESOLUTION=""
for arg in ${GRUB_CMDLINE_LINUX}
do
if [[ "${arg}" == "mhwdfb="* ]]; then
arg="$(echo "${arg}" | cut -d= -f2)"
FB_DRIVER="$(echo "${arg}" | cut -d: -f1)"
FB_RESOLUTION="$(echo "${arg}:" | cut -d: -f2)" # additional ':' if f2 isn't set -> empty string
break;
fi
done
if [ "${FB_DRIVER}" != "kms" ] && [ "${FB_DRIVER}" != "uvesafb" ] && [ "${FB_DRIVER}" != "" ]; then
echo "warning: set mhwd-fb driver is invalid: '${FB_DRIVER}'"
exit 1
elif [ "${FB_DRIVER}" == "" ]; then
FB_DRIVER="disabled"
FB_RESOLUTION="-"
else
[ "${FB_RESOLUTION}" == "" ] && FB_RESOLUTION="auto"
fi
echo ":: current mhwd-fb state"
echo -e " framebuffer:\t${FB_DRIVER}"
echo -e " resolution:\t${FB_RESOLUTION}"
}
print_help() {
echo "mhwd-fb [OPTION] [...]"
echo ""
echo " --help show help"
echo " --status show current status"
echo " --setfb [kms/uvesafb/none] set framebuffer"
echo " --setres [resolution] set uvesafb resolution. ex.: 1440x900 or 1440x900-32"
echo ""
echo "note: mhwd-fb sets kernel arguments to tell the mhwd-fb initramfs hook which framebuffer should be loaded. mhwd-fb requires an installed grub which is configured to this system to work. Otherwise check the wiki how to add mhwd-fb kernel arguments manually."
echo ""
}
if [ "${PARAM}" -lt 1 ]; then
print_status
exit 0
fi
for (( I=1; $I <= $PARAM; I++ ))
do
case "$1" in
--help)
print_help
exit 0
;;
--setfb)
shift
FBARG="$1"
;;
--setres)
shift
FBRESOLUTION="$1"
;;
--status)
print_status
exit 0
;;
"") ;;
*)
echo "error: invalid argument: $1"
echo ""
print_help
exit 1
;;
esac
shift
done
# Check root
if [[ $EUID -ne 0 ]]; then
echo "error: you cannot perform this operation unless you are root." 1>&2
exit 1
fi
# Check system
check_system
# Set framebuffer
if [ "${FBARG}" != "" ]; then
if [ "${FBARG}" != "kms" ] && [ "${FBARG}" != "uvesafb" ] && [ "${FBARG}" != "none" ]; then
echo "error: invalid argument '${FBARG}'"
exit 1
fi
set_framebuffer "${FBARG}"
fi
exit 0
...@@ -5,288 +5,123 @@ ...@@ -5,288 +5,123 @@
PARAM=$# PARAM=$#
MHWDXORGCONF="/etc/X11/xorg.conf.d/90-mhwd.conf" MHWDXORGCONF="/etc/X11/xorg.conf.d/90-mhwd.conf"
CHECKCONFIG="false" CHECKCONFIG="false"
SETGL=""
SETXORGCONF="" SETXORGCONF=""
SETMOD=""
ARCH=$(uname -m) ARCH=$(uname -m)
MODULES_LOAD="/etc/modules-load.d" MODULES_LOAD="/etc/modules-load.d"
# lib32 config true/false
MHWD64CONF="/etc/mhwd-x86_64.conf"
# source lib32 true/false for x86_64
if [ "${ARCH}" == "x86_64" ];then
if [ -f ${MHWD64CONF} ];then
echo "Sourcing ${MHWD64CONF}"
. ${MHWD64CONF}
else
echo "Using default"
MHWD64_IS_LIB32="true"
fi
DEFAULT_IS_LIB32=${MHWD64_IS_LIB32}
echo "Default lib32 support: ${DEFAULT_IS_LIB32}"
fi
# param 1: modules to load # param 1: modules to load
# param 2: blacklisted modules # param 2: blacklisted modules
set_modules() { set_modules() {
echo "##" > "/etc/modprobe.d/mhwd-gpu.conf" echo "##" > "/etc/modprobe.d/mhwd-gpu.conf"
echo "## Generated by mhwd - Manjaro Hardware Detection" >> "/etc/modprobe.d/mhwd-gpu.conf" echo "## Generated by mhwd - Manjaro Hardware Detection" >> "/etc/modprobe.d/mhwd-gpu.conf"
echo "##" >> "/etc/modprobe.d/mhwd-gpu.conf" echo "##" >> "/etc/modprobe.d/mhwd-gpu.conf"
echo " " >> "/etc/modprobe.d/mhwd-gpu.conf" echo " " >> "/etc/modprobe.d/mhwd-gpu.conf"
for module in $2 for module in $2
do do
echo "blacklist ${module}" >> "/etc/modprobe.d/mhwd-gpu.conf" echo "blacklist ${module}" >> "/etc/modprobe.d/mhwd-gpu.conf"
# Unload module if X is not running # Unload module if X is not running
if [ ! "$(pgrep X)" ]; then if [ ! "$(pgrep X)" ]; then
rmmod -f ${module} rmmod -f ${module}
fi fi
done done
echo "##" > "${MODULES_LOAD}/mhwd-gpu.conf" echo "##" > "${MODULES_LOAD}/mhwd-gpu.conf"
echo "## Generated by mhwd - Manjaro Hardware Detection" >> "${MODULES_LOAD}/mhwd-gpu.conf" echo "## Generated by mhwd - Manjaro Hardware Detection" >> "${MODULES_LOAD}/mhwd-gpu.conf"
echo "##" >> "${MODULES_LOAD}/mhwd-gpu.conf" echo "##" >> "${MODULES_LOAD}/mhwd-gpu.conf"
echo " " >> "${MODULES_LOAD}/mhwd-gpu.conf" echo " " >> "${MODULES_LOAD}/mhwd-gpu.conf"
for module in $1 for module in $1
do do
echo "${module}" >> "${MODULES_LOAD}/mhwd-gpu.conf" echo "${module}" >> "${MODULES_LOAD}/mhwd-gpu.conf"
# Load module if X is not running # Load module if X is not running
if [ ! "$(pgrep X)" ]; then if [ ! "$(pgrep X)" ]; then
modprobe ${module} modprobe ${module}
fi fi
done done
} }
# param 1: Xorg configuration file # param 1: Xorg configuration file
set_xorg() set_xorg()
{ {
if [ -e "${MHWDXORGCONF}" ]; then if [ -e "${MHWDXORGCONF}" ]; then
rm "${MHWDXORGCONF}" rm "${MHWDXORGCONF}"
fi fi
if [ -e "$1" ]; then if [ -e "$1" ]; then
ln -sf "$1" "${MHWDXORGCONF}" ln -sf "$1" "${MHWDXORGCONF}"
echo "xorg configuration file: '$1'" echo "xorg configuration file: '$1'"
else else
echo "warning: could not find '$1'!" echo "warning: could not find '$1'!"
fi fi
}
# param 1: libGl path
# param 2: libGLESv1 path
# param 3: libGLESv2 path
# param 4: libEGL path
# param 5: libglx path
# optional param 6: lib32 libGl path
# optional param 7: lib32 libGLESv1 path
# optional param 8: lib32 libGLESv2 path
# optional param 9: lib32 libEGL path
set_Gl() {
if [ -e "$1" ]; then
ln -sf "$1" /usr/lib/libGL.so
ln -sf "$1" /usr/lib/libGL.so.1
ln -sf "$1" /usr/lib/libGL.so.1.2.0
echo "libGl: '$1'"
else
echo "warning: could not find '$1'!"
fi
if [ -e "$2" ]; then
ln -sf "$2" /usr/lib/libGLESv1_CM.so
ln -sf "$2" /usr/lib/libGLESv1_CM.so.1
ln -sf "$2" /usr/lib/libGLESv1_CM.so.1.1.0
echo "libGLESv1: '$2'"
else
echo "warning: could not find '$2'!"
fi
if [ -e "$3" ]; then
ln -sf "$3" /usr/lib/libGLESv2.so
ln -sf "$3" /usr/lib/libGLESv2.so.2
ln -sf "$3" /usr/lib/libGLESv2.so.2.0.0
echo "libGLESv2: '$3'"
else
echo "warning: could not find '$3'!"
fi
if [ -e "$4" ]; then
ln -sf "$4" /usr/lib/libEGL.so
ln -sf "$4" /usr/lib/libEGL.so.1
ln -sf "$4" /usr/lib/libEGL.so.1.0.0
echo "libEGL: '$4'"
else
echo "warning: could not find '$4'!"
fi
if [ "${MHWD64_IS_LIB32}" == "true" ];then
if [ -e "$6" ]; then
ln -sf "$6" /usr/lib32/libGL.so
ln -sf "$6" /usr/lib32/libGL.so.1
ln -sf "$6" /usr/lib32/libGL.so.1.2.0
echo "lib32-libGl: '$6'"
fi
if [ -e "$7" ]; then
ln -sf "$7" /usr/lib32/libGLESv1_CM.so
ln -sf "$7" /usr/lib32/libGLESv1_CM.so.1
ln -sf "$7" /usr/lib32/libGLESv1_CM.so.1.1.0
echo "lib32-libGLESv1: '$7'"
fi
if [ -e "$8" ]; then
ln -sf "$8" /usr/lib32/libGLESv2.so
ln -sf "$8" /usr/lib32/libGLESv2.so.2
ln -sf "$8" /usr/lib32/libGLESv2.so.2.0.0
echo "lib32-libGLESv2: '$8'"
fi
if [ -e "$9" ]; then
ln -sf "$9" /usr/lib32/libEGL.so
ln -sf "$9" /usr/lib32/libEGL.so.1
ln -sf "$9" /usr/lib32/libEGL.so.1.0.0
echo "lib32-libEGL: '$9'"
fi
fi
if [ -e "$5" ]; then
ln -sf "$5" /usr/lib/xorg/modules/extensions/libglx.so
echo "libglx: '$5'"
else
echo "warning: could not find '$5'!"
fi
}
# param 1: true/false
set_lib32(){
echo "Saving lib32 setting: ${MHWD64CONF}"
echo 'MHWD64_IS_LIB32="'$1'"' > ${MHWD64CONF}
echo "Has lib32 support: $1"
} }
print_link_destination_if_exists() print_link_destination_if_exists()
{ {
if [ -e "$1" ]; then if [ -e "$1" ]; then
echo "$2 '$(readlink "$1")'" echo "$2 '$(readlink "$1")'"
else else
echo "warning: could not find '$1'!" echo "warning: could not find '$1'!"
fi fi
} }
print_status() print_status()
{ {
echo ":: status" echo ":: status"
if [ "${MHWD64_IS_LIB32}" == "true" ];then print_link_destination_if_exists "${MHWDXORGCONF}" " xorg configuration file:"
print_link_destination_if_exists "/usr/lib32/libGL.so" " lib32-libGl:"
print_link_destination_if_exists "/usr/lib32/libGLESv1_CM.so" " lib32-libGLESv1:"
print_link_destination_if_exists "/usr/lib32/libGLESv2.so" " lib32-libGLESv2:"
print_link_destination_if_exists "/usr/lib32/libEGL.so" " lib32-libEGL:"
fi
print_link_destination_if_exists "/usr/lib/libGL.so" " libGl:"
print_link_destination_if_exists "/usr/lib/libGLESv1_CM.so" " libGLESv1:"
print_link_destination_if_exists "/usr/lib/libGLESv2.so" " libGLESv2:"
print_link_destination_if_exists "/usr/lib/libEGL.so" " libEGL:"
print_link_destination_if_exists "/usr/lib/xorg/modules/extensions/libglx.so" " libglx:"
print_link_destination_if_exists "${MHWDXORGCONF}" " xorg configuration file:"
} }
print_help() print_help()
{ {
echo "mhwd-gpu [OPTION] [...]" echo "mhwd-gpu [OPTION] [...]"
echo "" echo ""
echo " --help show help" echo " --help show help"
echo " --status show current status" echo " --status show current status"
echo " --check check for invalid symlinks and repair" echo " --check check for invalid symlinks and repair"
echo " --setgl [mesa/nvidia/catalyst] set libgl and libglx" echo " --setxorg [PATH] set xorg configuration file"
echo " --setxorg [PATH] set xorg configuration file" echo " --setmod [nvidia/catalyst] set modules"
echo ""
if [ "${ARCH}" == "x86_64" ];then
echo " --setlib32 [true/false] set lib32 support"
fi
echo ""
} }
if [ "${PARAM}" -lt 1 ]; then if [ "${PARAM}" -lt 1 ]; then
print_status print_status
exit 0 exit 0
fi fi
if [ "${ARCH}" == "x86_64" ];then for (( I=1; $I <= $PARAM; I++ ));do
for (( I=1; $I <= $PARAM; I++ ));do case "$1" in
case "$1" in --help)
--help) print_help
print_help exit 0
exit 0 ;;
;; --status)
--status) print_status
print_status exit 0
exit 0 ;;
;; --check)
--check) CHECKCONFIG="true"
CHECKCONFIG="true" ;;
;; --setxorg)
--setgl) shift
shift SETXORGCONF="$1"
SETGL="$1" ;;
;; --setmod)
--setxorg) shift
shift SETMOD="$1"
SETXORGCONF="$1" ;;
;; "") ;;
--setlib32) *)
shift echo "error: invalid argument: $1"
MHWD64_IS_LIB32="$1" echo ""
;; print_help
"") ;; exit 1
*) ;;
echo "error: invalid argument: $1" esac
echo ""
print_help shift
exit 1 done
;;
esac
shift
done
else
for (( I=1; $I <= $PARAM; I++ ));do
case "$1" in
--help)
print_help
exit 0
;;
--status)
print_status
exit 0
;;
--check)
CHECKCONFIG="true"
;;
--setgl)
shift
SETGL="$1"
;;
--setxorg)
shift
SETXORGCONF="$1"
;;
"") ;;
*)
echo "error: invalid argument: $1"
echo ""
print_help
exit 1
;;
esac
shift
done
fi
# Check root # Check root
if [[ $EUID -ne 0 ]]; then if [[ $EUID -ne 0 ]]; then
...@@ -294,105 +129,27 @@ if [[ $EUID -ne 0 ]]; then ...@@ -294,105 +129,27 @@ if [[ $EUID -ne 0 ]]; then
exit 1 exit 1
fi fi
if [ "${DEFAULT_IS_LIB32}" != "${MHWD64_IS_LIB32}" ];then # Set Modules
if [ "${MHWD64_IS_LIB32}" == "true" ] || [ "${MHWD64_IS_LIB32}" == "false" ]; then if [ "${SETMOD}" == "nvidia" ]; then
set_lib32 "${MHWD64_IS_LIB32}" set_modules "nvidia" "nouveau ttm drm_kms_helper drm"
fi elif [ "${SETMOD}" == "catalyst" ] || [ "${SETMOD}" == "ati" ]; then
fi set_modules "fglrx" "radeon"
elif [ "${SETMOD}" != "" ]; then
# Set libGl and libglx echo "error: invalid argument '${SETMOD}'"
if [ "${SETGL}" == "mesa" ] || [ "${SETGL}" == "default" ]; then exit 1
set_modules
set_Gl "/usr/lib/mesa/libGL.so.1.2.0" \
"/usr/lib/mesa/libGLESv1_CM.so.1.1.0" \
"/usr/lib/mesa/libGLESv2.so.2.0.0" \
"/usr/lib/mesa/libEGL.so.1.0.0" \
"/usr/lib/xorg/modules/extensions/libglx.xorg" \
"/usr/lib32/mesa/libGL.so.1.2.0" \
"/usr/lib32/mesa/libGLESv1_CM.so.1.1.0" \
"/usr/lib32/mesa/libGLESv2.so.2.0.0" \
"/usr/lib32/mesa/libEGL.so.1.0.0"
elif [ "${SETGL}" == "nvidia" ]; then
set_modules "nvidia" "nouveau ttm drm_kms_helper drm"
set_Gl "/usr/lib/nvidia/libGL.so" \
"/usr/lib/nvidia/libGLESv1_CM.so" \
"/usr/lib/nvidia/libGLESv2.so" \
"/usr/lib/nvidia/libEGL.so" \
"/usr/lib/nvidia/xorg/modules/extensions/libglx.so" \
"/usr/lib32/nvidia/libGL.so" \
"/usr/lib32/nvidia/libGLESv1_CM.so" \
"/usr/lib32/nvidia/libGLESv2.so" \
"/usr/lib32/nvidia/libEGL.so"
elif [ "${SETGL}" == "catalyst" ] || [ "${SETGL}" == "ati" ]; then
set_modules "fglrx" "radeon"
set_Gl "/usr/lib/fglrx/libGL.so" \
"/usr/lib/fglrx/libGLESv1_CM.so" \
"/usr/lib/fglrx/libGLESv2.so" \
"/usr/lib/fglrx/libEGL.so" \
"/usr/lib/fglrx/xorg/modules/extensions/libglx.so" \
"/usr/lib32/fglrx/libGL.so" \
"/usr/lib32/fglrx/libGLESv1_CM.so" \
"/usr/lib32/fglrx/libGLESv2.so" \
"/usr/lib32/fglrx/libEGL.so"
elif [ "${SETGL}" != "" ]; then
echo "error: invalid argument '${SETGL}'"
exit 1
fi fi
# Set xorg configuration file # Set xorg configuration file
if [ "${SETXORGCONF}" != "" ]; then if [ "${SETXORGCONF}" != "" ]; then
set_xorg "${SETXORGCONF}" set_xorg "${SETXORGCONF}"
fi fi
# Check config # Check config
if [ "${CHECKCONFIG}" == "true" ]; then if [ "${CHECKCONFIG}" == "true" ]; then
if [ -L "${MHWDXORGCONF}" -a ! -e "${MHWDXORGCONF}" ]; then if [ -L "${MHWDXORGCONF}" -a ! -e "${MHWDXORGCONF}" ]; then
echo "'${MHWDXORGCONF}' symlink is invalid! Removing it..." echo "'${MHWDXORGCONF}' symlink is invalid! Removing it..."
rm "${MHWDXORGCONF}" rm "${MHWDXORGCONF}"
elif [ -e "${MHWDXORGCONF}" ]; then elif [ -e "${MHWDXORGCONF}" ]; then
echo "xorg configuration symlink valid..." echo "xorg configuration symlink valid..."
fi fi
if [ "${MHWD64_IS_LIB32}" == "true" ];then
if [ ! -e "/usr/lib/libGL.so" ] || [ ! -e "/usr/lib/xorg/modules/extensions/libglx.so" ] || \
[ ! -e "/usr/lib/libGLESv1_CM.so" ] || [ ! -e "/usr/lib/libGLESv2.so" ] || [ ! -e "/usr/lib/libEGL.so" ] || \
[ -L "/usr/lib32/libGL.so" -a ! -e "/usr/lib32/libGL.so" ] || \
[ -e "/usr/lib32/mesa/libGL.so.1.2.0" -a ! -e "/usr/lib32/libGL.so" ] || \
[ -L "/usr/lib32/libGLESv1_CM.so" -a ! -e "/usr/lib32/libGLESv1_CM.so" ] || \
[ -e "/usr/lib32/mesa/libGLESv1_CM.so.1.1.0" -a ! -e "/usr/lib32/libGLESv1_CM.so" ] || \
[ -L "/usr/lib32/libGLESv2.so" -a ! -e "/usr/lib32/libGLESv2.so" ] || \
[ -e "/usr/lib32/mesa/libGLESv2.so.2.0.0" -a ! -e "/usr/lib32/libGLESv2.so" ] || \
[ -L "/usr/lib32/libEGL.so" -a ! -e "/usr/lib32/libEGL.so" ] || \
[ -e "/usr/lib32/mesa/libEGL.so.1.0.0" -a ! -e "/usr/lib32/libEGL.so" ]; then
echo "libGl and libglx symlinks are invalid!"
echo "Falling back to default..."
set_modules
set_Gl "/usr/lib/mesa/libGL.so.1.2.0" \
"/usr/lib/mesa/libGLESv1_CM.so.1.1.0" \
"/usr/lib/mesa/libGLESv2.so.2.0.0" \
"/usr/lib/mesa/libEGL.so.1.0.0" \
"/usr/lib/xorg/modules/extensions/libglx.xorg" \
"/usr/lib32/mesa/libGL.so.1.2.0" \
"/usr/lib32/mesa/libGLESv1_CM.so.1.1.0" \
"/usr/lib32/mesa/libGLESv2.so.2.0.0" \
"/usr/lib32/mesa/libEGL.so.1.0.0"
else
echo "libGl and libglx symlinks valid..."
fi
else
if [ ! -e "/usr/lib/libGL.so" ] || [ ! -e "/usr/lib/xorg/modules/extensions/libglx.so" ] || \
[ ! -e "/usr/lib/libGLESv1_CM.so" ] || [ ! -e "/usr/lib/libGLESv2.so" ] || \
[ ! -e "/usr/lib/libEGL.so" ]; then
echo "libGl and libglx symlinks are invalid!"
echo "Falling back to default..."
set_modules
set_Gl "/usr/lib/mesa/libGL.so.1.2.0" \
"/usr/lib/mesa/libGLESv1_CM.so.1.1.0" \
"/usr/lib/mesa/libGLESv2.so.2.0.0" \
"/usr/lib/mesa/libEGL.so.1.0.0" \
"/usr/lib/xorg/modules/extensions/libglx.xorg"
else
echo "libGl and libglx symlinks valid..."
fi
fi
fi fi
...@@ -9,7 +9,7 @@ args_check() { ...@@ -9,7 +9,7 @@ args_check() {
} }
err() { err() {
echo "Error: $1" 1>&2; exit 1 printf "\e[31mError:\e[0m $1\n" 1>&2; exit 1
} }
kernel_usage() { kernel_usage() {
...@@ -21,24 +21,38 @@ kernel_usage() { ...@@ -21,24 +21,38 @@ kernel_usage() {
-r --remove Remove a kernel [kernel(s)]" -r --remove Remove a kernel [kernel(s)]"
} }
update_grub() {
# Update grub configuration file
echo ""
echo ":: grub-mkconfig output:"
grub-mkconfig -o /boot/grub/grub.cfg
# workaround for https://git.savannah.gnu.org/cgit/grub.git/commit/?id=3cf2e848bc03c44d30bb87e583d12efe7e7ccf75
# if grub is not updated in MBR/EFI dashes still won't work, hence we remove them
sed -i -e '/cryptomount -u/ {s/-//g;s/ u/ -u/g}' /boot/grub/grub.cfg
if [ $? != 0 ]; then
echo "error: grub-mkconfig failed!"
exit 1
fi
}
kernel_install() { kernel_install() {
pkginstall=() pkginstall=()
rmc=0 rmc=0
for kernel in "$@"; do for kernel in "$@"; do
[[ $kernel = "rmc" ]] && rmc=1 && continue [[ $kernel = "rmc" ]] && rmc=1 && continue
[[ $kernel != linux[0-9][0-9]?([0-9]) && $kernel != "rmc" ]] && err "Invalid argument (use -h for help)." [[ $kernel != linux[0-9][0-9]?([0-9]) && $kernel != linux[0-9][0-9]?([0-9])-rt && $kernel != "rmc" ]] && err "Invalid argument.\nPlease choose one of the $(kernel_repo)"
[[ $kernel != linux[0-9][0-9]?([0-9]) ]] && err "Please enter a valid kernel name."
[[ $current = $kernel ]] && err "You can't reinstall your current kernel. Please use 'pacman -Syu' instead to update." [[ $current = $kernel ]] && err "You can't reinstall your current kernel. Please use 'pacman -Syu' instead to update."
[[ -z $(pacman -Ssq "^$kernel$") ]] && err "Please make sure if the given kernel(s) exist(s)." [[ -z $(pacman -Ssq "^$kernel$") ]] && err "Please make sure if the given kernel(s) exist(s).\n$(kernel_repo)"
for pkg in $(pacman -Qqs "$current"); do for pkg in $(pacman -Qqs "$current"); do
pkg=${pkg//$current/$kernel} pkg=${pkg//$current/$kernel}
[[ -n $(pacman -Ssq "^$pkg$") ]] && pkginstall+=("$pkg") [[ -n $(pacman -Ssq "^$pkg$" | grep -E "^$pkg$|^$pkg-\S+$") ]] && pkginstall+=("$pkg")
done done
done done
pacman -Syy pacman -Sy
outofdate="$(pacman -Qqu | tr '\n' ' ')" outofdate="$(pacman -Qqu | tr '\n' ' ')"
if [[ -n $outofdate ]]; then if [[ -n $outofdate ]]; then
...@@ -51,34 +65,40 @@ kernel_install() { ...@@ -51,34 +65,40 @@ kernel_install() {
[[ $rmc = 1 && $? = 0 ]] && pacman -R $(pacman -Qqs $current) [[ $rmc = 1 && $? = 0 ]] && pacman -R $(pacman -Qqs $current)
[[ $rmc = 1 && $? != 0 ]] && { echo ""; err "'rmc' aborted because the kernel failed to install or canceled on removal."; } [[ $rmc = 1 && $? != 0 ]] && { echo ""; err "'rmc' aborted because the kernel failed to install or canceled on removal."; }
[[ ! -e "/usr/bin/update-grub" && -e "/usr/bin/grub-mkconfig" ]] && update_grub
} }
kernel_repo() { kernel_repo() {
echo "Available kernels:" printf "\e[32mavailable kernels:\e[0m\n"
pacman -Ss "^linux[0-9][0-9]?([0-9])$" | grep core | while read -r; do echo " * ${REPLY:5:8}"; done pacman -Ssq "^linux[0-9][0-9]?([0-9])$" | while read -r; do echo " * $REPLY"; done
pacman -Ssq "^linux[0-9][0-9]?([0-9])-rt$" | while read -r; do echo " * $REPLY"; done
} }
kernel_list() { kernel_list() {
echo "Currently running: $(uname -r) (${current})" printf "\e[32mCurrently running:\e[0m $(uname -r) (${current})\n"
echo "The following kernels are installed in your system:" echo "The following kernels are installed in your system:"
pacman -Qqs "^linux[0-9][0-9]?([0-9])$" | while read -r; do echo " * $REPLY"; done pacman -Qqs "^linux[0-9][0-9]?([0-9])$" | while read -r; do echo " * $REPLY"; done
pacman -Qqs "^linux[0-9][0-9]?([0-9])-rt$" | while read -r; do echo " * $REPLY"; done
} }
kernel_remove() { kernel_remove() {
pkgremove=() pkgremove=()
for kernel in "$@"; do for kernel in "$@"; do
[[ -z "$kernel" ]] && err "Invalid argument (use -h for help)." [[ -z "$kernel" ]] && err "Invalid argument (use -h for help)."
[[ $kernel != linux[0-9][0-9]?([0-9]) ]] && err "Please enter a valid kernel name." [[ $kernel != linux[0-9][0-9]?([0-9]) && $kernel != linux[0-9][0-9]?([0-9])-rt ]] && err "Please enter a valid kernel name.\n$(kernel_list)"
[[ $current = $kernel ]] && err "You can't remove your current kernel." [[ $current = $kernel ]] && err "You can't remove your current kernel."
[[ -z $(pacman -Qqs "^$1$") ]] && err "Kernel not installed." [[ -z $(pacman -Qqs "^$1$") ]] && err "Kernel not installed.\n$(kernel_list)"
for pkg in $(pacman -Qqs "$kernel"); do for pkg in $(pacman -Qqs "$kernel" | grep -E "^$kernel$|^$kernel-\S+$"); do
pkgremove+=("$pkg") pkgremove+=("$pkg")
done done
done done
pacman -R "${pkgremove[@]}" pacman -R "${pkgremove[@]}"
[[ ! -e "/usr/bin/update-grub" && -e "/usr/bin/grub-mkconfig" ]] && update_grub
} }
IFS=. read -r major minor _ <<< "$(uname -r)" IFS=. read -r major minor _ <<< "$(uname -r)"
...@@ -105,6 +125,3 @@ case "$1" in ...@@ -105,6 +125,3 @@ case "$1" in
-*) err "Invalid argument (use -h for help)." ;; -*) err "Invalid argument (use -h for help)." ;;
*) err "No arguments given (use -h for help)." ;; *) err "No arguments given (use -h for help)." ;;
esac esac
...@@ -5,22 +5,22 @@ include_directories(. ${mhwd_SOURCE_DIR}/libmhwd) ...@@ -5,22 +5,22 @@ include_directories(. ${mhwd_SOURCE_DIR}/libmhwd)
### ###
set( HEADERS set( HEADERS
Config.hpp Config.hpp
Data.hpp ConsoleWriter.hpp
Device.hpp Data.hpp
Enums.hpp Device.hpp
Mhwd.hpp Enums.hpp
Printer.hpp Mhwd.hpp
Transaction.hpp Transaction.hpp
) )
set( SOURCES set( SOURCES
Config.cpp Config.cpp
ConsoleWriter.cpp
Data.cpp Data.cpp
Device.cpp Device.cpp
main.cpp main.cpp
Mhwd.cpp Mhwd.cpp
Printer.cpp
Transaction.cpp Transaction.cpp
) )
......
/* /*
* This file is part of the mhwd - Manjaro Hardware Detection project
*
* mhwd - Manjaro Hardware Detection * mhwd - Manjaro Hardware Detection
* Roland Singer <roland@manjaro.org> * Roland Singer <roland@manjaro.org>
* Łukasz Matysiak <december0123@gmail.com> * Łukasz Matysiak <december0123@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
* *
* Copyright (C) 2007 Free Software Foundation, Inc. * Copyright (C) 2012 - 2016 Manjaro (http://manjaro.org)
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -19,28 +22,23 @@ ...@@ -19,28 +22,23 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "Config.hpp"
#include "Utils.hpp"
#include <fstream> #include <fstream>
#include <string> #include <string>
#include <vector> #include <vector>
#include "Config.hpp"
Config::Config(std::string configPath, std::string type) Config::Config(std::string configPath, std::string type)
: type_(type), basePath_(configPath.substr(0, configPath.find_last_of('/'))), : type_(type), basePath_(configPath.substr(0, configPath.find_last_of('/'))),
configPath_(configPath) configPath_(configPath), hwdIDs_(1)
{ {}
if (hwdIDs_.empty())
{
Config::HardwareID hwdID;
hwdIDs_.push_back(hwdID);
}
}
bool Config::readConfigFile(std::string configPath) bool Config::readConfigFile(std::string configPath)
{ {
std::ifstream file(configPath.c_str()); std::ifstream file(configPath);
if (!file.is_open()) if (!file)
{ {
return false; return false;
} }
...@@ -108,91 +106,72 @@ bool Config::readConfigFile(std::string configPath) ...@@ -108,91 +106,72 @@ bool Config::readConfigFile(std::string configPath)
} }
} }
if (key == "include") switch(MhwdUtils::hash(std::string(key).c_str()))
{ {
readConfigFile(getRightConfigPath(value, basePath_)); case MhwdUtils::hash_compile_time("include"):
} readConfigFile(getRightConfigPath(value, basePath_));
else if (key == "name") break;
{ case MhwdUtils::hash_compile_time("name"):
name_ = value.toLower(); name_ = value.toLower();
} break;
else if (key == "version") case MhwdUtils::hash_compile_time("version"):
{ version_ = value;
version_ = value; break;
} case MhwdUtils::hash_compile_time("info"):
else if (key == "info") info_ = value;
{ break;
info_ = value; case MhwdUtils::hash_compile_time("priority"):
} priority_ = value.convert<int>();
else if (key == "priority") break;
{ case MhwdUtils::hash_compile_time("freedriver"):
priority_ = value.convert<int>(); value = value.toLower();
} freedriver_ = value == "false" ? false : true;
else if (key == "freedriver") break;
{ case MhwdUtils::hash_compile_time("classids"):
value = value.toLower(); // Add new HardwareIDs group to vector if vector is not empty
if (!hwdIDs_.back().classIDs.empty())
if (value == "false") {
{ Config::HardwareID hwdID;
freedriver_ = false; hwdIDs_.push_back(hwdID);
} }
else if (value == "true")
{
freedriver_ = true;
}
}
else if (key == "classids")
{
// Add new HardwareIDs group to vector if vector is not empty
if (!hwdIDs_.back().classIDs.empty())
{
Config::HardwareID hwdID;
hwdIDs_.push_back(hwdID);
}
hwdIDs_.back().classIDs = splitValue(value); hwdIDs_.back().classIDs = splitValue(value);
} break;
else if (key == "vendorids") case MhwdUtils::hash_compile_time("vendorids"):
{ // Add new HardwareIDs group to vector if vector is not empty
// Add new HardwareIDs group to vector if vector is not empty if (!hwdIDs_.back().vendorIDs.empty())
if (!hwdIDs_.back().vendorIDs.empty()) {
{ Config::HardwareID hwdID;
Config::HardwareID hwdID; hwdIDs_.push_back(hwdID);
hwdIDs_.push_back(hwdID); }
}
hwdIDs_.back().vendorIDs = splitValue(value); hwdIDs_.back().vendorIDs = splitValue(value);
} break;
else if (key == "deviceids") case MhwdUtils::hash_compile_time("deviceids"):
{ // Add new HardwareIDs group to vector if vector is not empty
// Add new HardwareIDs group to vector if vector is not empty if (!hwdIDs_.back().deviceIDs.empty())
if (!hwdIDs_.back().deviceIDs.empty()) {
{ Config::HardwareID hwdID;
Config::HardwareID hwdID; hwdIDs_.push_back(hwdID);
hwdIDs_.push_back(hwdID); }
}
hwdIDs_.back().deviceIDs = splitValue(value); hwdIDs_.back().deviceIDs = splitValue(value);
} break;
else if (key == "blacklistedclassids") case MhwdUtils::hash_compile_time("blacklistedclassids"):
{ hwdIDs_.back().blacklistedClassIDs = splitValue(value);
hwdIDs_.back().blacklistedClassIDs = splitValue(value); break;
} case MhwdUtils::hash_compile_time("blacklistedvendorids"):
else if (key == "blacklistedvendorids") hwdIDs_.back().blacklistedVendorIDs = splitValue(value);
{ break;
hwdIDs_.back().blacklistedVendorIDs = splitValue(value); case MhwdUtils::hash_compile_time("blacklisteddeviceids"):
} hwdIDs_.back().blacklistedDeviceIDs = splitValue(value);
else if (key == "blacklisteddeviceids") break;
{ case MhwdUtils::hash_compile_time("mhwddepends"):
hwdIDs_.back().blacklistedDeviceIDs = splitValue(value); dependencies_ = splitValue(value);
} break;
else if (key == "mhwddepends") case MhwdUtils::hash_compile_time("mhwdconflicts"):
{ conflicts_ = splitValue(value);
dependencies_ = splitValue(value); break;
}
else if (key == "mhwdconflicts")
{
conflicts_ = splitValue(value);
} }
} }
...@@ -216,12 +195,7 @@ bool Config::readConfigFile(std::string configPath) ...@@ -216,12 +195,7 @@ bool Config::readConfigFile(std::string configPath)
} }
} }
if (name_.empty()) return ! name_.empty();
{
return false;
}
return true;
} }
std::vector<std::string> Config::splitValue(Vita::string str, Vita::string onlyEnding) std::vector<std::string> Config::splitValue(Vita::string str, Vita::string onlyEnding)
......
/* /*
* This file is part of the mhwd - Manjaro Hardware Detection project
*
* mhwd - Manjaro Hardware Detection * mhwd - Manjaro Hardware Detection
* Roland Singer <roland@manjaro.org> * Roland Singer <roland@manjaro.org>
* Łukasz Matysiak <december0123@gmail.com> * Łukasz Matysiak <december0123@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
* *
* Copyright (C) 2007 Free Software Foundation, Inc. * Copyright (C) 2012 - 2016 Manjaro (http://manjaro.org)
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
......
/* /*
* This file is part of the mhwd - Manjaro Hardware Detection project
*
* mhwd - Manjaro Hardware Detection * mhwd - Manjaro Hardware Detection
* Roland Singer <roland@manjaro.org> * Roland Singer <roland@manjaro.org>
* Łukasz Matysiak <december0123@gmail.com> * Łukasz Matysiak <december0123@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
* *
* Copyright (C) 2007 Free Software Foundation, Inc. * Copyright (C) 2012 - 2016 Manjaro (http://manjaro.org)
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -19,68 +22,72 @@ ...@@ -19,68 +22,72 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "ConsoleWriter.hpp"
#include <hd.h>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
#include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
#include "Printer.hpp" void ConsoleWriter::printStatus(std::string statusMsg) const
void Printer::printStatus(std::string statusMsg) const
{ {
std::cout << CONSOLE_MESSAGE_COLOR << "> " std::cout << CONSOLE_RED_MESSAGE_COLOR << "> "
<< CONSOLE_COLOR_RESET << statusMsg << std::endl; << CONSOLE_COLOR_RESET << statusMsg << std::endl;
} }
void Printer::printError(std::string errorMsg) const void ConsoleWriter::printError(std::string errorMsg) const
{ {
std::cout << CONSOLE_MESSAGE_COLOR << "Error: " std::cout << CONSOLE_RED_MESSAGE_COLOR << "Error: "
<< CONSOLE_COLOR_RESET << errorMsg << std::endl; << CONSOLE_COLOR_RESET << errorMsg << std::endl;
} }
void Printer::printWarning(std::string warningMsg) const void ConsoleWriter::printWarning(std::string warningMsg) const
{ {
std::cout << CONSOLE_MESSAGE_COLOR << "Warning: " std::cout << CONSOLE_RED_MESSAGE_COLOR << "Warning: "
<< CONSOLE_COLOR_RESET << warningMsg << std::endl; << CONSOLE_COLOR_RESET << warningMsg << std::endl;
} }
void Printer::printMessage(MHWD::MESSAGETYPE type, std::string msg) const void ConsoleWriter::printMessage(MHWD::MESSAGETYPE type, std::string msg) const
{ {
switch(type) switch(type)
{ {
case MHWD::MESSAGETYPE::CONSOLE_OUTPUT: case MHWD::MESSAGETYPE::CONSOLE_OUTPUT:
std::cout << CONSOLE_TEXT_OUTPUT_COLOR << msg << CONSOLE_COLOR_RESET; std::cout << CONSOLE_TEXT_OUTPUT_COLOR << msg << CONSOLE_COLOR_RESET;
break; break;
case MHWD::MESSAGETYPE::INSTALLDEPENDENCY_START: case MHWD::MESSAGETYPE::INSTALLDEPENDENCY_START:
printStatus("Installing dependency " + msg + "..."); printStatus("Installing dependency " + msg + "...");
break; break;
case MHWD::MESSAGETYPE::INSTALLDEPENDENCY_END: case MHWD::MESSAGETYPE::INSTALLDEPENDENCY_END:
printStatus("Successfully installed dependency " + msg); printStatus("Successfully installed dependency " + msg);
break; break;
case MHWD::MESSAGETYPE::INSTALL_START: case MHWD::MESSAGETYPE::INSTALL_START:
printStatus("Installing " + msg + "..."); printStatus("Installing " + msg + "...");
break; break;
case MHWD::MESSAGETYPE::INSTALL_END: case MHWD::MESSAGETYPE::INSTALL_END:
printStatus("Successfully installed " + msg); printStatus("Successfully installed " + msg);
break; break;
case MHWD::MESSAGETYPE::REMOVE_START: case MHWD::MESSAGETYPE::REMOVE_START:
printStatus("Removing " + msg + "..."); printStatus("Removing " + msg + "...");
break; break;
case MHWD::MESSAGETYPE::REMOVE_END: case MHWD::MESSAGETYPE::REMOVE_END:
printStatus("Successfully removed " + msg); printStatus("Successfully removed " + msg);
break; break;
default: default:
printError("You shouldn't see this?! Unknown message type!"); printError("You shouldn't see this?! Unknown message type!");
break; break;
} }
} }
void Printer::printHelp() const void ConsoleWriter::printHelp() const
{ {
std::cout << "Usage: mhwd [OPTIONS] <config(s)>\n\n" std::cout << "Usage: mhwd [OPTIONS] <config(s)>\n\n"
<< " --pci\t\t\t\t\tlist only pci devices and driver configs\n" << " --pci\t\t\t\t\tlist only pci devices and driver configs\n"
<< " --usb\t\t\t\t\tlist only usb devices and driver configs\n" << " --usb\t\t\t\t\tlist only usb devices and driver configs\n"
<< " -h/--help\t\t\t\tshow help\n" << " -h/--help\t\t\t\tshow help\n"
<< " -v/--version\t\t\t\tshow version of mhwd\n"
<< " -f/--force\t\t\t\tforce reinstallation\n" << " -f/--force\t\t\t\tforce reinstallation\n"
<< " -d/--detail\t\t\t\tshow detailed info for -l/-li/-lh\n" << " -d/--detail\t\t\t\tshow detailed info for -l/-li/-lh\n"
<< " -l/--list\t\t\t\tlist available configs for devices\n" << " -l/--list\t\t\t\tlist available configs for devices\n"
...@@ -96,7 +103,16 @@ void Printer::printHelp() const ...@@ -96,7 +103,16 @@ void Printer::printHelp() const
<< " --pmroot <path>\t\t\tset package manager root\n" << std::endl; << " --pmroot <path>\t\t\tset package manager root\n" << std::endl;
} }
void Printer::listDevices(const std::vector<std::shared_ptr<Device>>& devices, std::string type) const void ConsoleWriter::printVersion(std::string& versionMhwd, std::string& yearCopy) const
{
std::cout << "Manjaro Hardware Detection v"<< versionMhwd <<"\n\n"
<< "Copyright (C) "<< yearCopy <<" Manjaro Linux Developers\n"
<< "This is free software licensed under GNU GPL v3.0\n"
<< "FITNESS FOR A PARTICULAR PURPOSE.\n"
<< std::endl;
}
void ConsoleWriter::listDevices(const std::vector<std::shared_ptr<Device>>& devices, std::string type) const
{ {
if (devices.empty()) if (devices.empty())
{ {
...@@ -126,7 +142,7 @@ void Printer::listDevices(const std::vector<std::shared_ptr<Device>>& devices, s ...@@ -126,7 +142,7 @@ void Printer::listDevices(const std::vector<std::shared_ptr<Device>>& devices, s
} }
} }
void Printer::listConfigs(const std::vector<std::shared_ptr<Config>>& configs, std::string header) const void ConsoleWriter::listConfigs(const std::vector<std::shared_ptr<Config>>& configs, std::string header) const
{ {
printStatus(header); printStatus(header);
printLine(); printLine();
...@@ -145,7 +161,7 @@ void Printer::listConfigs(const std::vector<std::shared_ptr<Config>>& configs, s ...@@ -145,7 +161,7 @@ void Printer::listConfigs(const std::vector<std::shared_ptr<Config>>& configs, s
std::cout << std::endl << std::endl; std::cout << std::endl << std::endl;
} }
void Printer::printAvailableConfigsInDetail(const std::string& deviceType, void ConsoleWriter::printAvailableConfigsInDetail(const std::string& deviceType,
const std::vector<std::shared_ptr<Device>>& devices) const const std::vector<std::shared_ptr<Device>>& devices) const
{ {
bool configFound = false; bool configFound = false;
...@@ -195,7 +211,7 @@ void Printer::printAvailableConfigsInDetail(const std::string& deviceType, ...@@ -195,7 +211,7 @@ void Printer::printAvailableConfigsInDetail(const std::string& deviceType,
} }
} }
void Printer::printInstalledConfigs(const std::string& deviceType, void ConsoleWriter::printInstalledConfigs(const std::string& deviceType,
const std::vector<std::shared_ptr<Config>>& installedConfigs) const const std::vector<std::shared_ptr<Config>>& installedConfigs) const
{ {
if (installedConfigs.empty()) if (installedConfigs.empty())
...@@ -212,7 +228,7 @@ void Printer::printInstalledConfigs(const std::string& deviceType, ...@@ -212,7 +228,7 @@ void Printer::printInstalledConfigs(const std::string& deviceType,
} }
} }
void Printer::printConfigDetails(const Config& config) const void ConsoleWriter::printConfigDetails(const Config& config) const
{ {
std::string classids; std::string classids;
std::string vendorids; std::string vendorids;
...@@ -251,7 +267,21 @@ void Printer::printConfigDetails(const Config& config) const ...@@ -251,7 +267,21 @@ void Printer::printConfigDetails(const Config& config) const
<< "\n VENDORIDS:\t" << vendorids << "\n" << std::endl; << "\n VENDORIDS:\t" << vendorids << "\n" << std::endl;
} }
void Printer::printLine() const void ConsoleWriter::printLine() const
{
std::cout << std::string(80, '-') << std::endl;
}
void ConsoleWriter::printDeviceDetails(hw_item hw, FILE *f) const
{ {
std::cout << std::setfill('-') << std::setw(80) << "-" << std::setfill(' ') << std::endl; std::unique_ptr<hd_data_t> hd_data{new hd_data_t()};
hd_t *hd = hd_list(hd_data.get(), hw, 1, nullptr);
for (hd_t* hdIter = hd; hdIter; hdIter = hdIter->next)
{
hd_dump_entry(hd_data.get(), hdIter, f);
}
hd_free_hd_list(hd);
hd_free_hd_data(hd_data.get());
} }
/* /*
* This file is part of the mhwd - Manjaro Hardware Detection project
*
* mhwd - Manjaro Hardware Detection * mhwd - Manjaro Hardware Detection
* Roland Singer <roland@manjaro.org> * Roland Singer <roland@manjaro.org>
* Łukasz Matysiak <december0123@gmail.com> * Łukasz Matysiak <december0123@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
* *
* Copyright (C) 2007 Free Software Foundation, Inc. * Copyright (C) 2012 - 2016 Manjaro (http://manjaro.org)
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -22,6 +25,8 @@ ...@@ -22,6 +25,8 @@
#ifndef PRINTER_HPP_ #ifndef PRINTER_HPP_
#define PRINTER_HPP_ #define PRINTER_HPP_
#include <hd.h>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -29,7 +34,7 @@ ...@@ -29,7 +34,7 @@
#include "Device.hpp" #include "Device.hpp"
#include "Enums.hpp" #include "Enums.hpp"
class Printer class ConsoleWriter
{ {
public: public:
void printStatus(std::string statusMsg) const; void printStatus(std::string statusMsg) const;
...@@ -37,7 +42,9 @@ public: ...@@ -37,7 +42,9 @@ public:
void printWarning(std::string warningMsg) const; void printWarning(std::string warningMsg) const;
void printMessage(MHWD::MESSAGETYPE type, std::string str) const; void printMessage(MHWD::MESSAGETYPE type, std::string str) const;
void printHelp() const; void printHelp() const;
void listDevices(const std::vector<std::shared_ptr<Device>>& devices, std::string typeOfDevice) const; void printVersion(std::string& versionMhwd, std::string& yearCopy) const;
void listDevices(const std::vector<std::shared_ptr<Device>>& devices,
std::string typeOfDevice) const;
void listConfigs(const std::vector<std::shared_ptr<Config>>& configs, void listConfigs(const std::vector<std::shared_ptr<Config>>& configs,
std::string header) const; std::string header) const;
void printAvailableConfigsInDetail(const std::string& deviceType, void printAvailableConfigsInDetail(const std::string& deviceType,
...@@ -45,11 +52,12 @@ public: ...@@ -45,11 +52,12 @@ public:
void printInstalledConfigs(const std::string& deviceType, void printInstalledConfigs(const std::string& deviceType,
const std::vector<std::shared_ptr<Config>>& installedConfigs) const; const std::vector<std::shared_ptr<Config>>& installedConfigs) const;
void printConfigDetails(const Config& config) const; void printConfigDetails(const Config& config) const;
void printDeviceDetails(hw_item hw, FILE *f = stdout) const;
private: private:
void printLine() const; void printLine() const;
const char* CONSOLE_COLOR_RESET {"\033[m"}; const char* CONSOLE_COLOR_RESET {"\033[m"};
const char* CONSOLE_MESSAGE_COLOR {"\033[1m\033[31m"}; const char* CONSOLE_RED_MESSAGE_COLOR {"\033[1m\033[31m"};
const char* CONSOLE_TEXT_OUTPUT_COLOR {"\033[0;32m"}; const char* CONSOLE_TEXT_OUTPUT_COLOR {"\033[0;32m"};
}; };
......
This diff is collapsed.
/* /*
* This file is part of the mhwd - Manjaro Hardware Detection project
*
* mhwd - Manjaro Hardware Detection * mhwd - Manjaro Hardware Detection
* Roland Singer <roland@manjaro.org> * Roland Singer <roland@manjaro.org>
* Łukasz Matysiak <december0123@gmail.com> * Łukasz Matysiak <december0123@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
* *
* Copyright (C) 2007 Free Software Foundation, Inc. * Copyright (C) 2012 - 2024 Manjaro (http://manjaro.org)
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -29,18 +32,21 @@ ...@@ -29,18 +32,21 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
#include <cstdint>
#include "Config.hpp" #include "Config.hpp"
#include "Device.hpp"
#include "const.h" #include "const.h"
#include "Device.hpp"
#include "vita/string.hpp" #include "vita/string.hpp"
class Data { class Data
{
public: public:
Data(); Data();
~Data(); ~Data() = default;
struct Environment { struct Environment
{
std::string PMCachePath {MHWD_PM_CACHE_DIR}; std::string PMCachePath {MHWD_PM_CACHE_DIR};
std::string PMConfigPath {MHWD_PM_CONFIG}; std::string PMConfigPath {MHWD_PM_CONFIG};
std::string PMRootPath {MHWD_PM_ROOT}; std::string PMRootPath {MHWD_PM_ROOT};
...@@ -58,7 +64,6 @@ public: ...@@ -58,7 +64,6 @@ public:
void updateInstalledConfigData(); void updateInstalledConfigData();
void getAllDevicesOfConfig(std::shared_ptr<Config> config, std::vector<std::shared_ptr<Device>>& foundDevices); void getAllDevicesOfConfig(std::shared_ptr<Config> config, std::vector<std::shared_ptr<Device>>& foundDevices);
bool fillConfig(std::shared_ptr<Config> config, std::string configPath, std::string type);
std::vector<std::shared_ptr<Config>> getAllDependenciesToInstall(std::shared_ptr<Config> config); std::vector<std::shared_ptr<Config>> getAllDependenciesToInstall(std::shared_ptr<Config> config);
void getAllDependenciesToInstall(std::shared_ptr<Config> config, void getAllDependenciesToInstall(std::shared_ptr<Config> config,
...@@ -73,18 +78,17 @@ private: ...@@ -73,18 +78,17 @@ private:
void getAllDevicesOfConfig(const std::vector<std::shared_ptr<Device>>& devices, void getAllDevicesOfConfig(const std::vector<std::shared_ptr<Device>>& devices,
std::shared_ptr<Config> config, std::vector<std::shared_ptr<Device>>& foundDevices); std::shared_ptr<Config> config, std::vector<std::shared_ptr<Device>>& foundDevices);
void fillInstalledConfigs(std::string type); void fillInstalledConfigs(std::string type);
void fillDevices(std::string type); void fillDevices(hw_item hw, std::vector<std::shared_ptr<Device>>& devices);
void fillAllConfigs(std::string type); void fillAllConfigs(std::string type);
void setMatchingConfigs(const std::vector<std::shared_ptr<Device>>& devices, void setMatchingConfigs(const std::vector<std::shared_ptr<Device>>& devices,
std::vector<std::shared_ptr<Config>>& configs, bool setAsInstalled); std::vector<std::shared_ptr<Config>>& configs, bool setAsInstalled);
void setMatchingConfig(std::shared_ptr<Config> config, const std::vector<std::shared_ptr<Device>>& devices, void setMatchingConfig(std::shared_ptr<Config> config, const std::vector<std::shared_ptr<Device>>& devices,
bool setAsInstalled); bool setAsInstalled);
void addConfigSorted(std::vector<std::shared_ptr<Config>>& configs, std::shared_ptr<Config> config); void addConfigSorted(std::vector<std::shared_ptr<Config>>& configs, std::shared_ptr<Config> newConfig);
std::vector<std::string> getRecursiveDirectoryFileList(const std::string& directoryPath, std::vector<std::string> getRecursiveDirectoryFileList(const std::string& directoryPath,
std::string onlyFilename = ""); std::string onlyFilename = "");
Vita::string getRightConfigPath(Vita::string str, Vita::string baseConfigPath); Vita::string getRightConfigPath(Vita::string str, Vita::string baseConfigPath);
std::vector<std::string> splitValue(Vita::string str, Vita::string onlyEnding = "");
void updateConfigData(); void updateConfigData();
Vita::string from_Hex(uint16_t hexnum, int fill); Vita::string from_Hex(uint16_t hexnum, int fill);
......