|
| 1 | +#!/bin/bash |
| 2 | +# ------------------------------------------------------------ |
| 3 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 4 | +# or more contributor license agreements. See the NOTICE file |
| 5 | +# distributed with this work for additional information |
| 6 | +# regarding copyright ownership. The ASF licenses this file |
| 7 | +# to you under the Apache License, Version 2.0 (the |
| 8 | +# "License"); you may not use this file except in compliance |
| 9 | +# with the License. You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, |
| 14 | +# software distributed under the License is distributed on an |
| 15 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | +# KIND, either express or implied. See the License for the |
| 17 | +# specific language governing permissions and limitations |
| 18 | +# under the License. |
| 19 | +# ------------------------------------------------------------ |
| 20 | +# This script is used to update the meeting time date on the |
| 21 | +# site. |
| 22 | +# Guidance from: |
| 23 | +# http://thelinuxtips.com/2012/12/06/finding-the-nth-particular-week-in-a-month-shell-script/ |
| 24 | + |
| 25 | +clear |
| 26 | +echo "Script to update meeting date. Assumes the meeting is\ |
| 27 | + every 3rd Saturday of the month" |
| 28 | + |
| 29 | +# constants |
| 30 | +DAY="1" |
| 31 | +FREQ="3" |
| 32 | +# ------------------------------------------------------------ |
| 33 | +# functions |
| 34 | +USAGE() |
| 35 | +{ |
| 36 | + echo "------------------------------------------------------" |
| 37 | + echo "USAGE :: updateDate YEAR MONTH WEBSITE" |
| 38 | + echo "For example: " |
| 39 | + echo "updateDate 2017 4 ~/public_html" |
| 40 | + echo "The above will return the date of the 3rd Saturday in May\ |
| 41 | + and update all html pages accordingly" |
| 42 | + echo "Valid values for YEAR ( 2016 to 2050 )" |
| 43 | + echo "Valid values for MONTH ( 1 to 12 )" |
| 44 | +} |
| 45 | + |
| 46 | + |
| 47 | +YearCheck() |
| 48 | +{ |
| 49 | + echo "$1" | grep -v "^[0-9]*$" >/dev/null 2>&1 && echo "Please enter the year" && USAGE |
| 50 | + if [[ ! "${1}" -le "2051" || "${1}" -eq "2016" ]]; then |
| 51 | + echo "Enter the correct Year [2017-2050]" |
| 52 | + USAGE |
| 53 | + fi |
| 54 | +} |
| 55 | + |
| 56 | +MonthCheck() |
| 57 | +{ |
| 58 | + echo "$1" | grep -v "^[0-9]*$" >/dev/null 2>&1 && echo "Please enter the month" && USAGE |
| 59 | + if [[ ! "${1}" -le "12" || "${1}" -eq "0" ]]; then |
| 60 | + echo "Enter the correct Month [1-12]" |
| 61 | + USAGE |
| 62 | + fi |
| 63 | +} |
| 64 | + |
| 65 | +LastDigit() |
| 66 | +{ |
| 67 | + lastD="${1: -1}" |
| 68 | + |
| 69 | + if [[ $lastD == "1" ]]; then |
| 70 | + ordinalEnding="st" |
| 71 | + elif [[ $lastD == "2" ]]; then |
| 72 | + ordinalEnding="nd" |
| 73 | + elif [[ $lastD == "3" ]]; then |
| 74 | + ordinalEnding="rd" |
| 75 | + else |
| 76 | + ordinalEnding="th" |
| 77 | + fi |
| 78 | + |
| 79 | + echo "$1$ordinalEnding" |
| 80 | +} |
| 81 | + |
| 82 | +MonthStr() |
| 83 | +{ |
| 84 | + if [[ $1 == "1" || $1 == "01" ]]; then |
| 85 | + mthStr="January" |
| 86 | + fi |
| 87 | + if [[ $1 == "2" || $1 == "02" ]]; then |
| 88 | + mthStr="February" |
| 89 | + fi |
| 90 | + if [[ $1 == "3" || $1 == "03" ]]; then |
| 91 | + mthStr="March" |
| 92 | + fi |
| 93 | + if [[ $1 == "4" || $1 == "04" ]]; then |
| 94 | + mthStr="April" |
| 95 | + fi |
| 96 | + if [[ $1 == "5" || $1 == "05" ]]; then |
| 97 | + mthStr="May" |
| 98 | + fi |
| 99 | + if [[ $1 == "6" || $1 == "06" ]]; then |
| 100 | + mthStr="June" |
| 101 | + fi |
| 102 | + if [[ $1 == "7" || $1 == "07" ]]; then |
| 103 | + mthStr="July" |
| 104 | + fi |
| 105 | + if [[ $1 == "8" || $1 == "08" ]]; then |
| 106 | + mthStr="August" |
| 107 | + fi |
| 108 | + if [[ $1 == "9" || $1 == "09" ]]; then |
| 109 | + mthStr="September" |
| 110 | + fi |
| 111 | + if [[ $1 == "10" ]]; then |
| 112 | + mthStr="October" |
| 113 | + fi |
| 114 | + if [[ $1 == "11" ]]; then |
| 115 | + mthStr="November" |
| 116 | + fi |
| 117 | + if [[ $1 == "12" ]]; then |
| 118 | + mthStr="December" |
| 119 | + fi |
| 120 | + echo "$mthStr" |
| 121 | +} |
| 122 | +# ------------------- end functions -------------------------- |
| 123 | + |
| 124 | +if [ "$#" -ne "3" ]; then |
| 125 | + USAGE |
| 126 | +else |
| 127 | + WEBSITE=$3 |
| 128 | + YearCheck $1 |
| 129 | + MonthCheck $2 |
| 130 | + NY=$1 |
| 131 | + NM=$2 |
| 132 | + oldDay=`cal $2 $1| tail +5|cut -c19,20| sed -n 1p` |
| 133 | + oldMthStr=$(MonthStr ${NM}) |
| 134 | + oldDate="$oldMthStr $(LastDigit ${oldDay}), $NY" |
| 135 | + oldDay=$((oldDay-1)) |
| 136 | + |
| 137 | + # get new date |
| 138 | + newMth=$((NM+1)) |
| 139 | + newYr=$1 |
| 140 | + |
| 141 | + |
| 142 | + if [[ $newMth == "13" ]]; then |
| 143 | + newYr=$((NY+1)) |
| 144 | + newMth="1" |
| 145 | + fi |
| 146 | + |
| 147 | + newDay=`cal $newMth $newYr| tail +5|cut -c19,20| sed -n 1p` |
| 148 | + newMthStr=$(MonthStr ${newMth}) |
| 149 | + newDate="$newMthStr $(LastDigit ${newDay}), $newYr" |
| 150 | + |
| 151 | + # change all the dates |
| 152 | + $PWD/updatePages.sh $WEBSITE "${oldDate}" "${newDate}" |
| 153 | + |
| 154 | + # add the updated files to GitHub |
| 155 | + cd $WEBSITE |
| 156 | + git add * |
| 157 | + git commit -m 'updated with new meeting date' |
| 158 | + git push origin |
| 159 | + |
| 160 | +echo "New Date: $newDate Old Date: $oldDate" |
| 161 | +fi |
0 commit comments