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:
Roland Singer <roland@manjaro.org>
Code refactoring:
Ł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
INSTALL(PROGRAMS mhwd-kernel
DESTINATION /usr/bin)
INSTALL(PROGRAMS mhwd-fb
DESTINATION /usr/bin)
FILE(GLOB INCLUDEFILES "include/*")
INSTALL(PROGRAMS ${INCLUDEFILES}
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="..."
DEPENDS_64="lib32-..."
DEPKMOD="..."
# Optional remove dependencies
OPTREMDEPENDS="..."
OPTREMDEPENDS_32="..."
OPTREMDEPENDS_64="lib32-..."
# Conflicts
MHWDCONFLICTS="..."
......
......@@ -7,85 +7,85 @@ IDENTIFIERCOUNT=0
MHWD_ADD_DEVICE_SECTION_FOR_EACH_BUSID()
{
local XORGDRIVER="$1"
local XORGFILE="$2"
local VENDORID="$3"
local PCIBUSIDS=""
local XORGDRIVER="$1"
local XORGFILE="$2"
local VENDORID="$3"
local PCIBUSIDS=""
if [ "$VENDORID" != "" ]; then
PCIBUSIDS="$(MHWD_DEVICE_BUS_ID "0300" "$VENDORID" "false")"
fi
if [ "$VENDORID" != "" ]; then
PCIBUSIDS="$(MHWD_DEVICE_BUS_ID "0300" "$VENDORID" "false")"
fi
if [ "$PCIBUSIDS" == "" ]; then
MHWD_ADD_DEVICE_SECTION "$XORGDRIVER" "$XORGFILE" "$4"
return
fi
if [ "$PCIBUSIDS" == "" ]; then
MHWD_ADD_DEVICE_SECTION "$XORGDRIVER" "$XORGFILE" "$4"
return
fi
while read BUSID; do
MHWD_ADD_DEVICE_SECTION "$XORGDRIVER" "$XORGFILE" "BusID \"PCI:$BUSID\"|$4"
done <<< "$(echo "$PCIBUSIDS")"
while read BUSID; do
MHWD_ADD_DEVICE_SECTION "$XORGDRIVER" "$XORGFILE" "BusID \"PCI:$BUSID\"|$4"
done <<< "$(echo "$PCIBUSIDS")"
}
MHWD_ADD_DEVICE_SECTION()
{
local XORGDRIVER="$1"
local XORGFILE="$2"
local XORGDRIVER="$1"
local XORGFILE="$2"
echo 'Section "Device"' >> "$XORGFILE"
echo " Identifier \"Device${IDENTIFIERCOUNT}\"" >> "$XORGFILE"
echo " Driver \"$XORGDRIVER\"" >> "$XORGFILE"
echo 'Section "Device"' >> "$XORGFILE"
echo " Identifier \"Device${IDENTIFIERCOUNT}\"" >> "$XORGFILE"
echo " Driver \"$XORGDRIVER\"" >> "$XORGFILE"
IFS='|'
for i in $3; do
echo " $i" >> "$XORGFILE"
done
unset IFS
IFS='|'
for i in $3; do
echo " $i" >> "$XORGFILE"
done
unset IFS
echo 'EndSection' >> "$XORGFILE"
echo ' ' >> "$XORGFILE"
echo 'EndSection' >> "$XORGFILE"
echo ' ' >> "$XORGFILE"
IDENTIFIERCOUNT=$[IDENTIFIERCOUNT + 1]
IDENTIFIERCOUNT=$[IDENTIFIERCOUNT + 1]
}
MHWD_ADD_DRI()
{
# only for free drivers
sed -i /'Section "Device"'/,/'EndSection'/s/'EndSection'/"\tOption \"DRI\" \"true\"\nEndSection"/g "$1"
echo ' ' >> "$1"
echo 'Section "DRI"' >> "$1"
echo ' Group "video"' >> "$1"
echo ' Mode 0666' >> "$1"
echo 'EndSection' >> "$1"
echo ' ' >> "$1"
# only for free drivers
sed -i /'Section "Device"'/,/'EndSection'/s/'EndSection'/"\tOption \"DRI\" \"true\"\nEndSection"/g "$1"
echo ' ' >> "$1"
echo 'Section "DRI"' >> "$1"
echo ' Group "video"' >> "$1"
echo ' Mode 0666' >> "$1"
echo 'EndSection' >> "$1"
echo ' ' >> "$1"
}
MHWD_ADD_COMPOSITING()
{
echo ' ' >> "$1"
echo 'Section "Extensions"' >> "$1"
echo ' Option "Composite" "Enable"' >> "$1"
echo ' Option "RENDER" "Enable"' >> "$1"
echo 'EndSection' >> "$1"
echo ' ' >> "$1"
echo ' ' >> "$1"
echo 'Section "Extensions"' >> "$1"
echo ' Option "Composite" "Enable"' >> "$1"
echo ' Option "RENDER" "Enable"' >> "$1"
echo 'EndSection' >> "$1"
echo ' ' >> "$1"
}
MHWD_ADD_BACKSPACE()
{
echo ' ' >> "$1"
echo 'Section "InputClass"' >> "$1"
echo ' Identifier "Keyboard Defaults"' >> "$1"
echo ' MatchIsKeyboard "yes"' >> "$1"
echo ' Option "XkbOptions" "terminate:ctrl_alt_bksp"' >> "$1"
echo 'EndSection' >> "$1"
echo ' ' >> "$1"
echo ' ' >> "$1"
echo 'Section "InputClass"' >> "$1"
echo ' Identifier "Keyboard Defaults"' >> "$1"
echo ' MatchIsKeyboard "yes"' >> "$1"
echo ' Option "XkbOptions" "terminate:ctrl_alt_bksp"' >> "$1"
echo 'EndSection' >> "$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=()
MHWD_HEADING()
{
echo '##' > "$1"
echo '## Generated by mhwd - Manjaro Hardware Detection' >> "$1"
echo '##' >> "$1"
echo ' ' >> "$1"
echo ' ' >> "$1"
echo '##' > "$1"
echo '## Generated by mhwd - Manjaro Hardware Detection' >> "$1"
echo '##' >> "$1"
echo ' ' >> "$1"
echo ' ' >> "$1"
}
MHWD_IS_DEVICE()
{
local CCLASSID="$1"
local CVENDORID="$2"
local CDEVICEID="$3"
for device in ${MHWDDEVICES[@]}; do
while read CLASSID VENDORID DEVICEID BUSID; do
if [ "$CCLASSID" == "$CLASSID" ] && [ "$CVENDORID" == "$VENDORID" ] && [ "$CDEVICEID" == "$DEVICEID" ]; then
return 0
fi
done <<< "$(echo "$device" | sed 's/|/ /g')"
done
return 1
local CCLASSID="$1"
local CVENDORID="$2"
local CDEVICEID="$3"
for device in ${MHWDDEVICES[@]}; do
while read CLASSID VENDORID DEVICEID BUSID; do
if [ "$CCLASSID" == "$CLASSID" ] && [ "$CVENDORID" == "$VENDORID" ] && [ "$CDEVICEID" == "$DEVICEID" ]; then
return 0
fi
done <<< "$(echo "$device" | sed 's/|/ /g')"
done
return 1
}
MHWD_FUNC_ON_MATCH()
{
local CCLASSID="$1"
local CVENDORID="$2"
local CDEVICEIDS="$3"
local RUNFUNC="$4"
for device in ${MHWDDEVICES[@]}; do
while read CLASSID VENDORID DEVICEID BUSID; do
if [ "$CCLASSID" == "$CLASSID" ] && [ "$CVENDORID" == "$VENDORID" ]; then
for d in $CDEVICEIDS; do
if [ "$d" == "$DEVICEID" ]; then
$RUNFUNC
return
fi
done
fi
done <<< "$(echo "$device" | sed 's/|/ /g')"
done
local CCLASSID="$1"
local CVENDORID="$2"
local CDEVICEIDS="$3"
local RUNFUNC="$4"
for device in ${MHWDDEVICES[@]}; do
while read CLASSID VENDORID DEVICEID BUSID; do
if [ "$CCLASSID" == "$CLASSID" ] && [ "$CVENDORID" == "$VENDORID" ]; then
for d in $CDEVICEIDS; do
if [ "$d" == "$DEVICEID" ]; then
$RUNFUNC
return
fi
done
fi
done <<< "$(echo "$device" | sed 's/|/ /g')"
done
}
MHWD_DEVICE_BUS_ID()
{
local CCLASSID="$1"
local CVENDORID="$2"
local ONLYFIRST="$3"
for device in ${MHWDDEVICES[@]}; do
while read CLASSID VENDORID DEVICEID BUSID; do
if [ "$CVENDORID" == "*" ]; then
VENDORID="*"
fi
if [ "$CCLASSID" == "$CLASSID" ] && [ "$CVENDORID" == "$VENDORID" ]; then
echo "$BUSID"
if [ "$ONLYFIRST" == "true" ] || [ "$ONLYFIRST" == "yes" ]; then
return
fi
fi
done <<< "$(echo "$device" | sed 's/|/ /g')"
done
local CCLASSID="$1"
local CVENDORID="$2"
local ONLYFIRST="$3"
for device in ${MHWDDEVICES[@]}; do
while read CLASSID VENDORID DEVICEID BUSID; do
if [ "$CVENDORID" == "*" ]; then
VENDORID="*"
fi
if [ "$CCLASSID" == "$CLASSID" ] && [ "$CVENDORID" == "$VENDORID" ]; then
echo "$BUSID"
if [ "$ONLYFIRST" == "true" ] || [ "$ONLYFIRST" == "yes" ]; then
return
fi
fi
done <<< "$(echo "$device" | sed 's/|/ /g')"
done
}
MHWD_CHECK_KMODS()
{
CONKMODS=""
DEPKMODS=""
if [ "${CONKMOD}" != "" ]; then
for KERNEL in ${KERNELS} ; do
if [ "$(pacman -Qq | grep -o ${KERNEL} -m1)" != "" ]; then
for KMOD in ${CONKMOD} ; do
CONKMODS="${CONKMODS} ${KERNEL}-${KMOD}"
done
fi
done
fi
if [ "${DEPKMOD}" != "" ]; then
for KERNEL in ${KERNELS} ; do
if [ "$(pacman -Qq | grep -o ${KERNEL} -m1)" != "" ]; then
for KMOD in ${DEPKMOD} ; do
DEPKMODS="${DEPKMODS} ${KERNEL}-${KMOD}"
done
fi
done
fi
CONKMODS=""
DEPKMODS=""
if [ "${CONKMOD}" != "" ]; then
for KERNEL in ${KERNELS} ; do
if [ "$(pacman -Qq | grep -o ${KERNEL} -m1)" != "" ]; then
for KMOD in ${CONKMOD} ; do
CONKMODS="${CONKMODS} ${KERNEL}-${KMOD}"
done
fi
done
fi
if [ "${DEPKMOD}" != "" ]; then
for KERNEL in ${KERNELS} ; do
if [ "$(pacman -Qq | grep -o ${KERNEL} -m1)" != "" ]; then
for KMOD in ${DEPKMOD} ; do
DEPKMODS="${DEPKMODS} ${KERNEL}-${KMOD}"
done
fi
done
fi
}
MHWD_CHECK_PKGS()
{
local REMOVEPKGS=""
local REMOVEPKGS=""
for PKG in ${PACKAGES} ; do
for RMPKG in $(pacman -Qq | grep ${PKG}) ; do
......@@ -136,223 +136,272 @@ 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
echo "Has lib32 support: ${MHWD64_IS_LIB32}"
if [ -f ${MHWD64CONF} ];then
echo "Sourcing ${MHWD64CONF}"
. ${MHWD64CONF}
else
echo "Using default"
MHWD64_IS_LIB32="true"
fi
echo "Has lib32 support: ${MHWD64_IS_LIB32}"
fi
if [ "${PARAM}" -lt 1 ]; then
echo "No Arguments!"
exit 1
echo "No Arguments!"
exit 1
fi
for (( I=1; $I <= $PARAM; I++ ));do
case "$1" in
--install)
INSTALL="true"
;;
--remove)
REMOVE="true"
;;
--sync)
SYNC="y"
;;
--cachedir)
shift
CACHEPATH="$1"
;;
--config)
shift
CONFIGPATH="$1"
;;
--pmconfig)
shift
PMCONFIG="$1"
;;
--pmroot)
shift
PMROOT="$1"
;;
--device)
shift
MHWDDEVICES+=("$1")
;;
"") ;;
*)
echo "Wrong Argument: $1"
exit 1
;;
esac
shift
case "$1" in
--install)
INSTALL="true"
;;
--remove)
REMOVE="true"
;;
--sync)
SYNC="y"
;;
--cachedir)
shift
CACHEPATH="$1"
;;
--config)
shift
CONFIGPATH="$1"
;;
--pmconfig)
shift
PMCONFIG="$1"
;;
--pmroot)
shift
PMROOT="$1"
;;
--device)
shift
MHWDDEVICES+=("$1")
;;
"") ;;
*)
echo "Wrong Argument: $1"
exit 1
;;
esac
shift
done
# Set final variables
PACMAN="${PACMAN} --cachedir ${CACHEPATH} --config ${PMCONFIG} --root ${PMROOT}"
if [ "${CONFIGPATH}" != "" ] && [ -e "${CONFIGPATH}" ]; then
echo "Sourcing ${CONFIGPATH}"
. "${CONFIGPATH}"
for classid in ${CLASSIDS} ; do
echo "Processing classid: ${classid}"
if [ -e "${INCLUDEPATH}/${classid}" ]; then
echo "Sourcing ${INCLUDEPATH}/${classid}"
. "${INCLUDEPATH}/${classid}"
fi
done
echo "Sourcing ${CONFIGPATH}"
. "${CONFIGPATH}"
for classid in ${CLASSIDS} ; do
echo "Processing classid: ${classid}"
if [ -e "${INCLUDEPATH}/${classid}" ]; then
echo "Sourcing ${INCLUDEPATH}/${classid}"
. "${INCLUDEPATH}/${classid}"
fi
done
else
exit 1
exit 1
fi
if [ "${INSTALL}" == "true" ]; then
# Run preinstall function
if [ "`grep "pre_install" "${CONFIGPATH}" | cut -d"#" -f1 | cut -d"(" -f1 | grep "pre_install"`" == "pre_install" ]; then
pre_install
fi
PACKAGES=""
# Remove conflicts
if [ "${CONFLDD}" != "" ]; then
PACKAGES="${CONFLDD}"
fi
if [ "${ARCH}" == "x86_64" ] && [ "${CONFLDD_64}" != "" ]; then
if [ "${MHWD64_IS_LIB32}" == "true" ];then
PACKAGES="${PACKAGES} ${CONFLDD_64}"
else
PACKAGES="${PACKAGES}"
fi
fi
# Run preinstall function
if [ "`grep "pre_install" "${CONFIGPATH}" | cut -d"#" -f1 | cut -d"(" -f1 | grep "pre_install"`" == "pre_install" ]; then
pre_install
fi
PACKAGES=""
# Remove conflicts
if [ "${CONFLDD}" != "" ]; then
PACKAGES="${CONFLDD}"
fi
if [ "${ARCH}" == "x86_64" ] && [ "${CONFLDD_64}" != "" ]; then
if [ "${MHWD64_IS_LIB32}" == "true" ];then
PACKAGES="${PACKAGES} ${CONFLDD_64}"
else
PACKAGES="${PACKAGES}"
fi
fi
# Check if packages are installed
MHWD_CHECK_PKGS
if [ "${PACKAGES}" != "" ]; then
${PACMAN} -Rdd ${PACKAGES}
if [ "$?" -ne "0" ]; then
echo "Error: pacman failed!"
exit 1
fi
fi
PACKAGES=""
# Check for extramodules
MHWD_CHECK_KMODS
# Remove conflicts
if [ "${CONFLICTS}" != "" ]; then
PACKAGES="${CONFLICTS}"
fi
if [ "${ARCH}" == "i686" ] && [ "${CONFLICTS_32}" != "" ]; then
PACKAGES="${PACKAGES} ${CONFLICTS_32}"
fi
if [ "${ARCH}" == "x86_64" ] && [ "${CONFLICTS_64}" != "" ]; then
if [ "${MHWD64_IS_LIB32}" == "true" ];then
PACKAGES="${PACKAGES} ${CONFLICTS_64}"
else
PACKAGES="${PACKAGES}"
fi
fi
if [ "${CONKMODS}" != "" ]; then
PACKAGES="${PACKAGES} ${CONKMODS}"
fi
if [ "${PACKAGES}" != "" ]; then
${PACMAN} -Rdd ${PACKAGES}
if [ "$?" -ne "0" ]; then
echo "Error: pacman failed!"
exit 1
fi
fi
PACKAGES=""
# Check for extramodules
MHWD_CHECK_KMODS
# Remove conflicts
if [ "${CONFLICTS}" != "" ]; then
PACKAGES="${CONFLICTS}"
fi
if [ "${ARCH}" == "i686" ] && [ "${CONFLICTS_32}" != "" ]; then
PACKAGES="${PACKAGES} ${CONFLICTS_32}"
fi
if [ "${ARCH}" == "x86_64" ] && [ "${CONFLICTS_64}" != "" ]; then
if [ "${MHWD64_IS_LIB32}" == "true" ];then
PACKAGES="${PACKAGES} ${CONFLICTS_64}"
else
PACKAGES="${PACKAGES}"
fi
fi
if [ "${CONKMODS}" != "" ]; then
PACKAGES="${PACKAGES} ${CONKMODS}"
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=""
# Install dependencies
if [ "${DEPENDS}" != "" ]; then
PACKAGES="${DEPENDS}"
fi
if [ "${ARCH}" == "i686" ] && [ "${DEPENDS_32}" != "" ]; then
PACKAGES="${PACKAGES} ${DEPENDS_32}"
fi
if [ "${ARCH}" == "x86_64" ] && [ "${DEPENDS_64}" != "" ]; then
if [ "${MHWD64_IS_LIB32}" == "true" ];then
PACKAGES="${PACKAGES} ${DEPENDS_64}"
else
PACKAGES="${PACKAGES}"
fi
fi
if [ "${DEPKMODS}" != "" ]; then
PACKAGES="${PACKAGES} ${DEPKMODS}"
fi
if [ "${PACKAGES}" != "" ]; then
${PACMAN} --needed -S${SYNC} ${PACKAGES}
if [ "$?" -ne "0" ]; then
echo "Error: pacman failed!"
exit 1
fi
fi
# Run postinstall function
if [ "`grep "post_install" "${CONFIGPATH}" | cut -d"#" -f1 | cut -d"(" -f1 | grep "post_install"`" == "post_install" ]; then
post_install
fi
if [ "${PACKAGES}" != "" ]; then
${PACMAN} -Rs ${PACKAGES}
if [ "$?" -ne "0" ]; then
echo "Error: pacman failed!"
exit 1
fi
fi
PACKAGES=""
[ "${OPTREMDEPENDS}" != "" ] && DEPENDS="${DEPENDS} ${OPTREMDEPENDS}"
[ "${OPTREMDEPENDS_32}" != "" ] && DEPENDS_32="${DEPENDS_32} ${OPTREMDEPENDS_32}"
[ "${OPTREMDEPENDS_64}" != "" ] && DEPENDS_64="${DEPENDS_64} ${OPTREMDEPENDS_64}"
# Install dependencies
if [ "${DEPENDS}" != "" ]; then
PACKAGES="${DEPENDS}"
fi
if [ "${ARCH}" == "i686" ] && [ "${DEPENDS_32}" != "" ]; then
PACKAGES="${PACKAGES} ${DEPENDS_32}"
fi
if [ "${ARCH}" == "x86_64" ] && [ "${DEPENDS_64}" != "" ]; then
if [ "${MHWD64_IS_LIB32}" == "true" ];then
PACKAGES="${PACKAGES} ${DEPENDS_64}"
else
PACKAGES="${PACKAGES}"
fi
fi
if [ "${DEPKMODS}" != "" ]; then
PACKAGES="${PACKAGES} ${DEPKMODS}"
fi
if [ "${PACKAGES}" != "" ]; then
${PACMAN} --needed -S${SYNC} ${PACKAGES}
if [ "$?" -ne "0" ]; then
echo "Error: pacman failed!"
exit 1
fi
${PACMAN} -D --asexplicit ${PACKAGES}
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
if [ "${REMOVE}" == "true" ]; then
# Run preremove function
if [ "`grep "pre_remove" "${CONFIGPATH}" | cut -d"#" -f1 | cut -d"(" -f1 | grep "pre_remove"`" == "pre_remove" ]; then
pre_remove
fi
PACKAGES=""
# Check for extramodules
MHWD_CHECK_KMODS
# Remove dependencies
if [ "${DEPENDS}" != "" ]; then
PACKAGES="${DEPENDS}"
fi
if [ "${ARCH}" == "i686" ] && [ "${DEPENDS_32}" != "" ]; then
PACKAGES="${PACKAGES} ${DEPENDS_32}"
fi
if [ "${ARCH}" == "x86_64" ] && [ "${DEPENDS_64}" != "" ]; then
if [ "${MHWD64_IS_LIB32}" == "true" ];then
PACKAGES="${PACKAGES} ${DEPENDS_64}"
else
PACKAGES="${PACKAGES}"
fi
fi
if [ "${DEPKMODS}" != "" ]; then
PACKAGES="${PACKAGES} ${DEPKMODS}"
fi
# Run preremove function
if [ "`grep "pre_remove" "${CONFIGPATH}" | cut -d"#" -f1 | cut -d"(" -f1 | grep "pre_remove"`" == "pre_remove" ]; then
pre_remove
fi
PACKAGES=""
OPTREMPACKAGES=""
# Check for extramodules
MHWD_CHECK_KMODS
# Remove dependencies
if [ "${DEPENDS}" != "" ]; then
PACKAGES="${DEPENDS}"
fi
if [ "${ARCH}" == "i686" ] && [ "${DEPENDS_32}" != "" ]; then
PACKAGES="${PACKAGES} ${DEPENDS_32}"
fi
if [ "${ARCH}" == "x86_64" ] && [ "${DEPENDS_64}" != "" ]; then
if [ "${MHWD64_IS_LIB32}" == "true" ];then
PACKAGES="${PACKAGES} ${DEPENDS_64}"
else
PACKAGES="${PACKAGES}"
fi
fi
if [ "${DEPKMODS}" != "" ]; then
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
MHWD_CHECK_PKGS
if [ "${PACKAGES}" != "" ]; then
${PACMAN} -Rs ${PACKAGES}
if [ "$?" -ne "0" ]; then
echo "Error: pacman failed!"
exit 1
fi
fi
# Run postremove function
if [ "`grep "post_remove" "${CONFIGPATH}" | cut -d"#" -f1 | cut -d"(" -f1 | grep "post_remove"`" == "post_remove" ]; then
post_remove
fi
if [ "${PACKAGES}" != "" ]; then
${PACMAN} -Rs ${PACKAGES}
if [ "$?" -ne "0" ]; then
echo "Error: pacman failed!"
exit 1
fi
fi
# Run postremove function
if [ "`grep "post_remove" "${CONFIGPATH}" | cut -d"#" -f1 | cut -d"(" -f1 | grep "post_remove"`" == "post_remove" ]; then
post_remove
fi
fi
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 @@
PARAM=$#
MHWDXORGCONF="/etc/X11/xorg.conf.d/90-mhwd.conf"
CHECKCONFIG="false"
SETGL=""
SETXORGCONF=""
SETMOD=""
ARCH=$(uname -m)
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 2: blacklisted modules
set_modules() {
echo "##" > "/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"
for module in $2
do
echo "blacklist ${module}" >> "/etc/modprobe.d/mhwd-gpu.conf"
# Unload module if X is not running
if [ ! "$(pgrep X)" ]; then
rmmod -f ${module}
fi
done
echo "##" > "${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"
for module in $1
do
echo "${module}" >> "${MODULES_LOAD}/mhwd-gpu.conf"
# Load module if X is not running
if [ ! "$(pgrep X)" ]; then
modprobe ${module}
fi
done
echo "##" > "/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"
for module in $2
do
echo "blacklist ${module}" >> "/etc/modprobe.d/mhwd-gpu.conf"
# Unload module if X is not running
if [ ! "$(pgrep X)" ]; then
rmmod -f ${module}
fi
done
echo "##" > "${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"
for module in $1
do
echo "${module}" >> "${MODULES_LOAD}/mhwd-gpu.conf"
# Load module if X is not running
if [ ! "$(pgrep X)" ]; then
modprobe ${module}
fi
done
}
# param 1: Xorg configuration file
set_xorg()
{
if [ -e "${MHWDXORGCONF}" ]; then
rm "${MHWDXORGCONF}"
fi
if [ -e "$1" ]; then
ln -sf "$1" "${MHWDXORGCONF}"
echo "xorg configuration file: '$1'"
else
echo "warning: could not find '$1'!"
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"
if [ -e "${MHWDXORGCONF}" ]; then
rm "${MHWDXORGCONF}"
fi
if [ -e "$1" ]; then
ln -sf "$1" "${MHWDXORGCONF}"
echo "xorg configuration file: '$1'"
else
echo "warning: could not find '$1'!"
fi
}
print_link_destination_if_exists()
{
if [ -e "$1" ]; then
echo "$2 '$(readlink "$1")'"
else
echo "warning: could not find '$1'!"
fi
if [ -e "$1" ]; then
echo "$2 '$(readlink "$1")'"
else
echo "warning: could not find '$1'!"
fi
}
print_status()
{
echo ":: status"
echo ":: status"
if [ "${MHWD64_IS_LIB32}" == "true" ];then
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_link_destination_if_exists "${MHWDXORGCONF}" " xorg configuration file:"
}
print_help()
{
echo "mhwd-gpu [OPTION] [...]"
echo ""
echo " --help show help"
echo " --status show current status"
echo " --check check for invalid symlinks and repair"
echo " --setgl [mesa/nvidia/catalyst] set libgl and libglx"
echo " --setxorg [PATH] set xorg configuration file"
if [ "${ARCH}" == "x86_64" ];then
echo " --setlib32 [true/false] set lib32 support"
fi
echo ""
echo "mhwd-gpu [OPTION] [...]"
echo ""
echo " --help show help"
echo " --status show current status"
echo " --check check for invalid symlinks and repair"
echo " --setxorg [PATH] set xorg configuration file"
echo " --setmod [nvidia/catalyst] set modules"
echo ""
}
if [ "${PARAM}" -lt 1 ]; then
print_status
exit 0
print_status
exit 0
fi
if [ "${ARCH}" == "x86_64" ];then
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"
;;
--setlib32)
shift
MHWD64_IS_LIB32="$1"
;;
"") ;;
*)
echo "error: invalid argument: $1"
echo ""
print_help
exit 1
;;
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
for (( I=1; $I <= $PARAM; I++ ));do
case "$1" in
--help)
print_help
exit 0
;;
--status)
print_status
exit 0
;;
--check)
CHECKCONFIG="true"
;;
--setxorg)
shift
SETXORGCONF="$1"
;;
--setmod)
shift
SETMOD="$1"
;;
"") ;;
*)
echo "error: invalid argument: $1"
echo ""
print_help
exit 1
;;
esac
shift
done
# Check root
if [[ $EUID -ne 0 ]]; then
......@@ -294,105 +129,27 @@ if [[ $EUID -ne 0 ]]; then
exit 1
fi
if [ "${DEFAULT_IS_LIB32}" != "${MHWD64_IS_LIB32}" ];then
if [ "${MHWD64_IS_LIB32}" == "true" ] || [ "${MHWD64_IS_LIB32}" == "false" ]; then
set_lib32 "${MHWD64_IS_LIB32}"
fi
fi
# Set libGl and libglx
if [ "${SETGL}" == "mesa" ] || [ "${SETGL}" == "default" ]; then
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
# Set Modules
if [ "${SETMOD}" == "nvidia" ]; then
set_modules "nvidia" "nouveau ttm drm_kms_helper drm"
elif [ "${SETMOD}" == "catalyst" ] || [ "${SETMOD}" == "ati" ]; then
set_modules "fglrx" "radeon"
elif [ "${SETMOD}" != "" ]; then
echo "error: invalid argument '${SETMOD}'"
exit 1
fi
# Set xorg configuration file
if [ "${SETXORGCONF}" != "" ]; then
set_xorg "${SETXORGCONF}"
set_xorg "${SETXORGCONF}"
fi
# Check config
if [ "${CHECKCONFIG}" == "true" ]; then
if [ -L "${MHWDXORGCONF}" -a ! -e "${MHWDXORGCONF}" ]; then
echo "'${MHWDXORGCONF}' symlink is invalid! Removing it..."
rm "${MHWDXORGCONF}"
elif [ -e "${MHWDXORGCONF}" ]; then
echo "xorg configuration symlink valid..."
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
if [ -L "${MHWDXORGCONF}" -a ! -e "${MHWDXORGCONF}" ]; then
echo "'${MHWDXORGCONF}' symlink is invalid! Removing it..."
rm "${MHWDXORGCONF}"
elif [ -e "${MHWDXORGCONF}" ]; then
echo "xorg configuration symlink valid..."
fi
fi
......@@ -9,7 +9,7 @@ args_check() {
}
err() {
echo "Error: $1" 1>&2; exit 1
printf "\e[31mError:\e[0m $1\n" 1>&2; exit 1
}
kernel_usage() {
......@@ -21,24 +21,38 @@ kernel_usage() {
-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() {
pkginstall=()
rmc=0
for kernel in "$@"; do
[[ $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]) ]] && err "Please enter a valid kernel name."
[[ $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)"
[[ $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
pkg=${pkg//$current/$kernel}
[[ -n $(pacman -Ssq "^$pkg$") ]] && pkginstall+=("$pkg")
[[ -n $(pacman -Ssq "^$pkg$" | grep -E "^$pkg$|^$pkg-\S+$") ]] && pkginstall+=("$pkg")
done
done
pacman -Syy
pacman -Sy
outofdate="$(pacman -Qqu | tr '\n' ' ')"
if [[ -n $outofdate ]]; then
......@@ -51,34 +65,40 @@ kernel_install() {
[[ $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."; }
[[ ! -e "/usr/bin/update-grub" && -e "/usr/bin/grub-mkconfig" ]] && update_grub
}
kernel_repo() {
echo "Available kernels:"
pacman -Ss "^linux[0-9][0-9]?([0-9])$" | grep core | while read -r; do echo " * ${REPLY:5:8}"; done
printf "\e[32mavailable kernels:\e[0m\n"
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() {
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:"
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() {
pkgremove=()
for kernel in "$@"; do
[[ -z "$kernel" ]] && err "Invalid argument (use -h for help)."
[[ $kernel != linux[0-9][0-9]?([0-9]) ]] && err "Please enter a valid kernel name."
[[ -z "$kernel" ]] && err "Invalid argument (use -h for help)."
[[ $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."
[[ -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")
done
done
pacman -R "${pkgremove[@]}"
[[ ! -e "/usr/bin/update-grub" && -e "/usr/bin/grub-mkconfig" ]] && update_grub
}
IFS=. read -r major minor _ <<< "$(uname -r)"
......@@ -105,6 +125,3 @@ case "$1" in
-*) err "Invalid argument (use -h for help)." ;;
*) err "No arguments given (use -h for help)." ;;
esac
......@@ -5,22 +5,22 @@ include_directories(. ${mhwd_SOURCE_DIR}/libmhwd)
###
set( HEADERS
Config.hpp
Data.hpp
Device.hpp
Enums.hpp
Mhwd.hpp
Printer.hpp
Transaction.hpp
Config.hpp
ConsoleWriter.hpp
Data.hpp
Device.hpp
Enums.hpp
Mhwd.hpp
Transaction.hpp
)
set( SOURCES
Config.cpp
ConsoleWriter.cpp
Data.cpp
Device.cpp
main.cpp
Mhwd.cpp
Printer.cpp
Transaction.cpp
)
......
/*
* This file is part of the mhwd - Manjaro Hardware Detection project
*
* mhwd - Manjaro Hardware Detection
* Roland Singer <roland@manjaro.org>
* Ł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
* it under the terms of the GNU General Public License as published by
......@@ -19,28 +22,23 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Config.hpp"
#include "Utils.hpp"
#include <fstream>
#include <string>
#include <vector>
#include "Config.hpp"
Config::Config(std::string configPath, std::string type)
: type_(type), basePath_(configPath.substr(0, configPath.find_last_of('/'))),
configPath_(configPath)
{
if (hwdIDs_.empty())
{
Config::HardwareID hwdID;
hwdIDs_.push_back(hwdID);
}
}
configPath_(configPath), hwdIDs_(1)
{}
bool Config::readConfigFile(std::string configPath)
{
std::ifstream file(configPath.c_str());
std::ifstream file(configPath);
if (!file.is_open())
if (!file)
{
return false;
}
......@@ -108,91 +106,72 @@ bool Config::readConfigFile(std::string configPath)
}
}
if (key == "include")
{
readConfigFile(getRightConfigPath(value, basePath_));
}
else if (key == "name")
{
name_ = value.toLower();
}
else if (key == "version")
{
version_ = value;
}
else if (key == "info")
{
info_ = value;
}
else if (key == "priority")
{
priority_ = value.convert<int>();
}
else if (key == "freedriver")
{
value = value.toLower();
if (value == "false")
{
freedriver_ = false;
}
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);
}
switch(MhwdUtils::hash(std::string(key).c_str()))
{
case MhwdUtils::hash_compile_time("include"):
readConfigFile(getRightConfigPath(value, basePath_));
break;
case MhwdUtils::hash_compile_time("name"):
name_ = value.toLower();
break;
case MhwdUtils::hash_compile_time("version"):
version_ = value;
break;
case MhwdUtils::hash_compile_time("info"):
info_ = value;
break;
case MhwdUtils::hash_compile_time("priority"):
priority_ = value.convert<int>();
break;
case MhwdUtils::hash_compile_time("freedriver"):
value = value.toLower();
freedriver_ = value == "false" ? false : true;
break;
case MhwdUtils::hash_compile_time("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);
}
else if (key == "vendorids")
{
// Add new HardwareIDs group to vector if vector is not empty
if (!hwdIDs_.back().vendorIDs.empty())
{
Config::HardwareID hwdID;
hwdIDs_.push_back(hwdID);
}
hwdIDs_.back().classIDs = splitValue(value);
break;
case MhwdUtils::hash_compile_time("vendorids"):
// Add new HardwareIDs group to vector if vector is not empty
if (!hwdIDs_.back().vendorIDs.empty())
{
Config::HardwareID hwdID;
hwdIDs_.push_back(hwdID);
}
hwdIDs_.back().vendorIDs = splitValue(value);
}
else if (key == "deviceids")
{
// Add new HardwareIDs group to vector if vector is not empty
if (!hwdIDs_.back().deviceIDs.empty())
{
Config::HardwareID hwdID;
hwdIDs_.push_back(hwdID);
}
hwdIDs_.back().vendorIDs = splitValue(value);
break;
case MhwdUtils::hash_compile_time("deviceids"):
// Add new HardwareIDs group to vector if vector is not empty
if (!hwdIDs_.back().deviceIDs.empty())
{
Config::HardwareID hwdID;
hwdIDs_.push_back(hwdID);
}
hwdIDs_.back().deviceIDs = splitValue(value);
}
else if (key == "blacklistedclassids")
{
hwdIDs_.back().blacklistedClassIDs = splitValue(value);
}
else if (key == "blacklistedvendorids")
{
hwdIDs_.back().blacklistedVendorIDs = splitValue(value);
}
else if (key == "blacklisteddeviceids")
{
hwdIDs_.back().blacklistedDeviceIDs = splitValue(value);
}
else if (key == "mhwddepends")
{
dependencies_ = splitValue(value);
}
else if (key == "mhwdconflicts")
{
conflicts_ = splitValue(value);
hwdIDs_.back().deviceIDs = splitValue(value);
break;
case MhwdUtils::hash_compile_time("blacklistedclassids"):
hwdIDs_.back().blacklistedClassIDs = splitValue(value);
break;
case MhwdUtils::hash_compile_time("blacklistedvendorids"):
hwdIDs_.back().blacklistedVendorIDs = splitValue(value);
break;
case MhwdUtils::hash_compile_time("blacklisteddeviceids"):
hwdIDs_.back().blacklistedDeviceIDs = splitValue(value);
break;
case MhwdUtils::hash_compile_time("mhwddepends"):
dependencies_ = splitValue(value);
break;
case MhwdUtils::hash_compile_time("mhwdconflicts"):
conflicts_ = splitValue(value);
break;
}
}
......@@ -216,12 +195,7 @@ bool Config::readConfigFile(std::string configPath)
}
}
if (name_.empty())
{
return false;
}
return true;
return ! name_.empty();
}
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
* Roland Singer <roland@manjaro.org>
* Ł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
* 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
* Roland Singer <roland@manjaro.org>
* Ł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
* it under the terms of the GNU General Public License as published by
......@@ -19,68 +22,72 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ConsoleWriter.hpp"
#include <hd.h>
#include <iomanip>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include "Printer.hpp"
void Printer::printStatus(std::string statusMsg) const
void ConsoleWriter::printStatus(std::string statusMsg) const
{
std::cout << CONSOLE_MESSAGE_COLOR << "> "
std::cout << CONSOLE_RED_MESSAGE_COLOR << "> "
<< 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;
}
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;
}
void Printer::printMessage(MHWD::MESSAGETYPE type, std::string msg) const
void ConsoleWriter::printMessage(MHWD::MESSAGETYPE type, std::string msg) const
{
switch(type)
{
case MHWD::MESSAGETYPE::CONSOLE_OUTPUT:
std::cout << CONSOLE_TEXT_OUTPUT_COLOR << msg << CONSOLE_COLOR_RESET;
break;
case MHWD::MESSAGETYPE::INSTALLDEPENDENCY_START:
printStatus("Installing dependency " + msg + "...");
break;
case MHWD::MESSAGETYPE::INSTALLDEPENDENCY_END:
printStatus("Successfully installed dependency " + msg);
break;
case MHWD::MESSAGETYPE::INSTALL_START:
printStatus("Installing " + msg + "...");
break;
case MHWD::MESSAGETYPE::INSTALL_END:
printStatus("Successfully installed " + msg);
break;
case MHWD::MESSAGETYPE::REMOVE_START:
printStatus("Removing " + msg + "...");
break;
case MHWD::MESSAGETYPE::REMOVE_END:
printStatus("Successfully removed " + msg);
break;
default:
printError("You shouldn't see this?! Unknown message type!");
break;
}
switch(type)
{
case MHWD::MESSAGETYPE::CONSOLE_OUTPUT:
std::cout << CONSOLE_TEXT_OUTPUT_COLOR << msg << CONSOLE_COLOR_RESET;
break;
case MHWD::MESSAGETYPE::INSTALLDEPENDENCY_START:
printStatus("Installing dependency " + msg + "...");
break;
case MHWD::MESSAGETYPE::INSTALLDEPENDENCY_END:
printStatus("Successfully installed dependency " + msg);
break;
case MHWD::MESSAGETYPE::INSTALL_START:
printStatus("Installing " + msg + "...");
break;
case MHWD::MESSAGETYPE::INSTALL_END:
printStatus("Successfully installed " + msg);
break;
case MHWD::MESSAGETYPE::REMOVE_START:
printStatus("Removing " + msg + "...");
break;
case MHWD::MESSAGETYPE::REMOVE_END:
printStatus("Successfully removed " + msg);
break;
default:
printError("You shouldn't see this?! Unknown message type!");
break;
}
}
void Printer::printHelp() const
void ConsoleWriter::printHelp() const
{
std::cout << "Usage: mhwd [OPTIONS] <config(s)>\n\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"
<< " -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"
<< " -d/--detail\t\t\t\tshow detailed info for -l/-li/-lh\n"
<< " -l/--list\t\t\t\tlist available configs for devices\n"
......@@ -96,7 +103,16 @@ void Printer::printHelp() const
<< " --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())
{
......@@ -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);
printLine();
......@@ -145,7 +161,7 @@ void Printer::listConfigs(const std::vector<std::shared_ptr<Config>>& configs, s
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
{
bool configFound = false;
......@@ -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
{
if (installedConfigs.empty())
......@@ -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 vendorids;
......@@ -251,7 +267,21 @@ void Printer::printConfigDetails(const Config& config) const
<< "\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
* Roland Singer <roland@manjaro.org>
* Ł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
* it under the terms of the GNU General Public License as published by
......@@ -22,6 +25,8 @@
#ifndef PRINTER_HPP_
#define PRINTER_HPP_
#include <hd.h>
#include <string>
#include <vector>
......@@ -29,7 +34,7 @@
#include "Device.hpp"
#include "Enums.hpp"
class Printer
class ConsoleWriter
{
public:
void printStatus(std::string statusMsg) const;
......@@ -37,7 +42,9 @@ public:
void printWarning(std::string warningMsg) const;
void printMessage(MHWD::MESSAGETYPE type, std::string str) 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,
std::string header) const;
void printAvailableConfigsInDetail(const std::string& deviceType,
......@@ -45,11 +52,12 @@ public:
void printInstalledConfigs(const std::string& deviceType,
const std::vector<std::shared_ptr<Config>>& installedConfigs) const;
void printConfigDetails(const Config& config) const;
void printDeviceDetails(hw_item hw, FILE *f = stdout) const;
private:
void printLine() const;
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"};
};
......
This diff is collapsed.
/*
* This file is part of the mhwd - Manjaro Hardware Detection project
*
* mhwd - Manjaro Hardware Detection
* Roland Singer <roland@manjaro.org>
* Ł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
* it under the terms of the GNU General Public License as published by
......@@ -29,18 +32,21 @@
#include <memory>
#include <string>
#include <vector>
#include <cstdint>
#include "Config.hpp"
#include "Device.hpp"
#include "const.h"
#include "Device.hpp"
#include "vita/string.hpp"
class Data {
class Data
{
public:
Data();
~Data();
~Data() = default;
struct Environment {
struct Environment
{
std::string PMCachePath {MHWD_PM_CACHE_DIR};
std::string PMConfigPath {MHWD_PM_CONFIG};
std::string PMRootPath {MHWD_PM_ROOT};
......@@ -58,7 +64,6 @@ public:
void updateInstalledConfigData();
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);
void getAllDependenciesToInstall(std::shared_ptr<Config> config,
......@@ -73,18 +78,17 @@ private:
void getAllDevicesOfConfig(const std::vector<std::shared_ptr<Device>>& devices,
std::shared_ptr<Config> config, std::vector<std::shared_ptr<Device>>& foundDevices);
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 setMatchingConfigs(const std::vector<std::shared_ptr<Device>>& devices,
std::vector<std::shared_ptr<Config>>& configs, bool setAsInstalled);
void setMatchingConfig(std::shared_ptr<Config> config, const std::vector<std::shared_ptr<Device>>& devices,
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::string onlyFilename = "");
Vita::string getRightConfigPath(Vita::string str, Vita::string baseConfigPath);
std::vector<std::string> splitValue(Vita::string str, Vita::string onlyEnding = "");
void updateConfigData();
Vita::string from_Hex(uint16_t hexnum, int fill);
......