|
1
|
#!/bin/bash
|
|
2
|
|
|
3
|
#set -x # Set to help debug
|
|
4
|
|
|
5
|
show_usage()
|
|
6
|
{
|
|
7
|
i=0; usage[$i]="Usage: $0 [-p<path>] [-fsad]"
|
|
8
|
i=$((i+1)); usage[$i]="Where:"
|
|
9
|
i=$((i+1)); usage[$i]="f \t= Use patched NCURSES version, thread-safe is default"
|
|
10
|
i=$((i+1)); usage[$i]="p \t= Use specific path instead of current directory"
|
|
11
|
i=$((i+1)); usage[$i]="s \t= Set system-wide environment instead of just current user"
|
|
12
|
i=$((i+1)); usage[$i]="a \t= Force setup of /etc/apt/sources.list and restore when done (requires sudo)"
|
|
13
|
i=$((i+1)); usage[$i]="d \t= Dry run. Just show commands."
|
|
14
|
|
|
15
|
for i in "${usage[@]}"; do
|
|
16
|
echo -e $i
|
|
17
|
done
|
|
18
|
}
|
|
19
|
|
|
20
|
# process options
|
|
21
|
while getopts "h?p:fsad" opt; do
|
|
22
|
case $opt in
|
|
23
|
p ) target_dir=$OPTARG ;;
|
|
24
|
f ) patch_ncurses=true ;;
|
|
25
|
s ) system=true ;;
|
|
26
|
a ) handle_apt=true ;;
|
|
27
|
d ) dry="echo" ;;
|
|
28
|
h | \
|
|
29
|
\? ) show_usage && exit 1
|
|
30
|
exit 1 ;;
|
|
31
|
esac
|
|
32
|
done
|
|
33
|
shift $(($OPTIND - 1))
|
|
34
|
|
|
35
|
# remove previous install, if any
|
|
36
|
$dry rm -rf ncurses*
|
|
37
|
|
|
38
|
# Learn the OS so that we can handle non-Ubuntu "kind of" gracefully
|
|
39
|
if [ "$(cat /etc/os-release | grep "^ID=" | cut -d'=' -f2 | sed "s/\"//g")" = "rhel" ]; then
|
|
40
|
is_rhel=true
|
|
41
|
fi
|
|
42
|
|
|
43
|
# get up to date version
|
|
44
|
if [[ "$handle_apt" == "true" ]]; then
|
|
45
|
if [[ -f "/etc/apt/sources.list.d/ubuntu.sources" ]]; then
|
|
46
|
$dry cp /etc/apt/sources.list.d/ubuntu.sources /tmp
|
|
47
|
$dry sed -i '/^Types: deb$/a Types: deb-src' /etc/apt/sources.list.d/ubuntu.sources
|
|
48
|
else
|
|
49
|
$dry cp /etc/apt/sources.list /tmp
|
|
50
|
$dry sed -i '/^# deb-src /s/^# //' /etc/apt/sources.list
|
|
51
|
fi
|
|
52
|
$dry apt-get update
|
|
53
|
fi
|
|
54
|
|
|
55
|
# install ncurses source code for this version
|
|
56
|
if [ -z "$is_rhel" ]; then
|
|
57
|
$dry apt-get -q -y source ncurses
|
|
58
|
else
|
|
59
|
$dry yum install ncurses-devel
|
|
60
|
fi
|
|
61
|
|
|
62
|
if [[ "$handle_apt" == "true" ]]; then
|
|
63
|
if [[ -f "/etc/apt/sources.list.d/ubuntu.sources" ]]; then
|
|
64
|
$dry mv /tmp/ubuntu.sources /etc/apt/sources.list.d/
|
|
65
|
else
|
|
66
|
$dry mv /tmp/sources.list /etc/apt/
|
|
67
|
fi
|
|
68
|
$dry apt-get update
|
|
69
|
fi
|
|
70
|
|
|
71
|
# check if sources obtained
|
|
72
|
if [ $? -ne 0 ] && [ -z "$dry" ]
|
|
73
|
then
|
|
74
|
echo "+------------------------------------------------------------------------------+"
|
|
75
|
echo "| Unable to get NCURSES source tree! |"
|
|
76
|
echo "| Check the available packages list in /etc/apt/sources.list. |"
|
|
77
|
echo "+------------------------------------------------------------------------------+"
|
|
78
|
exit
|
|
79
|
fi
|
|
80
|
|
|
81
|
# patching the source files
|
|
82
|
$dry pushd ncurses-6.* > /dev/null
|
|
83
|
if [[ "$patch_ncurses" == "true" ]]; then
|
|
84
|
$dry wget https://proj.goldencode.com/downloads/ncurses/ncurses_curses_h_in_v6.1_20200708.patch
|
|
85
|
$dry wget https://proj.goldencode.com/downloads/ncurses/ncurses_lib_getch_c_v6.1_20200708.patch
|
|
86
|
$dry patch include/curses.h.in ncurses_curses_h_in_v6.1_20200708.patch
|
|
87
|
$dry patch ncurses/base/lib_getch.c ncurses_lib_getch_c_v6.1_20200708.patch
|
|
88
|
fi
|
|
89
|
|
|
90
|
# configure and build object libraries
|
|
91
|
if [[ "$patch_ncurses" == "true" ]]; then
|
|
92
|
$dry ./configure --with-termlib CFLAGS='-fPIC -O2' --with-abi-version=6
|
|
93
|
else
|
|
94
|
$dry ./configure --with-termlib CFLAGS='-fPIC -O2' --with-abi-version=6 --with-pthread --enable-pthreads-eintr
|
|
95
|
fi
|
|
96
|
$dry make
|
|
97
|
|
|
98
|
# make valid reference to updated ncurses.h
|
|
99
|
$dry cd include
|
|
100
|
$dry ln -s curses.h ncurses.h
|
|
101
|
$dry cd ..
|
|
102
|
|
|
103
|
if [[ "$patch_ncurses" == "true" ]]; then
|
|
104
|
echo "+------------------------------------------------------------------------------+"
|
|
105
|
echo "| Patched NCURSES libraries update completed. |"
|
|
106
|
else
|
|
107
|
echo "+------------------------------------------------------------------------------+"
|
|
108
|
echo "| Thread-safe NCURSES libraries build completed. |"
|
|
109
|
fi
|
|
110
|
|
|
111
|
# Position minimal files if path is specified
|
|
112
|
if [[ ! -z "$target_dir" ]]; then
|
|
113
|
$dry mkdir -p $target_dir
|
|
114
|
$dry cp -r include $target_dir
|
|
115
|
$dry cp -r lib $target_dir
|
|
116
|
$dry cd $target_dir
|
|
117
|
fi
|
|
118
|
|
|
119
|
# Set up environment variable(s) if they are not set already
|
|
120
|
env_update=""; sudo_update=""
|
|
121
|
if [ -z "$NCURSES_FWD_STATIC" ]; then
|
|
122
|
env_update+="export NCURSES_FWD_STATIC=\"$PWD\""$'\n'
|
|
123
|
sudo_update+="Defaults env_keep += NCURSES_FWD_STATIC"$'\n'
|
|
124
|
fi
|
|
125
|
if [ -z "$NCURSES_FWD_PTHREADS" ] && [ "$patch_ncurses" != "true" ]; then
|
|
126
|
env_update+="export NCURSES_FWD_PTHREADS=true"$'\n'
|
|
127
|
sudo_update+="Defaults env_keep += NCURSES_FWD_PTHREADS"$'\n'
|
|
128
|
fi
|
|
129
|
if [ ."$env_update". != ".." ]; then
|
|
130
|
if [[ "$system" == "true" ]]; then
|
|
131
|
rc_filename='/etc/profile.d/10-ncurses.sh'
|
|
132
|
msg="| The environment has been changed! Reboot to activate changes |"
|
|
133
|
# Ensure we are making the only entry in the profile.d script
|
|
134
|
[ -f "$rc_filename" ] && $dry rm -f $rc_filename
|
|
135
|
[ -z "$dry" ] && echo -n "$sudo_update" > /etc/sudoers.d/10-ncurses
|
|
136
|
mode="644"
|
|
137
|
else
|
|
138
|
rc_filename=$HOME'/.bashrc'
|
|
139
|
msg="| The .bashrc has been changed! Please open new console to activate setup! |"
|
|
140
|
fi
|
|
141
|
if [[ -z "$dry" ]]; then
|
|
142
|
echo '' >> $rc_filename
|
|
143
|
if [[ "$patch_ncurses" == "true" ]]; then
|
|
144
|
echo '# set up patched NCURSES root location' >> $rc_filename
|
|
145
|
else
|
|
146
|
if [ -z "$NCURSES_FWD_STATIC" ]; then
|
|
147
|
echo '# set up thread-safe NCURSES root location' >> $rc_filename
|
|
148
|
fi
|
|
149
|
if [ -z "$NCURSES_FWD_PTHREADS" ]; then
|
|
150
|
echo '# and set up thread-safe NCURSES_FWD_PTHREADS variable' >> $rc_filename
|
|
151
|
fi
|
|
152
|
fi
|
|
153
|
echo -n "$env_update" >> $rc_filename
|
|
154
|
if [[ "$system" == "true" ]]; then
|
|
155
|
chmod $mode $rc_filename
|
|
156
|
fi
|
|
157
|
fi
|
|
158
|
echo "| --------------------------- WARNING ! -------------------------------- |"
|
|
159
|
echo "$msg"
|
|
160
|
echo "| --------------------------- WARNING ! -------------------------------- |"
|
|
161
|
fi
|
|
162
|
|
|
163
|
echo "| Please do FULL FWD rebuild to activate the changes. |"
|
|
164
|
echo "+------------------------------------------------------------------------------+"
|
|
165
|
|
|
166
|
# back to the starting directory
|
|
167
|
$dry popd > /dev/null
|