]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1574] shell scripts: remove the use of lists
authorAndrei Pavel <andrei@isc.org>
Fri, 11 Dec 2020 13:43:55 +0000 (15:43 +0200)
committerAndrei Pavel <andrei@isc.org>
Mon, 14 Dec 2020 10:08:11 +0000 (12:08 +0200)
src/bin/keactrl/keactrl.in
src/share/database/scripts/cql/upgrade_2.0_to_3.0.sh.in
src/share/database/scripts/cql/upgrade_3.0_to_4.0.sh.in
src/share/database/scripts/cql/upgrade_4.0_to_5.0.sh.in
src/share/database/scripts/mysql/upgrade_8.1_to_8.2.sh.in

index 1da80c511b23af217a18516c798c95fb8afadc4d..3c3b93fa8f08dca72fd7511dbabb9e8869033a8a 100644 (file)
@@ -177,8 +177,7 @@ process is not running"
 # Start the Kea process. Do not start the process if there is an instance
 # already running.
 start_server() {
-    binary_path=${1}   # Full path to the binary.
-    full_command=("${@}")    # Binary and arguments.
+    binary_path=${1}    # Full path to the binary.
     # Extract the name of the binary from the path.
     local binary_name
     binary_name=$(basename -- "${binary_path}")
@@ -189,9 +188,9 @@ start_server() {
         log_info "${binary_name} appears to be running, see: \
 PID ${_pid}, PID file: ${_pid_file}."
     else
-        log_info "Starting ${full_command[*]}"
+        log_info "Starting ${*}"
         # Start the process.
-        "${full_command[@]}" &
+        "${@}" &
     fi
 }
 
index 286d3f31b9e7a76422c7fa2790e01f9dc35f83d4..a3062a801326fb7dad55c59ff670bfc543f08de7 100644 (file)
@@ -28,9 +28,6 @@ else
     . "@abs_top_builddir@/src/bin/admin/admin-utils.sh"
 fi
 
-# Save the command line arguments for later use.
-cqlargs=("${@}")
-
 # Need a path for temporary files created during upgrade data migration
 # Use the state directory in the install path directory if it exists, otherwise
 # use the build tree
@@ -42,7 +39,7 @@ fi
 
 # Ensures the current schema version is 2.0. If not it exits.
 check_version() {
-    version=$(cql_version "${cqlargs[@]}")
+    version=$(cql_version "${@}")
 
     if [ "${version}" != "2.0" ]; then
         printf "This script upgrades 2.0 to 3.0. Reported version is %s. Skipping upgrade.\n" "${version}"
@@ -52,7 +49,7 @@ check_version() {
 
 # Peforms the schema changes from 2.0 to 3.0
 update_schema() {
-    cqlsh "${cqlargs[@]}" <<EOF
+    cqlsh "${@}" <<EOF
 -- This line starts database upgrade to version 3.0
 
 -- Add a column holding leases for user context.
@@ -188,7 +185,7 @@ migrate_host_data() {
         (id, host_ipv4_subnet_id, host_ipv6_subnet_id, option_subnet_id)\
         TO '$export_file'"
 
-    if ! cqlsh "${cqlargs[@]}" -e "$query"
+    if ! cqlsh "${@}" -e "$query"
     then
         exit_now 1 "Cassandra export failed! Could not migrate data!"
     fi
@@ -266,7 +263,7 @@ migrate_host_data() {
     # We have at least one update in the update file, so submit it # to cqlsh.
     echo "$update_cnt update statements written to $update_file"
     echo "Running the updates..."
-    if ! cqlsh "${cqlargs[@]}" -f "$update_file"
+    if ! cqlsh "${@}" -f "$update_file"
     then
         exit_now 1 "Cassandra updates failed"
     fi
@@ -274,9 +271,9 @@ migrate_host_data() {
     exit_now 0 "Updated $update_cnt of $line_cnt records"
 }
 
-check_version
-if ! update_schema; then
+check_version "{@}"
+if ! update_schema "{@}"; then
     printf 'Schema update FAILED!\n'
     exit 1
 fi
-migrate_host_data
+migrate_host_data "${@}"
index 74e5e5be652ad247a25e729c8119f741e33353a9..af41c162b8ae6f284b7dc6e60bb9aa00c21b4355 100644 (file)
@@ -37,12 +37,9 @@ else
     temp_file_dir="@abs_top_builddir@/src/share/database/scripts/cql"
 fi
 
-# Save the command line arguments for later use.
-cqlargs=("${@}")
-
 # Ensures the current schema version is 3.0. If not it exits.
 check_version() {
-    version=$(cql_version "${cqlargs[@]}")
+    version=$(cql_version "${@}")
 
     if [ "${version}" != "3.0" ]; then
         printf "This script upgrades 3.0 to 4.0. Reported version is %s. Skipping upgrade.\n" "${version}"
@@ -52,7 +49,7 @@ check_version() {
 
 # Peforms the schema changes from 3.0 to 4.0
 update_schema() {
-    cqlsh "${cqlargs[@]}" <<EOF
+    cqlsh "${@}" <<EOF
 -- This line starts database upgrade to version 4.0
 
 -- -----------------------------------------------------
@@ -105,7 +102,7 @@ EOF
 
 # Peforms the clean up schema changes from 3.0 to 4.0
 clean_up_schema() {
-    cqlsh "${cqlargs[@]}" <<EOF
+    cqlsh "${@}" <<EOF
 DROP TABLE IF EXISTS host_reservations;
 
 DROP INDEX IF EXISTS host_reservationsindex1;
@@ -146,13 +143,13 @@ clean_up() {
 # status - integer value to pass to sh:exit
 # explanation - "quoted" text message to emit to stdout
 exit_now() {
-    status=$1;shift
-    explanation=$1
+    status=$1; shift
+    explanation=$1; shift
 
     clean_up
     if [ "$status" -eq 0 ]
     then
-        clean_up_schema
+        clean_up_schema "${@}"
         echo "Data Migration SUCCESS! $explanation"
     else
         echo "Data Migration FAILURE! $explanation"
@@ -272,9 +269,9 @@ migrate_host_data() {
         TO '$export_file'"
 
 
-    if ! cqlsh "${cqlargs[@]}" -e "$query"
+    if ! cqlsh "${@}" -e "$query"
     then
-        exit_now 1 "Cassandra export failed! Could not migrate data!"
+        exit_now 1 "Cassandra export failed! Could not migrate data!" "{@}"
     fi
 
     # Strip the carriage returns that CQL insists on adding.
@@ -284,7 +281,7 @@ migrate_host_data() {
         mv $export_file.2 $export_file
     else
         # Shouldn't happen but then again we're talking about CQL here
-        exit_now 1 "Cassandra export file $export_file is missing?"
+        exit_now 1 "Cassandra export file $export_file is missing?" "{@}"
     fi
 
     # Iterate through the exported data, accumulating update statements,
@@ -337,7 +334,7 @@ migrate_host_data() {
     # If we didn't record any updates, then hey, we're good to go!
     if [ "$update_cnt" -eq 0 ]
     then
-        exit_now 0 "Completed successfully: No updates were needed"
+        exit_now 0 "Completed successfully: No updates were needed" "{@}"
     fi
 
     # We have at least one update in the update file, so submit it # to cqlsh.
@@ -356,17 +353,17 @@ migrate_host_data() {
          option_scope_id) \
         FROM '$update_file'"
 
-    if ! cqlsh "${cqlargs[@]}" -e "$query"
+    if ! cqlsh "${@}" -e "$query"
     then
-        exit_now 1 "Cassandra updates failed"
+        exit_now 1 "Cassandra updates failed" "{@}"
     fi
 
-    exit_now 0 "Updated $update_cnt of $line_cnt records"
+    exit_now 0 "Updated $update_cnt of $line_cnt records" "{@}"
 }
 
-check_version
-if ! update_schema; then
+check_version "${@}"
+if ! update_schema "${@}"; then
     printf 'Schema update FAILED!\n'
     exit 1
 fi
-migrate_host_data
+migrate_host_data "${@}"
index 0d858cae53a4599076adaa79e6b5f256e28773de..d8a23bf01eea1550cebaabc88e4eab22c41df063 100644 (file)
@@ -28,9 +28,6 @@ else
     . "@abs_top_builddir@/src/bin/admin/admin-utils.sh"
 fi
 
-# Save the command line arguments for later use.
-cqlargs=("${@}")
-
 # Need a path for temporary files created during data update
 # Use the state directory in the install path directory if it exists, otherwise
 # use the build tree
@@ -42,7 +39,7 @@ fi
 
 # Ensures the current schema version is 4.0. If not it exits.
 check_version() {
-    version=$(cql_version "${cqlargs[@]}")
+    version=$(cql_version "${@}")
 
     if [ "${version}" != "4.0" ]; then
         printf "This script upgrades 4.0 to 5.0. Reported version is %s. Skipping upgrade.\n" "${version}"
@@ -52,7 +49,7 @@ check_version() {
 
 # Peforms the schema changes from 4.0 to 5.0
 update_schema() {
-    cqlsh "${cqlargs[@]}" <<EOF
+    cqlsh "${@}" <<EOF
 -- This line starts database upgrade to version 5.0
 
 -- Add the lower case hostname column to reservations.
@@ -144,7 +141,7 @@ update_host_data() {
     query="COPY hosts (key, id, hostname) TO '$host_export_file'"
 
 
-    if ! cqlsh "${cqlargs[@]}" -e "$query"
+    if ! cqlsh "${@}" -e "$query"
     then
         exit_now 1 "Cassandra get hostname failed! Could not update host!"
     fi
@@ -221,7 +218,7 @@ update_host_data() {
     echo "$update_cnt host update statements written to $host_update_file"
     echo "Running the updates..."
 
-    if ! cqlsh "${cqlargs[@]}" -f "$host_update_file"
+    if ! cqlsh "${@}" -f "$host_update_file"
     then
         exit_now 1 "Cassandra host updates failed"
     fi
@@ -243,7 +240,7 @@ update_lease4_data() {
     query="COPY lease4 (address, hostname) TO '$lease4_export_file'"
 
 
-    if ! cqlsh "${cqlargs[@]}" -e "$query"
+    if ! cqlsh "${@}" -e "$query"
     then
         exit_now 1 "Cassandra get hostname failed! Could not update lease4!"
     fi
@@ -317,7 +314,7 @@ update_lease4_data() {
     echo "$update_cnt lease4 update statements written to $lease4_update_file"
     echo "Running the updates..."
 
-    if ! cqlsh "${cqlargs[@]}" -f "$lease4_update_file"
+    if ! cqlsh "${@}" -f "$lease4_update_file"
     then
         exit_now 1 "Cassandra lease4 updates failed"
     fi
@@ -338,7 +335,7 @@ update_lease6_data() {
     echo "Exporting hostnames to $lease6_export_file ..."
     query="COPY lease6 (address, hostname) TO '$lease6_export_file'"
 
-    if ! cqlsh "${cqlargs[@]}" -e "$query"
+    if ! cqlsh "${@}" -e "$query"
     then
         exit_now 1 "Cassandra get hostname failed! Could not update lease6!"
     fi
@@ -412,7 +409,7 @@ update_lease6_data() {
     echo "$update_cnt lease6 update statements written to $lease6_update_file"
     echo "Running the updates..."
 
-    if ! cqlsh "${cqlargs[@]}" -f "$lease6_update_file"
+    if ! cqlsh "${@}" -f "$lease6_update_file"
     then
         exit_now 1 "Cassandra lease6 updates failed"
     fi
@@ -427,11 +424,11 @@ lease4_update_file="$temp_file_dir/cql_lease4_update.cql"
 lease6_export_file="$temp_file_dir/cql_lease6_export.csv"
 lease6_update_file="$temp_file_dir/cql_lease6_update.cql"
 
-check_version
-if ! update_schema; then
+check_version "${@}"
+if ! update_schema "${@}"; then
     printf 'Schema update FAILED!\n'
     exit 1
 fi
-update_host_data
-update_lease4_data
-update_lease6_data
+update_host_data "${@}"
+update_lease4_data "${@}"
+update_lease6_data "${@}"
index 7b20c671b16ceef1e00cef51c367b23250922606..9d92543c5d7b0e2a9ebc3d8a6e2f2803d32f1473 100644 (file)
@@ -55,7 +55,6 @@ then
 fi
 
 # Save the command line args, as we use these later change_column function.
-cmdargs=("${@}")
 
 # Function to rename a column in a table.
 change_column() {
@@ -66,7 +65,7 @@ change_column() {
 
     # First let's find out if the column name in the table actually needs updating.
     sql="select count(column_name) from information_schema.columns where table_schema='$schema' and table_name = '$table' and column_name = '$ocolumn'"
-    if ! count=$(mysql -N -B "${cmdargs[@]}" -e "$sql")
+    if ! count=$(mysql -N -B "${@}" -e "${sql}")
     then
         printf 'change_column: schema query failed [%s]\n' "${sql}"
         exit 255
@@ -76,7 +75,7 @@ change_column() {
     if [ "$count" -eq 1 ]
     then
         sql="ALTER TABLE $table CHANGE COLUMN $ocolumn $ncolumn"
-        if ! mysql -N -B "${cmdargs[@]}" -e "$sql"
+        if ! mysql -N -B "${@}" -e "${sql}"
         then
             printf 'change_column: alter query failed [%s]\n' "${sql}"
             exit 255
@@ -497,5 +496,5 @@ EOF
 
 # We need to rename the columns in the option def tables because "array" is
 # a MySQL keyword as of 8.0.17
-change_column "${schema}" dhcp4_option_def array "is_array TINYINT(1) NOT NULL"
-change_column "${schema}" dhcp6_option_def array "is_array TINYINT(1) NOT NULL"
+change_column "${schema}" dhcp4_option_def array "is_array TINYINT(1) NOT NULL" "${@}"
+change_column "${schema}" dhcp6_option_def array "is_array TINYINT(1) NOT NULL" "${@}"