-
Notifications
You must be signed in to change notification settings - Fork 36
/
hdmi.sh
144 lines (115 loc) · 3.77 KB
/
hdmi.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
#!/bin/bash
setup_hdmi() {
get_board
if [ "$BOARD" = "odroidc" ]; then
do_odroidc_hdmi
return 0
fi
if [ "$BOARD" = "odroidxu" ] || [ "$BOARD" = "odroidxu3" ]; then
msgbox "For ODROID-XU and ODROID-XU3 please check the /media/boot/boot.ini file instead. There are instructions there"
return 0
fi
HM=$(whiptail --backtitle "Hardkernel ODROID Utility v$_REV" --menu "HDMI Configuration" 0 0 0 \
"1" "Automatic Configuration" \
"2" "1920x1080 (1080P) Using your monitor timings (EDID)" \
"3" "1920x1080 (1080P) Using generic timings (NO-EDID)" \
"4" "1280x720 (720P) Using your monitor timings (EDID)" \
"5" "1280x720 (720P) Using generic timings (NO-EDID)" \
"6" "1024x768 Using generic timings (NO-EDID) (Failsafe)" \
3>&1 1>&2 2>&3)
HR=$?
if [ $HR -eq 1 ]; then
return 0
else
do_change_hdmi $HM
fi
}
do_change_hdmi() {
if [ "$DISTRO" = "ubuntu" ] || [ "$DISTRO" = "ubuntu-server" ]; then
BASE=/media/boot
elif [ "$DISTRO" = "debian" ]; then
BASE=/boot
else
msgbox "HDMI: Your distro $DISTRO isn't supported yet. Please report on the forums"
return 0
fi
case "$1" in
"1") cp $BASE/boot-auto_edid.scr $BASE/boot.scr ;;
"2") cp $BASE/boot-1080p-edid.scr $BASE/boot.scr ;;
"3") cp $BASE/boot-1080p-noedid.scr $BASE/boot.scr ;;
"4") cp $BASE/boot-720p-edid.scr $BASE/boot.scr ;;
"5") cp $BASE/boot-720p-noedid.scr $BASE/boot.scr ;;
"6") cp $BASE/boot-1024x768-noedid.scr $BASE/boot.scr ;;
*) msgbox "HDMI: Error. You shouldn't be here. Report on the forums. Error HDMI-$1" ;;
esac
msgbox "HDMI Configuration changed. Please reboot"
REBOOT=1
}
do_odroidc_hdmi() {
# Defines
export oIFS="$IFS"
export IFS="/"
export R_VALUE=()
export R_NAME=()
export COUNT=0
# Read boot.ini to get the current selected resolution
# Also populate the array with the valid options found on the boot.ini
while read line; do
if [[ $line =~ "setenv m \"" ]]; then
if [[ ${line:0:1} == "s" ]]; then
export selected=`echo $line | awk '{print $3}' | sed s/"\""//g`
fi
lt=`echo $line | sed s/"# "//g | sed s/"setenv m "//g | awk '{print $1}' | sed s/"\""//g`
la=`echo $line | sed s/"# "//g | sed s/"setenv m "//g | awk '{$1=""; print $0}'`
R_VALUE[$COUNT]=$lt
R_NAME[$COUNT]=$la
((COUNT++))
fi
done < /media/boot/boot.ini
# Create the variable that we'll pass over to whiptail
for ((C=0; C<$COUNT; C++)); do
export HDMI_MENU+="${R_VALUE[$C]}/${R_NAME[$C]}/"
done
# Call whiptail
NR=$(whiptail --backtitle "Hardkernel ODROID Utility v$_REV" --menu "HDMI Configuration" 0 0 0 --default-item $selected $HDMI_MENU 3>&1 1>&2 2>&3)
# Sanity check, just to make sure that the user selected something
RT=$?
if [ $RT -eq 1 ]; then
return
fi
# Same as before? Stop here
if [ "$NR" == "$selected" ]; then
msgbox "You didn't changed the resolution. Keeping $selected"
return
fi
# First Pass, disable all setenv's
while read line; do
if [[ $line =~ "setenv m \"" ]]; then
if [[ ${line:0:1} == "s" ]]; then
nl=`echo $line | sed s/"setenv m"/"# setenv m"/g`
line=$nl
fi
fi
echo $line >> /tmp/tmp1.ini
done < /media/boot/boot.ini
# Second pass, enable just the selected resolution :)
while read line; do
if [[ $line =~ "setenv m \"" ]]; then
p=`echo $line | awk '{print $4}' | sed s/\"//g`
if [ "$p" == "$NR" ]; then
nl=`echo $line | sed s/"# setenv m"/"setenv m"/g`
echo "NL: $nl -> P: $p -> NR: $NR"
line=$nl
fi
fi
echo $line >> /tmp/new.ini
done < /tmp/tmp1.ini
# Copy the new boot.ini
mv /tmp/new.ini /media/boot/boot.ini
rm -fr /tmp/tmp1.ini
sync
msgbox "Changed screen resolution from $selected to $NR. Please reboot"
# For the sake of sanity
export HDMI_MENU=""; export p=""; export NR=""; export COUNT=""; export selected=""; export R_VALUE=""; export R_NAME=""
REBOOT=1
}