add_users() {
	_l="/etc/login.defs"
	_p="/etc/passwd"

	## get mini UID limit ##
	l=$(grep "^UID_MIN" $_l)

	## get max UID limit ##
	l1=$(grep "^UID_MAX" $_l)

	## use awk to print if UID >= $MIN and UID <= $MAX and shell is not /sbin/nologin ##
	users=$(awk -F':' -v "min=${l##UID_MIN}" -v "max=${l1##UID_MAX}" '{ if ( $3 >= min && $3 <= max  && $7 != "/sbin/nologin" ) print $0 }' "$_p" | cut -d: -f1)
	for i in $users; do
		echo "Adding user '$i' to user-group 'input,video'"
		usermod -a -G input "$i"
		usermod -a -G video "$i"
	done
}

add_group() {
	getent group "input" &>/dev/null || groupadd -r input -g 97
	getent group "video" &>/dev/null || groupadd -r video -g 91
	add_users
}

post_install() {
	add_group
}

post_upgrade() {
	add_group

	if [ "$(vercmp "$2" 1.0.3)" -le 0 ]; then
		cat <<'EOF'
==> input-devices-support no longer depends on xdotool, libinput-gestures and
    xf86-input-{elographics,evdev,void,wacom}, and no longer autostarts
    libinput-gestures. On Wayland desktops (Plasma, GNOME, Hyprland, Sway,
    COSMIC) they are not needed, and KDE Plasma has its own touchpad gestures:
      sudo systemctl --global disable libinput-gestures
    On X11 desktops (Cinnamon, Xfce, i3), keep them installed:
      sudo pacman -D --asexplicit xdotool libinput-gestures xf86-input-elographics xf86-input-evdev xf86-input-void xf86-input-wacom
    Without that, removing orphaned packages also removes them.
EOF
	fi
}
