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>] [-sd]"
|
8
|
i=$((i+1)); usage[$i]="Where:"
|
9
|
i=$((i+1)); usage[$i]="p \t= Use specific path instead of current directory"
|
10
|
i=$((i+1)); usage[$i]="s \t= Set system-wide environment instead of just current user"
|
11
|
i=$((i+1)); usage[$i]="d \t= Dry run. Just show commands."
|
12
|
|
13
|
for i in "${usage[@]}"; do
|
14
|
echo -e $i
|
15
|
done
|
16
|
}
|
17
|
|
18
|
# process options
|
19
|
while getopts "h?p:sd" opt; do
|
20
|
case $opt in
|
21
|
p ) target_dir=$OPTARG ;;
|
22
|
s ) system=true ;;
|
23
|
d ) dry="echo" ;;
|
24
|
h | \
|
25
|
\? ) show_usage && exit 1
|
26
|
exit 1 ;;
|
27
|
esac
|
28
|
done
|
29
|
shift $(($OPTIND - 1))
|
30
|
|
31
|
# remove previous install, if any
|
32
|
$dry rm -rf ncurses*
|
33
|
|
34
|
# Special handling if in a docker container
|
35
|
[[ -e "/tmp/docker_build" ]] && in_docker=true
|
36
|
|
37
|
# Learn the OS so that we can handle non-Ubuntu "kind of" gracefully
|
38
|
if [ "$(cat /etc/os-release | grep "^ID=" | cut -d'=' -f2 | sed "s/\"//g")" = "rhel" ]; then
|
39
|
is_rhel=true
|
40
|
fi
|
41
|
|
42
|
# get up to date version
|
43
|
if [[ "$in_docker" == "true" ]]; then
|
44
|
$dry cp /etc/apt/sources.list /tmp
|
45
|
$dry sed -i '/^# deb-src /s/^# //' /etc/apt/sources.list
|
46
|
$dry apt-get update
|
47
|
fi
|
48
|
|
49
|
# install ncurses source code for this version
|
50
|
if [ -z "$is_rhel" ]; then
|
51
|
$dry apt-get -q -y source ncurses
|
52
|
else
|
53
|
$dry yum install ncurses-devel
|
54
|
fi
|
55
|
|
56
|
if [[ "$in_docker" == "true" ]]; then
|
57
|
$dry mv /tmp/sources.list /etc/apt/
|
58
|
$dry apt-get update
|
59
|
fi
|
60
|
|
61
|
# check if sources obtained
|
62
|
if [ $? -ne 0 ] && [ -z "$dry" ]
|
63
|
then
|
64
|
echo "+------------------------------------------------------------------------------+"
|
65
|
echo "| Unable to get NCURSES source tree! |"
|
66
|
echo "| Check the available packages list in /etc/apt/sources.list. |"
|
67
|
echo "+------------------------------------------------------------------------------+"
|
68
|
exit
|
69
|
fi
|
70
|
|
71
|
# patching the source files
|
72
|
$dry pushd ncurses-6.* > /dev/null
|
73
|
$dry wget https://proj.goldencode.com/downloads/ncurses/ncurses_curses_h_in_v6.1_20200708.patch
|
74
|
$dry wget https://proj.goldencode.com/downloads/ncurses/ncurses_lib_getch_c_v6.1_20200708.patch
|
75
|
$dry patch include/curses.h.in ncurses_curses_h_in_v6.1_20200708.patch
|
76
|
$dry patch ncurses/base/lib_getch.c ncurses_lib_getch_c_v6.1_20200708.patch
|
77
|
|
78
|
# configure and build object libraries
|
79
|
$dry ./configure --with-termlib CFLAGS='-fPIC -O2' --with-abi-version=6
|
80
|
$dry make
|
81
|
|
82
|
# make valid reference to updated ncurses.h
|
83
|
$dry cd include
|
84
|
$dry ln -s curses.h ncurses.h
|
85
|
$dry cd ..
|
86
|
|
87
|
echo "+------------------------------------------------------------------------------+"
|
88
|
echo "| Patched NCURSES libraries update completed. |"
|
89
|
|
90
|
# Position minimal files if path is specified
|
91
|
if [[ ! -z "$target_dir" ]]; then
|
92
|
$dry mkdir -p $target_dir
|
93
|
$dry cp -r include $target_dir
|
94
|
$dry cp -r lib $target_dir
|
95
|
$dry cd $target_dir
|
96
|
fi
|
97
|
|
98
|
# setting up system variable if not yet defined to use custom libraries location
|
99
|
if [ -z "$NCURSES_FWD_STATIC" ]
|
100
|
then
|
101
|
if [[ "$system" == "true" ]]; then
|
102
|
rc_filename='/etc/environment'
|
103
|
msg="| The environment has been changed! Reboot to activate changes |"
|
104
|
update="NCURSES_FWD_STATIC=\"$PWD\""
|
105
|
else
|
106
|
rc_filename=$HOME'/.bashrc'
|
107
|
msg="| The .bashrc has been changed! Please open new console to activate setup! |"
|
108
|
update="export NCURSES_FWD_STATIC=$PWD"
|
109
|
fi
|
110
|
if [[ -z "$dry" ]]; then
|
111
|
echo '' >> $rc_filename
|
112
|
echo '# set up patched NCURSES root location' >> $rc_filename
|
113
|
echo $update >> $rc_filename
|
114
|
fi
|
115
|
echo "| --------------------------- WARNING ! -------------------------------- |"
|
116
|
echo "$msg"
|
117
|
echo "| --------------------------- WARNING ! -------------------------------- |"
|
118
|
fi
|
119
|
echo "| Please do FULL FWD rebuild to activate the changes. |"
|
120
|
echo "+------------------------------------------------------------------------------+"
|
121
|
|
122
|
# back to the starting directory
|
123
|
$dry popd > /dev/null
|