-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ORAchk to the Oracle Toolkit (#35) #220
Changes from all commits
e4b2fe0
1d1714c
27fb68c
c652c40
da19496
329904c
f9fc032
928d74a
f0fac13
cd8eff7
43285fc
0731637
7480284
dd91795
6fa6ecc
52ab35f
a2ad6df
59f1184
64f9cb6
8ebb803
bda6d83
2d0886a
e43a8b3
2cffcb4
5bf4efa
6d9ed2b
028aeb6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,229 @@ | ||
#!/bin/bash | ||
# Copyright 2025 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# used for oracle ORAchk. install, run and uninstall ORAchk | ||
# | ||
# Check if we're using the Mac stock getopt and fail if true | ||
# shellcheck disable=SC2034 | ||
out="$(getopt -T)" | ||
if [ $? != 4 ]; then | ||
echo -e "Your getopt does not support long parameters, possibly you're on a Mac, if so please install gnu-getopt with brew" | ||
echo -e "\thttps://brewformulas.org/Gnu-getopt" | ||
exit 1 | ||
fi | ||
|
||
# do not display skipped hosts - | ||
# a misnomer, as it does not display all 'skipped' tasks | ||
export ANSIBLE_EXTRA_VARS='' | ||
# use ANSIBLE_DISPLAY_SKIPPED_HOSTS=true ./check-oracle.sh to see skipped tasks | ||
: ${ANSIBLE_DISPLAY_SKIPPED_HOSTS:=false} | ||
export ANSIBLE_DISPLAY_SKIPPED_HOSTS | ||
#echo ANSIBLE_DISPLAY_SKIPPED_HOSTS: $ANSIBLE_DISPLAY_SKIPPED_HOSTS | ||
|
||
export INVENTORY_FILE='' | ||
export AHF_LOCATION='' | ||
|
||
export AHF_LOCATION_PARAM='^gs://.+[^/]$' | ||
|
||
export ORACLE_SERVER='' | ||
export AHF_DIR='AHF' | ||
export AHF_FILE='' | ||
export AHF_INSTALL=0 | ||
export AHF_UNINSTALL=0 | ||
export RUN_ORACHK=0 | ||
|
||
export GETOPT_MANDATORY="instance-ip-addr:" | ||
export GETOPT_OPTIONAL="extra-vars:,ahf-location:,db-name:,inventory-file:,ahf-install,ahf-uninstall,run-orachk,help,debug" | ||
|
||
export GETOPT_LONG="$GETOPT_MANDATORY,$GETOPT_OPTIONAL" | ||
export GETOPT_SHORT="h" | ||
|
||
options="$(getopt --longoptions "$GETOPT_LONG" --options "$GETOPT_SHORT" -- "$@")" | ||
|
||
# shellcheck disable=SC2181 | ||
[ $? -eq 0 ] || { | ||
echo "Invalid options provided: $*" >&2 | ||
exit 1 | ||
} | ||
|
||
eval set -- "$options" | ||
|
||
help () { | ||
|
||
echo -e "\tUsage: $(basename "$0")" | ||
echo "${GETOPT_MANDATORY}" | sed 's/,/\n/g' | sed 's/:/ <value>/' | sed 's/\(.\+\)/\t --\1/' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do like the autogeneration of usage, but when I run it, I don't see --install-ahf at all: $ bash ./check-oracle.sh --inventory-file inventory_files/inventory_new_RAC --ahf-install and --run-orachk may be combined to install and run |
||
echo "${GETOPT_OPTIONAL}" | sed 's/,/\n/g' | sed 's/:/ <value>/' | sed 's/\(.\+\)/\t [ --\1 ]/' | ||
echo | ||
echo "--ahf-install and --run-orachk may be combined to install and run" | ||
echo "--extra-vars is used to pass extra ansible vars" | ||
echo " example: --extra-vars "var1=val1 var2=val2 ..."" | ||
|
||
} | ||
|
||
# check if both install and run were specified together | ||
export RUN_ENABLED=0 | ||
export INSTALL_ENABLED=0 | ||
|
||
while true | ||
do | ||
|
||
case "$1" in | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can I ask for a --debug parameter like install-oracle.sh does, which adds verbosity to the ansible-playbook command? Maybe even an --extra-vars to pass extra stuff to ansible if needed? |
||
|
||
--extra-vars) | ||
ANSIBLE_EXTRA_VARS="$2" | ||
;; | ||
|
||
--ahf-location) | ||
AHF_LOCATION="$2" | ||
;; | ||
|
||
--debug) | ||
export ANSIBLE_DEBUG=1 | ||
export ANSIBLE_DISPLAY_SKIPPED_HOSTS=true | ||
;; | ||
|
||
--help | -h) | ||
help >&2 | ||
exit 0 | ||
;; | ||
|
||
--inventory-file) | ||
INVENTORY_FILE="$2" | ||
shift; | ||
;; | ||
|
||
--db-name) | ||
ORACLE_SID="$2" | ||
shift | ||
;; | ||
|
||
--instance-ip-addr) | ||
ORACLE_SERVER="$2" | ||
shift | ||
;; | ||
|
||
--ahf-install) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If no command is specified, this script exits with success and no output at all. It would be better to show an error in this case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something here does not seem right. When I run without any options, I get this:
When run with
I think it would probably be good to include the help message here, but, there is output. Can you verify that check-oracle.sh is correct? What I see in google-toolkit-for-oracle in rel/oratk-57-orachk
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my case, I'm saw the error message and passed |
||
: ${ORACLE_SID:='NOOP'} | ||
AHF_UNINSTALL=1 | ||
AHF_INSTALL=1 | ||
INSTALL_ENABLED=1 | ||
;; | ||
|
||
--ahf-uninstall) | ||
ORACLE_SID='NOOP' | ||
AHF_UNINSTALL=1 | ||
AHF_INSTALL=0 | ||
;; | ||
|
||
--run-orachk) | ||
AHF_UNINSTALL=0 | ||
AHF_INSTALL=0 | ||
RUN_ORACHK=1 | ||
RUN_ENABLED=1 | ||
;; | ||
|
||
--) | ||
shift | ||
break | ||
;; | ||
|
||
esac | ||
|
||
shift | ||
|
||
done | ||
|
||
# one of install, uninstall or run must be called | ||
|
||
[[ $AHF_INSTALL -eq 0 ]] && [[ $AHF_UNINSTALL -eq 0 ]] && [[ $RUN_ORACHK -eq 0 ]] && { help; exit 1; } | ||
|
||
|
||
[[ -n $ANSIBLE_EXTRA_VARS ]] && { | ||
|
||
if [[ ! "$ANSIBLE_EXTRA_VARS" =~ ^([a-zA-Z_][a-zA-Z0-9_]*=[^[:space:]]+)([[:space:]]+[a-zA-Z_][a-zA-Z0-9_]*=[^[:space:]]+)*$ ]]; then | ||
echo "Invalid format for --extra-vars" | ||
echo "the extra vars should be a string of 1 or more name=value pairs separated by a space" | ||
echo "example: varname1=value varname2=value2 varname3=value3" | ||
exit 1 | ||
fi | ||
|
||
} | ||
|
||
[ "$RUN_ENABLED" -eq 1 ] && [ "$INSTALL_ENABLED" -eq 1 ] && { | ||
AHF_UNINSTALL=1 | ||
AHF_INSTALL=1 | ||
INSTALL_ENABLED=1 | ||
} | ||
|
||
[[ -z $ORACLE_SID ]] && { echo "please specify --db-name"; echo; help; exit 1; } | ||
|
||
# if an ip address is passed for --instance-ip-address, and inventory file is not specified on the cli, check for an inventory file by lookup of target hostname | ||
[[ "$ORACLE_SERVER" =~ ^[[:digit:]]{1,3}[.][[:digit:]]{1,3}[.][[:digit:]]{1,3}[.][[:digit:]]{1,3}$ ]] && [[ -z "$INVENTORY_FILE" ]] && { | ||
TARGET_HOSTNAME="$( dig +short -x $ORACLE_SERVER | cut -f1 -d\. )" | ||
TEST_INVENTORY_FILE=inventory_files/inventory_${TARGET_HOSTNAME}_${ORACLE_SID} | ||
[[ -r $TEST_INVENTORY_FILE ]] && INVENTORY_FILE="$TEST_INVENTORY_FILE" | ||
} | ||
|
||
# if the inventory file is specified on the cli, then the --instance-ip-addr or ORACLE_SERVER are not required | ||
if [[ -z $INVENTORY_FILE ]]; then | ||
[[ -z $ORACLE_SERVER ]] && { echo "please specify --instance-ip-addr"; echo; help; exit 1; } | ||
INVENTORY_FILE=inventory_files/inventory_${ORACLE_SERVER}_${ORACLE_SID} | ||
fi | ||
|
||
[[ -r $INVENTORY_FILE ]] || { | ||
echo "cannot read inventory file '$INVENTORY_FILE'" | ||
echo " please check and --instance-ip-addr" | ||
echo " and --inventory-file" | ||
exit 1 | ||
} | ||
|
||
# fail early if the AFH file format is incorrect and/or the file does not exist. | ||
[[ -n "$AHF_LOCATION" ]] || [[ $AHF_INSTALL -eq 1 ]] && { | ||
|
||
[[ ! "$AHF_LOCATION" =~ $AHF_LOCATION_PARAM ]] && { | ||
echo "Incorrect parameter provided for AHF_LOCATION: $AHF_LOCATION" | ||
echo "Example: gs://my-gcs-bucket/ahf/ahf.zip" | ||
exit 1 | ||
} | ||
|
||
( gsutil ls "$AHF_LOCATION" >/dev/null 2>&1 ) || { | ||
echo "--ahf-location file '$AHF_LOCATION' not found" | ||
exit 1; | ||
} | ||
} | ||
|
||
# Uninstall AHF | ||
[[ $AHF_UNINSTALL -eq 1 ]] && { | ||
|
||
ansible-playbook -i "$INVENTORY_FILE" check-oracle.yml \ | ||
--extra-vars "uninstall_ahf=true $ANSIBLE_EXTRA_VARS" | ||
} | ||
|
||
# Install AHF | ||
[[ $AHF_INSTALL -eq 1 ]] && { | ||
|
||
|
||
ansible-playbook -i "$INVENTORY_FILE" check-oracle.yml \ | ||
--extra-vars "uninstall_ahf=false AHF_LOCATION=$AHF_LOCATION $ANSIBLE_EXTRA_VARS" | ||
} | ||
|
||
# run ORAchk | ||
[[ $RUN_ORACHK -eq 1 ]] && { | ||
|
||
ansible-playbook -i "$INVENTORY_FILE" check-oracle.yml \ | ||
--extra-vars "uninstall_ahf=false run_orachk=true ORACLE_SID=$ORACLE_SID $ANSIBLE_EXTRA_VARS" | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind running these shell scripts through a linter like shellcheck? It has a bunch of lint-style warnings around quoting and the like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only remaining shell script is
check-oracle.sh
, and I have run it through shellcheck, and made any modifications that were appropriate.