Browse Source

wip

* apply_update.sh split out into legacy and current
* untested
Abram Connelly 6 năm trước cách đây
mục cha
commit
407abf4295

+ 34 - 0
busunit/scripts/apply_update.sh

@@ -0,0 +1,34 @@
+#!/bin/bash
+#
+# Copyright (c) 2019 Clementine Computing LLC.
+# 
+# This file is part of PopuFare.
+# 
+# PopuFare is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+# 
+# PopuFare is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+# 
+# You should have received a copy of the GNU Affero General Public License
+# along with PopuFare.  If not, see <https://www.gnu.org/licenses/>.
+#
+
+## Wrapper script to handle legacy updates if need be.
+##
+
+update_file="$1"
+update_checksum="$2"
+file_size="$3"
+server_path="$4"
+file_version="$5"
+
+if tar -tf $update_file popufare.witness > /dev/null 2>&1 ; then
+  /home/bus/bin/apply_update_popufare.sh $update_file $update_checksum $file_size $server_path $file_version
+else
+  /home/bus/bin/apply_update_legacy.sh $update_file $update_checksum $file_size $server_path $file_version
+fi

+ 90 - 0
busunit/scripts/apply_update_legacy.sh

@@ -0,0 +1,90 @@
+#!/bin/sh
+#
+# Copyright (c) 2019 Clementine Computing LLC.
+# 
+# This file is part of PopuFare.
+# 
+# PopuFare is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+# 
+# PopuFare is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+# 
+# You should have received a copy of the GNU Affero General Public License
+# along with PopuFare.  If not, see <https://www.gnu.org/licenses/>.
+#
+
+update_file="$1"
+update_checksum="$2"
+file_size="$3"
+server_path="$4"
+file_version="$5"
+
+. /home/bus/bin/common_values.sh
+
+# Confirm we have a checksum that differs from our existing checksum
+#
+if [[ -f /home/bus/config/$update_file.checksum ]] ; then
+  existing_checksum=`cat /hom/bus/config/$update_file.checksum`
+  if [[ "$update_checksum" == "$existing_checksum" ]] ; then
+    echo "We already HAVE an update $update_file with checksum $update_checksum, aborting install"
+    exit 1
+  fi
+fi
+
+local_checksum=`md5sum $update_file | cut -d' ' -f1`
+
+# We are doing a 'legacy' install, so unpack the package locally and only
+# check for appropriate files in the 'config' directory.
+#
+if [[ "$update_checksum" == "$local_checksum" ]] ; then
+
+  tar -zxf $update_file
+
+  if [[ ! -d ./mnt/data2/config ]] ; then
+    echo "Legacy update did not find 'mnt/data2/config', not going further"
+    exit 0
+  fi
+
+  # We are specifically only interested in:
+  # - *.paddle
+  # - avls_freq.txt
+  # - drivers.txt
+  # - init.scm
+  # - rules.scm
+  # - rfid_patterns.txt
+  #
+  # only look for those files and deposit them in the appropriate place
+  #
+
+  find ./mnt/data2/config -name '*.paddle' -type f | \
+    xargs -n1 -I{} cp -f {} /home/bus/config
+
+  if [[ -e ./mnt/data2/config/avls_freq.txt ]] ; then
+    cp -f ./mnt/data2/config/avls_freq.txt /home/bus/config/avls_freq.txt
+  fi
+
+  if [[ -e ./mnt/data2/config/drivers.txt ]] ; then
+    cp -f ./mnt/data2/config/drivers.txt /home/bus/config/drivers.txt
+  fi
+
+  if [[ -e ./mnt/data2/config/init.scm ]] ; then
+    cp -f ./mnt/data2/config/init.scm /home/bus/config/init.scm
+  fi
+
+  if [[ -e ./mnt/data2/config/rules.scm ]] ; then
+    cp -f ./mnt/data2/config/rules.scm /home/bus/config/rules.scm
+  fi
+
+  if [[ -e ./mnt/data2/config/rfid_patterns.txt ]] ; then
+    cp -f ./mnt/data2/config/rfid_patterns.txt /home/bus/config/rfid_patterns.txt
+  fi
+
+  exit 0
+fi
+
+exit 1

+ 94 - 0
busunit/scripts/apply_update_popufare.sh

@@ -0,0 +1,94 @@
+#!/bin/sh
+#
+# Copyright (c) 2019 Clementine Computing LLC.
+# 
+# This file is part of PopuFare.
+# 
+# PopuFare is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+# 
+# PopuFare is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+# 
+# You should have received a copy of the GNU Affero General Public License
+# along with PopuFare.  If not, see <https://www.gnu.org/licenses/>.
+#
+
+update_file="$1"
+update_checksum="$2"
+file_size="$3"
+server_path="$4"
+file_version="$5"
+
+. /home/bus/bin/common_values.sh
+
+# Confirm we have a checksum that differs from our existing checksum
+#
+if [[ -f /home/bus/config/$update_file.checksum ]] ; then
+  existing_checksum=`cat /hom/bus/config/$update_file.checksum`
+  if [[ "$update_checksum" == "$existing_checksum" ]] ; then
+    echo "We already HAVE an update $update_file with checksum $update_checksum, aborting install"
+    exit 1
+  fi
+fi
+
+local_checksum=`md5sum $update_file | cut -d' ' -f1`
+
+# We are doing a 'legacy' install, so unpack the package locally and only
+# check for appropriate files in the 'config' directory.
+#
+if [[ "$update_checksum" == "$local_checksum" ]] ; then
+
+  tar -zxf $update_file install.sh
+
+  if [ -n "$PACKAGE_OWNER_STRING" ]; then
+    chown $PACKAGE_OWNER_STRING install.sh
+  fi
+
+  chmod $PACKAGE_BIN_PERMISSIONS install.sh
+
+  if (./install.sh); then
+    echo "$local_checksum" > /home/bus/config/$update_file.checksum
+    echo "$file_version" > /home/bus/config/$update_file.version
+
+    if [ "$FIX_PACKAGE_PERMS" -ne "0" ]; then
+
+      if [ -f $EXTRACT_PATH_FILE ]; then
+        pkg_path="`cat $EXTRACT_PATH_FILE`"
+        echo "Fixing permissions from package specified path $pkg_path";
+      else
+        pkg_path="$DEFAULT_EXTRACT_PATH"
+        echo "Fixing permissions from default path $pkg_path";
+      fi
+
+      /home/bus/bin/fix_pkg_perm.sh $update_file $pkg_path
+    fi
+
+    echo "Update $update_file successfully installed"
+    rm -f $update_file
+    rm -f $EXTRACT_PATH_FILE
+    if [ -f /tmp/reboot_flag ]; then
+      killall diu_minder
+      echo "Tearing down network connection"
+      if [ -f $SSH_TUNNEL_PIDFILE ]; then kill `cat $SSH_TUNNEL_PIDFILE`; sleep 30; fi
+      /usr/bin/poff gprs
+      shutdown -r now;
+      sleep 1000;
+    fi
+    exit 0
+  else
+    echo "Update $update_file failed"
+    rm -f $update_file
+    exit 1
+  fi
+else
+  echo "Update $update_file appears to be BOGUS:  Server MD5=$update_checksum Local MD5=$local_checksum"
+  rm -f $update_file
+  exit 1
+fi
+
+exit 1

+ 90 - 0
busunit/scripts/apppy_update_legacy.sh

@@ -0,0 +1,90 @@
+#!/bin/sh
+#
+# Copyright (c) 2019 Clementine Computing LLC.
+# 
+# This file is part of PopuFare.
+# 
+# PopuFare is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+# 
+# PopuFare is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+# 
+# You should have received a copy of the GNU Affero General Public License
+# along with PopuFare.  If not, see <https://www.gnu.org/licenses/>.
+#
+
+update_file="$1"
+update_checksum="$2"
+file_size="$3"
+server_path="$4"
+file_version="$5"
+
+. /home/bus/bin/common_values.sh
+
+# Confirm we have a checksum that differs from our existing checksum
+#
+if [[ -f /home/bus/config/$update_file.checksum ]] ; then
+  existing_checksum=`cat /hom/bus/config/$update_file.checksum`
+  if [[ "$update_checksum" == "$existing_checksum" ]] ; then
+    echo "We already HAVE an update $update_file with checksum $update_checksum, aborting install"
+    exit 1
+  fi
+fi
+
+local_checksum=`md5sum $update_file | cut -d' ' -f1`
+
+# We are doing a 'legacy' install, so unpack the package locally and only
+# check for appropriate files in the 'config' directory.
+#
+if [[ "$update_checksum" == "$local_checksum" ]] ; then
+
+  tar -zxf $update_file
+
+  if [[ ! -d ./mnt/data2/config ]] ; then
+    echo "Legacy update did not find 'mnt/data2/config', not going further"
+    exit 0
+  fi
+
+  # We are specifically only interested in:
+  # - *.paddle
+  # - avls_freq.txt
+  # - drivers.txt
+  # - init.scm
+  # - rules.scm
+  # - rfid_patterns.txt
+  #
+  # only look for those files and deposit them in the appropriate place
+  #
+
+  find ./mnt/data2/config -name '*.paddle' -type f | \
+    xargs -n1 -I{} cp -f {} /home/bus/config
+
+  if [[ -e ./mnt/data2/config/avls_freq.txt ]] ; then
+    cp -f ./mnt/data2/config/avls_freq.txt /home/bus/config/avls_freq.txt
+  fi
+
+  if [[ -e ./mnt/data2/config/drivers.txt ]] ; then
+    cp -f ./mnt/data2/config/drivers.txt /home/bus/config/drivers.txt
+  fi
+
+  if [[ -e ./mnt/data2/config/init.scm ]] ; then
+    cp -f ./mnt/data2/config/init.scm /home/bus/config/init.scm
+  fi
+
+  if [[ -e ./mnt/data2/config/rules.scm ]] ; then
+    cp -f ./mnt/data2/config/rules.scm /home/bus/config/rules.scm
+  fi
+
+  if [[ -e ./mnt/data2/config/rfid_patterns.txt ]] ; then
+    cp -f ./mnt/data2/config/rfid_patterns.txt /home/bus/config/rfid_patterns.txt
+  fi
+
+  exit 0
+fi
+
+exit 1

+ 88 - 0
busunit/scripts/fix_pkg_perm.sh

@@ -0,0 +1,88 @@
+#!/bin/sh
+#
+# Copyright (c) 2019 Clementine Computing LLC.
+#
+# This file is part of PopuFare.
+#
+# PopuFare is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# PopuFare is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with PopuFare.  If not, see <https://www.gnu.org/licenses/>.
+#
+
+. /home/bus/bin/common_values.sh
+
+#    This script takes two parameters, first is a tarball, and the second is the target directory it was extracted to.
+#when supplied with this information, this script updates the ownership and permissions on everything to be correct.  This
+#is pretty much only done for things which live in /home/bus/bin/ and for special SSH related files and directores.
+#
+#    See common_values.sh:
+#       PACKAGE_*_PATTERN, PACKAGE_*_PERMISSIONS contain regexes to match each filespec from the
+#     tarball against.  If they match, the matching _PERMISSIONS variable holds the permissions that will
+#     be set.  Also, each file coming out of the tarball is given (with chown) to the user and group specified
+#     by PACKAGE_OWNER_STRING.
+#
+# When called with parameters, it processes the tarball first, and even without parameters it will examine the environment
+#and iterate through any existing files defined in ALWAYS_*_LIST and apply PACKAGE_*_PERMISSIONS to them.  This is an insurance
+#policy against forgotten execute bits and overly permissive settings on directories containing ssh authorized_keys or id_rsa 
+#files which might cause ssh or sshd to refuse to allow us to make or accept connections (bye-bye updates!).  Thus we want to
+#be extremely careful to prevent this snafu and have the scripts fix it right away if it occurs.
+
+tarball="$1"
+reldir="$2"
+
+olddir="`pwd`"
+
+pat_vars="`set | egrep '^PACKAGE_[A-Z_]+_PATTERN=' | sed -r 's/^PACKAGE_([A-Z_]+)_PATTERN=.*$/\1/'`"
+always_vars="`set | egrep '^ALWAYS_[A-Z_]+_LIST=' | sed -r 's/^ALWAYS_([A-Z_]+)_LIST=.*$/\1/'`"
+
+if [ -f "$olddir/$tarball" ]; then
+
+  cd $reldir
+  tar -ztf $olddir/$tarball |
+  while read filespec; do
+
+    if [ -n "$PACKAGE_OWNER_STRING" ]; then
+      chown $PACKAGE_OWNER_STRING $filespec
+    fi
+
+    for i in $pat_vars; do
+      patvar="PACKAGE_${i}_PATTERN";
+      permvar="PACKAGE_${i}_PERMISSIONS";
+
+      if (echo "$filespec" | egrep -q "${!patvar}"); then
+        chmod ${!permvar} $filespec
+      fi
+    done
+  done
+fi
+
+cd /
+
+for grp in $always_vars; do
+  filesvar="ALWAYS_${grp}_LIST";
+  permvar="PACKAGE_${grp}_PERMISSIONS";
+
+  for fil in ${!filesvar}; do
+
+    if [ -e "$fil" ]; then
+      if [ -n "$PACKAGE_OWNER_STRING" ]; then
+        chown $PACKAGE_OWNER_STRING $fil
+      fi
+
+      chmod ${!permvar} $fil
+    fi
+
+  done
+
+done
+
+cd $olddir