Project

General

Profile

setup_ncurses6_4-noWide.sh

Roger Borrello, 06/12/2026 12:13 PM

Download (6.84 KB)

 
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] [-u<user>]"
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]="f \t= Use patched NCURSES version, thread-safe is default"
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]="u \t= Update this user's .bashrc instead of current user. Typically for when run under sudo"
14
   i=$((i+1)); usage[$i]="d \t= Dry run. Just show commands."
15

    
16
   for i in "${usage[@]}"; do
17
      echo -e $i
18
   done
19
}
20

    
21
# Defaults
22
homedir=$HOME
23

    
24
# process options
25
while getopts "h?p:fsadu:" opt; do
26
   case $opt in
27
      p  ) target_dir=$OPTARG ;;
28
      f  ) patch_ncurses=true ;;
29
      s  ) system=true ;;
30
      a  ) handle_apt=true ;;
31
      u  ) user=$OPTARG
32
           homedir="/home/${OPTARG}" ;;
33
      d  ) dry="echo" ;;
34
      h | \
35
      \? ) show_usage && exit 1
36
           exit 1 ;;
37
   esac
38
done
39
shift $(($OPTIND - 1))
40

    
41
# remove previous install, if any
42
$dry rm -rf ncurses*
43

    
44
# Learn the OS so that we can handle non-Ubuntu "kind of" gracefully
45
. /etc/os-release
46
codename="$VERSION_CODENAME"
47
case "$codename" in
48
   ulyana|uma|una)                 release="focal" ;;
49
   vanessa|vera|victoria|virginia) release="jammy" ;;
50
   xia)                            release="noble" ;;
51
   *)                              release="$codename" ;;
52
esac
53
if [ "$ID" = "rhel" ]; then
54
   is_rhel=true
55
fi
56

    
57
# get up to date version
58
if [[ "$handle_apt" == "true" ]]; then
59
   if [[ -f "/etc/apt/sources.list.d/ubuntu.sources" ]]; then
60
      $dry sudo cp /etc/apt/sources.list.d/ubuntu.sources /tmp
61
      $dry sudo sed -i '/^Types: deb$/a Types: deb-src' /etc/apt/sources.list.d/ubuntu.sources
62
   elif [[ -f "/etc/apt/sources.list.d/official-package-repositories.list" ]]; then
63
      $dry sudo cp /etc/apt/sources.list.d/official-package-repositories.list /tmp
64
      $dry sudo grep -q '^deb-src' /etc/apt/sources.list.d/official-package-repositories.list || \
65
      $dry sudo sed -e 's|^deb |deb-src |' /etc/apt/sources.list.d/official-package-repositories.list >> /etc/apt/sources.list.d/deb-src.list
66
   else
67
      $dry sudo echo "deb-src http://archive.ubuntu.com/ubuntu $release main restricted universe multiverse" >> /etc/apt/sources.list
68
   fi
69
   $dry sudo apt-get update
70
fi
71

    
72
# install ncurses source code for this version
73
if [ -z "$is_rhel" ]; then
74
   $dry apt-get -q -y source ncurses
75
else
76
   $dry yum install ncurses-devel
77
fi
78

    
79
if [[ "$handle_apt" == "true" ]]; then
80
   if [[ -f "/etc/apt/sources.list.d/ubuntu.sources" ]]; then
81
      $dry sudo mv /tmp/ubuntu.sources /etc/apt/sources.list.d/
82
   else
83
      $dry sudo mv /tmp/sources.list /etc/apt/
84
   fi
85
   $dry sudo apt-get update
86
fi
87

    
88
# check if sources obtained
89
if [ $? -ne 0 ] && [ -z "$dry" ]
90
then
91
   echo "+------------------------------------------------------------------------------+"
92
   echo "|                  Unable to get NCURSES source tree!                          |"
93
   echo "|       Check the available packages list in /etc/apt/sources.list.            |"
94
   echo "+------------------------------------------------------------------------------+"
95
   exit
96
fi
97

    
98
# patching the source files
99
$dry pushd ncurses-6.* > /dev/null
100
if [[ "$patch_ncurses" == "true" ]]; then
101
#   $dry wget https://proj.goldencode.com/downloads/ncurses/ncurses_curses_h_in_v6.4+20240113.patch
102
#   $dry wget https://proj.goldencode.com/downloads/ncurses/ncurses_lib_getch_c_v6.4+20240113.patch
103
   $dry patch include/curses.h.in      ../libncurses_curses_h_in_v6.4+20240113.patch
104
   $dry patch ncurses/base/lib_getch.c ../libncurses_lib_getch_c_v6.4+20240113.patch
105
fi
106

    
107
# configure and build object libraries
108
if [[ "$patch_ncurses" == "true" ]]; then
109
   $dry ./configure --with-termlib CFLAGS='-fPIC -O2' --with-abi-version=6 --disable-widec
110
else
111
   $dry ./configure --with-termlib CFLAGS='-fPIC -O2' --with-abi-version=6 --with-pthread --enable-pthreads-eintr --disable-widec
112
fi
113
$dry make
114

    
115
# make valid reference to updated ncurses.h
116
$dry cd include
117
$dry ln -s curses.h ncurses.h
118
$dry cd ..
119

    
120
if [[ "$patch_ncurses" == "true" ]]; then
121
   echo "+------------------------------------------------------------------------------+"
122
   echo "|                 Patched NCURSES libraries update completed.                  |"
123
else
124
   echo "+------------------------------------------------------------------------------+"
125
   echo "|               Thread-safe NCURSES libraries build completed.                 |"
126
fi
127

    
128
# Position minimal files if path is specified
129
if [[ ! -z "$target_dir" ]]; then
130
   $dry mkdir -p $target_dir
131
   $dry cp -r include $target_dir
132
   $dry cp -r lib $target_dir
133
   $dry cd $target_dir
134
   [ -n "$user" ] && $dry chown -R $user:$user $target_dir
135
fi
136

    
137
# Set up environment variable(s) if they are not set already
138
env_update=""; sudo_update=""
139
if [ -z "$NCURSES_FWD_STATIC" ]; then
140
   env_update+="export NCURSES_FWD_STATIC=\"$PWD\""$'\n'
141
   sudo_update+="Defaults env_keep += NCURSES_FWD_STATIC"$'\n'
142
fi
143
if [ -z "$NCURSES_FWD_PTHREADS" ] && [ "$patch_ncurses" != true ]; then
144
   env_update+="export NCURSES_FWD_PTHREADS=true"$'\n'
145
   sudo_update+="Defaults env_keep += NCURSES_FWD_PTHREADS"$'\n'
146
fi
147
if [ ."$env_update". != ".." ]; then
148
   if [[ "$system" == true ]]; then
149
      rc_filename='/etc/profile.d/10-ncurses.sh'
150
      msg="|         The environment has been changed! Reboot to activate changes         |"
151
      # Ensure we are making the only entry in the profile.d script
152
      [ -f "$rc_filename" ] && $dry rm -f $rc_filename 
153
      [ -z "$dry" ] && echo -n "$sudo_update" > /etc/sudoers.d/10-ncurses
154
      mode="644"
155
   else
156
      rc_filename="${homedir}/.bashrc"
157
      msg="|   The .bashrc has been changed! Please open new console to activate setup!   |"
158
   fi
159
   if [[ -z "$dry" ]]; then
160
      echo '' >> $rc_filename
161
      if [[ "$patch_ncurses" == true ]]; then
162
         echo '# set up patched NCURSES root location' >> $rc_filename
163
      else
164
         if [ -z "$NCURSES_FWD_STATIC" ]; then
165
            echo '# set up thread-safe NCURSES root location' >> $rc_filename
166
         fi
167
         if [ -z "$NCURSES_FWD_PTHREADS" ]; then
168
            echo '# and set up thread-safe NCURSES_FWD_PTHREADS variable' >> $rc_filename
169
         fi
170
      fi
171
      echo -n "$env_update" >> $rc_filename 
172
      if [[ "$system" == true ]]; then
173
         chmod $mode $rc_filename
174
      fi
175
   fi
176
   echo "|   ---------------------------   WARNING ! --------------------------------   |"
177
   echo "$msg"
178
   echo "|   ---------------------------   WARNING ! --------------------------------   |"
179
fi
180

    
181
echo "|              Please do FULL FWD rebuild to activate the changes.             |"
182
echo "+------------------------------------------------------------------------------+"
183

    
184
# back to the starting directory
185
$dry popd > /dev/null