bbbec053420b89c64590c2316bc7e222dd15716d
[feisty_meow.git] / scripts / core / prep_feisty_host.sh
1 #!/usr/bin/env bash
2
3 # this is the feisty meow host preparation script.  it installs all the packages required to run and build feisty meow scripts and applications.
4
5 # preconditions and dependencies--this script itself depends on:
6 #   feisty meow
7 #   bash
8 #   anything else?
9
10 # note that this list of items is never totally complete, since feisty meow keeps expanding and mutating.  for example, we now have a few
11 # python scripts starting to sneak in.  there are assuredly lots of python packages we should be installing in here now, but we aren't yet.
12 # this is a best effort script, to at least get feisty meow able to run its core scripts and to build.  although it's always appreciated
13 # when things we rely on get installed too...
14
15 ####
16
17 ORIGINATING_FOLDER="$( \cd "$(\dirname "$0")" && /bin/pwd )"
18 CORE_SCRIPTS_DIR="$(echo "$ORIGINATING_FOLDER" | tr '\\\\' '/' )"
19 THIS_TOOL_NAME="$(basename "$0")"
20
21 # set up the feisty_meow dir.
22 pushd "$CORE_SCRIPTS_DIR/../.." &>/dev/null
23 #source "$CORE_SCRIPTS_DIR/functions.sh"
24 echo originating folder is $ORIGINATING_FOLDER
25 export FEISTY_MEOW_APEX="$(/bin/pwd)"
26 echo feisty now apex is FEISTY_MEOW_APEX=$FEISTY_MEOW_APEX
27
28 ####
29
30 # helper scripts...
31 #
32 # these come from other places in the feisty meow ecosystem, but they are here
33 # because this script is kind of a bootstrapping process for our scripts and code.
34 # we don't want to assume anything about the presence of the rest of feisty meow
35 # at this point in the process.
36
37 function exit_on_error() {
38   if [ $? -ne 0 ]; then
39     echo -e "\n\nan important action failed and this script will stop:\n\n$*\n\n*** Exiting script..."
40 #    error_sound
41     exit 1
42   fi
43 }
44
45 ####
46
47 function whichable()
48 {
49   local to_find="$1";
50   shift;
51   local WHICHER="$(/usr/bin/which which 2>/dev/null)";
52   if [ $? -ne 0 ]; then
53       echo;
54       return 2;
55   fi;
56   local sporkenz;
57   sporkenz=$($WHICHER "$to_find" 2>/dev/null);
58   local err=$?;
59   echo $sporkenz;
60   return $err
61 }
62
63 ####
64
65 #hmmm: copy to mainline scripts.
66 function apt_cyg_finder()
67 {
68   if whichable apt-cyg; then
69     return 0  # success.
70 #hmmm: is that the right syntax for bash?
71   else
72     echo "
73 The apt-cyg tool does not seem to be available for cygwin.
74 Please follow the install instructions at:
75     https://github.com/transcode-open/apt-cyg
76 "
77     return 13  # not found.
78   fi
79 }
80
81 ####
82
83 #hmmm: copy to mainline scripts also.
84 # figures out what kind of installation packager application is
85 # used on this machine and invokes it to install the list of
86 # packages provided as parameters.
87 function install_system_package()
88 {
89   local packages=("${@}")
90     # pull out the array of packages from the command line.
91   if whichable apt; then
92     # ubuntu or debian or other apt-based OSes...
93     sudo apt install "${packages[@]}"
94     return $?
95   elif whichable yum; then  
96     # rpm based with yum available...
97     sudo yum install "${packages[@]}"
98     return $?
99   elif [ ! -z "$IS_DARWIN" ]; then
100     # macos based...
101     brew install "${packages[@]}"
102     return $?
103   elif [ "$OS" == "Windows_NT" ]; then
104     # windows-based with cygwin (or we'll fail out currently).
105     if apt_cyg_finder; then
106       apt-cyg install perl-File-Which perl-Text-Diff
107       return $?
108     else
109       echo "apt-cyg is not currently available on this system.  please install cygwin and apt-cyg."
110       return 1
111     fi
112   else
113     echo "Unknown installer application for this platform."
114     return 1
115   fi
116 }
117
118 ####
119
120 # load feisty meow environment here, but first test that we *can* load it.
121
122 #hmmm: currently, this script needs the system to have already been configured?
123 #  that's the implication of calling launch_feisty...
124 #  can we find that same bootstrapping code that will reconfigure first?
125 #more about this...
126 #    hmmm: we need clean starty type approach!  must not expect feisty to already be configured for use!
127 #    e.g.?? $ bash /opt/feistymeow.org/feisty_meow/scripts/core/reconfigure_feisty_meow.sh
128 #    hmmm: above ALSO ESSENTIAL TO GET RIGHT!
129
130 BASE_PHASE_MESSAGE="Feisty Meow subsystems integrity check: "
131
132 # is our main variable set?
133 PHASE_MESSAGE="$BASE_PHASE_MESSAGE presence of FEISTY_MEOW_APEX variable"
134 if [ -z "$FEISTY_MEOW_APEX" ]; then
135   false; exit_on_error $PHASE_MESSAGE
136 fi
137
138 # simple brute force check.  can we go there?
139 PHASE_MESSAGE="$BASE_PHASE_MESSAGE check on directory $FEISTY_MEOW_APEX"
140 pushd $FEISTY_MEOW_APEX &> /dev/null
141 exit_on_error $PHASE_MESSAGE
142 popd &> /dev/null
143
144 # now ask feisty if it's there; should work as long as our scripts are in place.
145 #PHASE_MESSAGE="$BASE_PHASE_MESSAGE inquiry is_feisty_up"
146 #bash $FEISTY_MEOW_APEX/scripts/core/is_feisty_up.sh
147 #exit_on_error $PHASE_MESSAGE
148
149 # standard load-up.
150 #hmmm: this will currently fail if reconfigure has never been called.
151 #NO NO NO. source "$FEISTY_MEOW_SCRIPTS/core/launch_feisty_meow.sh"
152 # we are preparing to get feisty running; how can we use feisty during
153 # that process?  so bad.
154
155 ####
156
157 # figure out which kind of OS we're on first, from ground up by seeing
158 # how this system can install things.
159
160 opsystem_here=unknown
161
162 if whichable apt; then
163   # ubuntu or debian or other apt-based OSes...
164   opsystem_here=debianesque
165 elif whichable yum; then  
166   # rpm based with yum available...
167   opsystem_here=redhatty
168 elif [ ! -z "$IS_DARWIN" ]; then
169   # macos based...
170   opsystem_here=macos
171 elif [ "$OS" == "Windows_NT" ]; then
172   # windows-based with cygwin (or we'll fail out currently).
173   opsystem_here=windoze
174 fi
175
176 ####
177
178 # default value of our package list is to fail out, since we
179 # may not be able to determine what OS this is running on.
180 PAX=(noop)
181
182 ####
183
184 # first we install the low-level crucial bits for scripts to work...
185
186 PHASE_MESSAGE="installing script modules"
187
188 if [ "$opsystem_here" == "debianesque" ]; then
189   PAX=(libfile-which-perl libtext-diff-perl)
190 elif [ "$opsystem_here" == "redhatty" ]; then
191   PAX=(perl-Env perl-File-Which perl-Text-Diff)
192 elif [ "$opsystem_here" == "macos" ]; then
193   PAX=(dos2unix openssl)
194 elif [ "$opsystem_here" == "windoze" ]; then
195   PAX=(perl-File-Which perl-Text-Diff)
196 fi
197
198 install_system_package "${PAX[@]}"
199 exit_on_error $PHASE_MESSAGE
200
201 ####
202
203 # then the builder packages...
204
205 PHASE_MESSAGE="installing code builder packages"
206
207 if [ "$opsystem_here" == "debianesque" ]; then
208   PAX=(mawk build-essential librtmp-dev libcurl4-gnutls-dev libssl-dev)
209 elif [ "$opsystem_here" == "redhatty" ]; then
210   PAX=(curl-devel gcc gcc-c++ make gawk openssl-devel.x86_64 zlib-devel)
211 elif [ "$opsystem_here" == "macos" ]; then
212   PAX=(mawk gpg meld openjdk)
213 elif [ "$opsystem_here" == "windoze" ]; then
214   PAX=(gawk libcurl-devel meld mingw64-i686-openssl openssl openssl-devel libssl-devel zlib-devel)
215 fi
216
217 install_system_package "${PAX[@]}"
218 exit_on_error $PHASE_MESSAGE
219
220 ####
221
222 # install other external packages and whatnot.
223
224 PHASE_MESSAGE="installing additional helper packages"
225
226 if [ "$opsystem_here" == "debianesque" ]; then
227   PAX=(screen python3 python3-pip xserver-xorg xorg-docs)
228 elif [ "$opsystem_here" == "redhatty" ]; then
229   PAX=(screen python3 python3-pip xserver-xorg xorg-docs)
230 elif [ "$opsystem_here" == "macos" ]; then
231   PAX=(screen python3 pip xserver-xorg xorg-docs)
232 elif [ "$opsystem_here" == "windoze" ]; then
233   PAX=(screen python3 pip3 xserver-xorg xorg-docs)
234 fi
235
236 install_system_package "${PAX[@]}"
237 exit_on_error $PHASE_MESSAGE
238
239 ####
240
241 # get ready to finish up.
242
243 #...finishing steps...  if any.
244
245 # all done now.
246 exit 0
247
248 ####
249
250
251 #############################
252 #scavenging line
253 #############################
254
255 #The "kona" collection depends on Java version 8 or better.
256 #| Ubuntu:
257 #| Set up the java PPA archive as described here:
258 #| https://launchpad.net/~webupd8team/+archive/ubuntu/java
259
260 #not needed at the moment.
261 #echo "bailing because script is immature.  farts!"
262 #exit 1
263