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