# Copyright 2023 Oslo University Hospital # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # # 3. Neither the name of the copyright holder nor the names of its contributors # may be used to endorse or promote products derived from this software without # specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # SYMLINK_TARGET="${EROOT}/etc/PlusServer/current-config.xml" CONFIG_DIR="${EROOT}/etc/PlusServer" find_targets() { local targets for file in "${CONFIG_DIR}"/*.xml; do local basename=$(basename "${file}" .xml) if [[ -e ${file} && ${file} != *~ && ${basename} != "current-config" ]]; then targets="${targets}\n${basename}" fi done echo -ne ${targets} | sort -u } do_list() { local n targets=( $(find_targets) ) local current_target=$(basename "$(readlink "${SYMLINK_TARGET}")" .xml) write_list_start \ "Available PlusServer XML configurations ($(highlight '*') is current):" for (( n = 0; n < ${#targets[@]}; ++n )); do if [[ "${targets[n]}" == "${current_target}" ]]; then targets[n]=$(highlight_marker "${targets[n]}") fi done write_numbered_list -m "(none found)" "${targets[@]}" return 0 } do_set() { local target_number="${1}" [ -z "${target_number}" ] && die -q "You didn't specify any XML configuration to set" targets=( $(find_targets) ) is_number "${target_number}" && \ target=${targets[$(( ${target_number} - 1 ))]} [ -z "${target}" ] && \ die -q "Target \"${1}\" doesn't appear to be valid!" rm -f "${SYMLINK_TARGET}" ln -s "${CONFIG_DIR}/${target}.xml" "${SYMLINK_TARGET}" || \ die -q "Failed to create symlink from '${target}.xml' to '${SYMLINK_TARGET}'" }