Project

General

Profile

setup_ncurses6x.sh

Fixed bug in environmental setup - Roger Borrello, 12/12/2023 05:35 PM

Download (4.02 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>] [-sad]"
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]="a \t= Force setup of /etc/apt/sources.list and restore when done (requires sudo)"
12
   i=$((i+1)); usage[$i]="d \t= Dry run. Just show commands."
13

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

    
19
# process options
20
while getopts "h?p:sad" opt; do
21
   case $opt in
22
      p  ) target_dir=$OPTARG ;;
23
      s  ) system=true ;;
24
      a  ) handle_apt=true ;;
25
      d  ) dry="echo" ;;
26
      h | \
27
      \? ) show_usage && exit 1
28
           exit 1 ;;
29
   esac
30
done
31
shift $(($OPTIND - 1))
32

    
33
# remove previous install, if any
34
$dry rm -rf ncurses*
35

    
36
# Learn the OS so that we can handle non-Ubuntu "kind of" gracefully
37
if [ "$(cat /etc/os-release | grep "^ID=" | cut -d'=' -f2 | sed "s/\"//g")" = "rhel" ]; then
38
   is_rhel=true
39
fi
40

    
41
# get up to date version
42
if [[ "$handle_apt" == "true" ]]; then
43
   $dry cp /etc/apt/sources.list /tmp
44
   $dry sed -i '/^# deb-src /s/^# //' /etc/apt/sources.list
45
   $dry apt-get update
46
fi
47

    
48
# install ncurses source code for this version
49
if [ -z "$is_rhel" ]; then
50
   $dry apt-get -q -y source ncurses
51
else
52
   $dry yum install ncurses-devel
53
fi
54

    
55
if [[ "$handle_apt" == "true" ]]; then
56
   $dry mv /tmp/sources.list /etc/apt/
57
   $dry apt-get update
58
fi
59

    
60
# check if sources obtained
61
if [ $? -ne 0 ] && [ -z "$dry" ]
62
then
63
   echo "+------------------------------------------------------------------------------+"
64
   echo "|                  Unable to get NCURSES source tree!                          |"
65
   echo "|       Check the available packages list in /etc/apt/sources.list.            |"
66
   echo "+------------------------------------------------------------------------------+"
67
   exit
68
fi
69

    
70
# patching the source files
71
$dry pushd ncurses-6.* > /dev/null
72
$dry wget https://proj.goldencode.com/downloads/ncurses/ncurses_curses_h_in_v6.1_20200708.patch
73
$dry wget https://proj.goldencode.com/downloads/ncurses/ncurses_lib_getch_c_v6.1_20200708.patch
74
$dry patch include/curses.h.in ncurses_curses_h_in_v6.1_20200708.patch
75
$dry patch ncurses/base/lib_getch.c ncurses_lib_getch_c_v6.1_20200708.patch
76

    
77
# configure and build object libraries
78
$dry ./configure --with-termlib CFLAGS='-fPIC -O2' --with-abi-version=6
79
$dry make
80

    
81
# make valid reference to updated ncurses.h
82
$dry cd include
83
$dry ln -s curses.h ncurses.h
84
$dry cd ..
85

    
86
echo "+------------------------------------------------------------------------------+"
87
echo "|                 Patched NCURSES libraries update completed.                  |"
88

    
89
# Position minimal files if path is specified
90
if [[ ! -z "$target_dir" ]]; then
91
   $dry mkdir -p $target_dir
92
   $dry cp -r include $target_dir
93
   $dry cp -r lib $target_dir
94
   $dry cd $target_dir
95
fi
96

    
97
# setting up system variable if not yet defined to use custom libraries location
98
if [ -z "$NCURSES_FWD_STATIC" ]
99
then
100
   if [[ "$system" == "true" ]]; then
101
      rc_filename='/etc/profile.d/10-ncurses.sh'
102
      msg="|         The environment has been changed! Reboot to activate changes         |"
103
      update="export NCURSES_FWD_STATIC=\"$PWD\""
104
      rm $rc_filename
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