|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +function set_ascii_color { |
| 4 | + red="\033[0;31m" |
| 5 | + green="\033[0;32m" |
| 6 | + yellow="\033[0;33m" |
| 7 | + nc="\033[0m" |
| 8 | +} |
| 9 | + |
| 10 | +function output { |
| 11 | + echo -e $1 $2 ${nc} |
| 12 | +} |
| 13 | + |
| 14 | +set_ascii_color |
| 15 | +pwd=$(pwd) |
| 16 | +build="$pwd/build" |
| 17 | +resources="$pwd/resources" |
| 18 | +perl_ver="5.38.2" |
| 19 | +perl_build="$build/perl-$perl_ver" |
| 20 | +perl_tarfile="$resources/perl-$perl_ver.tar.gz" |
| 21 | + |
| 22 | +output ${green} "---- SCOT PERL builder packager " |
| 23 | +output ${green} "---- pwd = $pwd" |
| 24 | +output ${green} "---- resources = $resources" |
| 25 | +output ${green} "---- build = $build" |
| 26 | + |
| 27 | +function install_prereqs { |
| 28 | + output ${yellow} "Installing Apt Prerequisites" |
| 29 | + sudo DEBIAN_FRONTEND=noninteractive apt-get -y install libmagic-dev libexpat1-dev build-essential curl mysql-server libmysqlclient-dev postgresql postgresql-contrib libpq-dev krb5-config libkrb5-dev |
| 30 | +} |
| 31 | + |
| 32 | +function build_perl { |
| 33 | + output ${yellow} "Extracting PERL for building" |
| 34 | + if [[ ! -d $perl_build ]]; then |
| 35 | + mkdir -p $perl_build; |
| 36 | + fi |
| 37 | + tar xzf $perl_tarfile -C $build |
| 38 | + |
| 39 | + if [[ -r $perl_build/Makefile ]];then |
| 40 | + output ${yellow} "Cleaning Perl Previous Perl Build" |
| 41 | + cd $perl_build |
| 42 | + make clean |
| 43 | + cd $pwd |
| 44 | + fi |
| 45 | + |
| 46 | + output ${yellow} "Configuring..." |
| 47 | + cd $perl_build |
| 48 | + ./Configure -des -Dprefix=/opt/perl -Dotherlibdirs=/opt/perl/lib/perl5 |
| 49 | + |
| 50 | + output ${yellow} "Building..." |
| 51 | + make |
| 52 | + |
| 53 | + output ${yellow} "Testing..." |
| 54 | + make test |
| 55 | + |
| 56 | + output ${yellow} "Installing..." |
| 57 | + if [[ -d /opt/perl ]]; then |
| 58 | + sudo mv /opt/perl /opt/perl.bak |
| 59 | + fi |
| 60 | + |
| 61 | + sudo make install |
| 62 | + cd $pwd |
| 63 | +} |
| 64 | + |
| 65 | +function install_cpanm { |
| 66 | + output ${yellow} "Installing CPANMinus" |
| 67 | + curl -k -L https://cpanmin.us | /opt/perl/bin/perl - --sudo App::cpanminus |
| 68 | +} |
| 69 | + |
| 70 | +function install_modules { |
| 71 | + output ${yellow} "Manually installing Crypt::Curve25519" |
| 72 | + tar xzf $resources/Crypt-Curve25519-0.06.tar.gz -C $build |
| 73 | + cd $build/Crypt-Curve25519-0.06 |
| 74 | + grep -rl "fmul" ./ | xargs sed -i 's/fmul/fixedvar/g' |
| 75 | + /opt/perl/bin/perl Makefile.PL |
| 76 | + make |
| 77 | + make test |
| 78 | + sudo -E make install |
| 79 | + cd $pwd |
| 80 | + |
| 81 | + output ${yellow} "Installing GSSAPI to see why it fails" |
| 82 | + /opt/perl/bin/cpanm -v --sudo GSSAPI |
| 83 | + |
| 84 | + output ${yellow} "Installing Modules with problematic network configs" |
| 85 | + # Install Net::HTTP while disabling specific tests that conflict w/ ssl cert |
| 86 | + NO_NETWORK_TESTING=1 /opt/perl/bin/cpanm --sudo Net::HTTP |
| 87 | + |
| 88 | + # Install LWP::Protocol::https while disabling specific tests that get blocked by IT Policy |
| 89 | + NO_NETWORK_TESTING=1 /opt/perl/bin/cpanm --sudo LWP::Protocol::https |
| 90 | + |
| 91 | + output ${yellow} "Installing WWW::Mechanize without tests due to hanging test" |
| 92 | + NO_NETWORK_TESTING=1 /opt/perl/bin/cpanm -n --force --sudo WWW::Mechanize |
| 93 | + |
| 94 | + output ${yellow} "Installing Test::mysqld without tests due to hanging test" |
| 95 | + NO_NETWORK_TESTING=1 /opt/perl/bin/cpanm -n --force --sudo Test::mysqld |
| 96 | + |
| 97 | + output ${yellow} "Installing Modules in cpanfile" |
| 98 | + # Install modules from cpanfile |
| 99 | + sudo -E /opt/perl/bin/cpanm --cpanfile $resources/cpanfile --installdeps . |
| 100 | + |
| 101 | + output ${yellow} "Force installing XML::RSS:Parser::Lite due to failing test" |
| 102 | + # has a failing test that does not affect operation |
| 103 | + /opt/perl/bin/cpanm -v --force --sudo XML::RSS::Parser::Lite |
| 104 | + |
| 105 | + output ${yellow} "Re-installing Lingua::EN::StopWords due to intermittent failures" |
| 106 | + # Try installing Lingua::EN::StopWords again due to intermittent failures |
| 107 | + NO_NETWORK_TESTING=1 /opt/perl/bin/cpanm -v --sudo Lingua::EN::StopWords |
| 108 | + |
| 109 | + output ${yellow} "Verbosely Trying to install LWP::ConsoleLogger::Easy" |
| 110 | + NO_NETWORK_TESTSING=1 /opt/perl/bin/cpanm -force -sudo LWP::ConsoleLogger::Easy |
| 111 | + |
| 112 | + output ${yellow} "Manually installing File::Magic" |
| 113 | + tar xzf $resources/File-Magic-0.01.tar.gz -C $build |
| 114 | + cd $build/File-Magic-0.01 |
| 115 | + /opt/perl/bin/perl Makefile.PL |
| 116 | + make |
| 117 | + make test |
| 118 | + sudo -E make install |
| 119 | + cd $pwd |
| 120 | +} |
| 121 | + |
| 122 | +function verify_modules { |
| 123 | + output ${yellow} "Verifying Modules" |
| 124 | + modules=$(cat $resources/cpanfile | cut -d\' -f 2) |
| 125 | + modules="$modules File::Magic" |
| 126 | + missing='' |
| 127 | + |
| 128 | + for m in $modules; do |
| 129 | + /opt/perl/bin/perl -e "use $m;" 2>/dev/null |
| 130 | + if [[ "$?" != 0 ]]; then |
| 131 | + if [[ "$m" == "MooseX::AttributeShortcuts" ]];then |
| 132 | + echo "ignoring known error in $m" |
| 133 | + else |
| 134 | + missing="$missing $m" |
| 135 | + fi |
| 136 | + fi |
| 137 | + done |
| 138 | + |
| 139 | + failed='' |
| 140 | + if [[ "$missing" != "" ]]; then |
| 141 | + output ${red} "The Following Modules appear to be missing:" |
| 142 | + for x in $missing; do |
| 143 | + output ${red} " $x" |
| 144 | + fm = $(retry_module $x) |
| 145 | + if [[ "$fm" != "" ]]; then |
| 146 | + failed="$failed $fm" |
| 147 | + output ${red} "Retry of $x failed" |
| 148 | + else |
| 149 | + output ${green} "Retry of $x worked" |
| 150 | + fi |
| 151 | + done |
| 152 | + |
| 153 | + if [[ "$failed" != "" ]]; then |
| 154 | + output ${red} "The Following Modules failed Retry" |
| 155 | + for y in $failed; do |
| 156 | + output ${red} " $y" |
| 157 | + done |
| 158 | + output ${red} "Exiting build due to missing packages..." |
| 159 | + exit 1 |
| 160 | + fi |
| 161 | + else |
| 162 | + output ${green} "All modules installed" |
| 163 | + fi |
| 164 | +} |
| 165 | + |
| 166 | +function retry_module { |
| 167 | + module = "$1" |
| 168 | + /opt/perl/bin/cpanm -v --sudo $module |
| 169 | + /opt/perl/bin/perl -e "use $module;" 2>/dev/null |
| 170 | + if [[ "$?" != 0 ]]; then |
| 171 | + echo $module; |
| 172 | + fi |
| 173 | +} |
| 174 | + |
| 175 | +function copy_perl_for_debbuild { |
| 176 | + output ${yellow} "Copying Installed Perl to Debian build" |
| 177 | + mkdir -p $build/scot-perl/opt |
| 178 | + cp -rp /opt/perl $build/scot-perl/opt |
| 179 | + # tar -cf - /opt/perl | (cd $build/scot-perl; tar -xf -) |
| 180 | +} |
| 181 | + |
| 182 | +function build_deb_install_file { |
| 183 | + output ${yellow} "Building DEB install file" |
| 184 | + local files=$(find /opt/perl) |
| 185 | + for file in $files; do |
| 186 | + if [[ ! -d $file ]]; then |
| 187 | + local dir=$(dirname $file) |
| 188 | + local name=$(basename $file) |
| 189 | + echo "$name $dir" >> $build/scot-perl/DEBIAN/install |
| 190 | + fi |
| 191 | + done |
| 192 | +} |
| 193 | + |
| 194 | +function build_deb { |
| 195 | + output ${yellow} "Updating permissions of build dir" |
| 196 | + chmod -R 775 $build |
| 197 | + output ${yellow} "Packaging" |
| 198 | + if [[ ! -d $build/deb_build ]];then |
| 199 | + mkdir -p $build/deb_build |
| 200 | + fi |
| 201 | + cd $build |
| 202 | + dpkg-deb --build scot-perl |
| 203 | + cd $pwd |
| 204 | + cp $build/scot-perl.deb $build/scot-perl-install/scot-perl.$perl_ver.deb |
| 205 | +} |
| 206 | + |
| 207 | +function wrap { |
| 208 | + output ${yellow} "Wrapping" |
| 209 | + tar czvf scot.perl.install.tar.gz -C $build ./scot-perl-install |
| 210 | +} |
| 211 | + |
| 212 | +function usage { |
| 213 | + output ${yellow} "Usage: $0 [-v] [-r]" |
| 214 | + output ${green} " -v verify perl modules only" |
| 215 | + output ${green} " -r rebuild deb from current /opt/perl state" |
| 216 | +} |
| 217 | + |
| 218 | +function replace_old_js { |
| 219 | + siteperl="/opt/perl/lib/site_perl/$perl_ver" |
| 220 | + miniondir="$siteperl/Mojolicious/Plugin/Minion/resources/public/minion" |
| 221 | + cp $resources/moment.min.js $miniondir/moment/moment.js |
| 222 | + cp $resoutces/bootstrap.min.js $miniondir/bootstrap/bootstrap.js |
| 223 | + cp $resoutces/bootstrap.min.css $miniondir/bootstrap/bootstrap.css |
| 224 | + cp $resources/jquery-3.6.4.min.js $siteperl/Mojolicious/resources/public/mojo/jquery/jquery.js |
| 225 | +} |
| 226 | + |
| 227 | +while getopts "mprv" arg; do |
| 228 | + case $arg in |
| 229 | + m) |
| 230 | + echo "Rebuilding Modules..." |
| 231 | + install_modules |
| 232 | + exit 0 |
| 233 | + ;; |
| 234 | + p) |
| 235 | + echo "Installing Prerequisite Debian packages..." |
| 236 | + install_prereqs |
| 237 | + exit 0 |
| 238 | + ;; |
| 239 | + v) |
| 240 | + echo "Verify Modules..." |
| 241 | + verify_modules |
| 242 | + exit 0 |
| 243 | + ;; |
| 244 | + r) |
| 245 | + echo "Rebuilding..." |
| 246 | + copy_perl_for_debbuild |
| 247 | + build_deb_install_file |
| 248 | + build_deb |
| 249 | + wrap |
| 250 | + exit 0 |
| 251 | + ;; |
| 252 | + *) |
| 253 | + usage |
| 254 | + exit 0 |
| 255 | + ;; |
| 256 | + esac |
| 257 | +done |
| 258 | + |
| 259 | +# attempt to suppress warning |
| 260 | +# that is filling logs |
| 261 | +export no_proxy=$NO_PROXY |
| 262 | + |
| 263 | +install_prereqs |
| 264 | +build_perl |
| 265 | +install_cpanm |
| 266 | +install_modules |
| 267 | +verify_modules |
| 268 | +replace_old_js |
| 269 | +copy_perl_for_debbuild |
| 270 | +build_deb_install_file |
| 271 | +build_deb |
| 272 | +wrap |
| 273 | + |
| 274 | +mkdir -p cpanm-logs |
| 275 | +cp -r /root/.cpanm/work cpanm-logs |
0 commit comments