forked from wimpysworld/umpc-ubuntu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathumpc-ubuntu.sh
executable file
·145 lines (122 loc) · 4.44 KB
/
umpc-ubuntu.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env bash
# Set to either "gpd-pocket", "gpd-pocket2", "gpd-micropc" or "topjoy-falcon"
UMPC="gpd-pocket2"
XORG_CONF_PATH="/usr/share/X11/xorg.conf.d"
GDM3_CONF="/var/lib/gdm3/.config/monitors.xml"
INTEL_CONF="${XORG_CONF_PATH}/20-${UMPC}-intel.conf"
MONITOR_CONF="${XORG_CONF_PATH}/40-${UMPC}-monitor.conf"
TRACKPOINT_CONF="${XORG_CONF_PATH}/80-${UMPC}-trackpoint.conf"
TOUCH_RULES="/etc/udev/rules.d/99-${UMPC}-touch.rules"
BRCM4356_CONF="/lib/firmware/brcm/brcmfmac4356-pcie.txt"
GRUB_DEFAULT_CONF="/etc/default/grub"
CONSOLE_CONF="/etc/default/console-setup"
XRANDR_SCRIPT="/usr/bin/umpc-display-scaler"
XRANDR_DESKTOP="/etc/xdg/autostart/umpc-display-scaler.desktop"
# Copy file from /data to it's intended location
function inject_data() {
local TARGET_FILE="${1}"
local TARGET_DIR=$(dirname "${TARGET_FILE}")
if [ -n "${2}" ] && [ -f "${2}" ]; then
local SOURCE_FILE="${2}"
else
local SOURCE_FILE="data/$(basename ${TARGET_FILE})"
fi
echo " - Injecting ${TARGET_FILE}"
if [ ! -d "${TARGET_DIR}" ]; then
mkdir -p "${TARGET_DIR}"
fi
if [ -f "${SOURCE_FILE}" ]; then
cp "${SOURCE_FILE}" "${TARGET_FILE}"
fi
}
function enable_umpc_config() {
# Enable Intel SNA, DRI3 and TearFree.
inject_data "${INTEL_CONF}"
# Rotate the monitor.
inject_data "${MONITOR_CONF}"
# Place config for rotare GDM3.
inject_data "${GDM3_CONF}"
# Scroll while holding down the right track point button
inject_data "${TRACKPOINT_CONF}"
# Rotate the touchscreen.
inject_data "${TOUCH_RULES}"
# Reload udev rules
udevadm control --reload-rules
udevadm trigger
# Scale up the primary display to increase readability.
inject_data "${XRANDR_SCRIPT}"
inject_data "${XRANDR_DESKTOP}"
# Add BRCM4356 firmware configuration
if [ "${UMPC}" == "gpd-pocket" ]; then
inject_data "${BRCM4356_CONF}"
# Reload the brcmfmac kernel module
modprobe -r brcmfmac
modprobe brcmfmac
fi
# Rotate the framebuffer
sed -i 's/GRUB_CMDLINE_LINUX_DEFAULT="quiet/GRUB_CMDLINE_LINUX_DEFAULT="video=efifb fbcon=rotate:1 quiet/' "${GRUB_DEFAULT_CONF}"
sed -i 's/GRUB_CMDLINE_LINUX=""/GRUB_CMDLINE_LINUX="video=efifb fbcon=rotate:1"/' "${GRUB_DEFAULT_CONF}"
if [ "${UMPC}" == "gpd-pocket2" ]; then
grep -qxF 'GRUB_GFXMODE=1200x1920x32' "${GRUB_DEFAULT_CONF}" || echo 'GRUB_GFXMODE=1200x1920x32' >> "${GRUB_DEFAULT_CONF}"
fi
update-grub
# Increase tty font size
sed -i 's/FONTSIZE="8x16"/FONTSIZE="16x32"/' "${CONSOLE_CONF}"
echo "UMPC hardware configuration is applied. Please reboot to complete the setup."
}
function disable_umpc_config() {
# Remove the UMPC Pocket hardware configuration
for CONFIG in ${MONITOR_CONF} ${TOUCH_CONF} ${BRCM4356_CONF} ${XRANDR_SCRIPT} ${XRANDR_DESKTOP}; do
if [ -f "${CONFIG}" ]; then
rm -fv "${CONFIG}"
fi
done
# Remove the framebuffer rotation
sed -i 's/GRUB_CMDLINE_LINUX_DEFAULT="video=efifb fbcon=rotate:1 quiet/GRUB_CMDLINE_LINUX_DEFAULT="quiet/' "${GRUB_DEFAULT_CONF}"
sed -i 's/GRUB_CMDLINE_LINUX="video=efifb fbcon=rotate:1"/GRUB_CMDLINE_LINUX=""/' "${GRUB_DEFAULT_CONF}"
sed -i 's/GRUB_GFXMODE=1200x1920x32/d' "${GRUB_DEFAULT_CONF}"
update-grub
# Restore tty font size
sed -i 's/FONTSIZE=16x32"/FONTSIZE="8x16"/' "${CONSOLE_CONF}"
echo "UMPC hardware configuration is removed. Please reboot to complete the setup."
}
function usage() {
echo
echo "Usage"
echo " ${0} enable || disable"
echo ""
echo "You must supply one of the following modes of operation"
echo " enable : apply the ${MODEL} hardware configuration"
echo " disable : remove the ${MODEL} hardware configuration"
echo " help : This help."
echo
exit 1
}
# Make sure we are not running on Wayland
if [ "${XDG_SESSION_TYPE}" == "wayland" ]; then
echo "ERROR! This script is only designed to configure Xorg (X11). Please choose an alternative desktop session that uses Xorg (X11)."
exit 1
fi
# Make sure we are root.
if [ $(id -u) -ne 0 ]; then
echo "ERROR! You must be root to run $(basename $0)"
exit 1
fi
# Display usage instructions if we've not been given an action. If an action
# has been provided store it in lowercase.
if [ -z "${1}" ]; then
usage
else
MODE=$(echo "${1}" | tr '[:upper:]' '[:lower:]')
fi
case "${MODE}" in
-d|--disable|disable)
disable_umpc_config;;
-e|--enable|enable)
enable_umpc_config;;
-h|--h|-help|--help|-?|help)
usage;;
*)
echo "ERROR! \"${MODE}\" is not a supported parameter."
usage;;
esac