Skip to content

Commit

Permalink
fix: docker compose
Browse files Browse the repository at this point in the history
Signed-off-by: Xinwei Xiong (cubxxw) <[email protected]>
  • Loading branch information
cubxxw committed Dec 16, 2023
1 parent 647c703 commit 597dc01
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ sudo docker compose up -d
**Setting configuration items:**

```bash
cp ./deployments/templates/config.yaml ./config/config.yaml
make init
```

> Then modify the configuration file `config/config.yaml` according to your needs
Expand Down
95 changes: 78 additions & 17 deletions scripts/init-config.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
#!/usr/bin/env bash
# Copyright © 2023 OpenIM. All rights reserved.
#
# 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.

# This script automatically initializes various configuration files and can generate example files.
#!/bin/bash

set -o errexit
set -o nounset
Expand All @@ -23,4 +8,80 @@ set -o pipefail
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..

cp ${OPENIM_ROOT}/deployments/templates/config.yaml ${OPENIM_ROOT}/config/config.yaml
config_file="${OPENIM_ROOT}/config/config.yaml"

# Initialize flags
FORCE=false
SKIP=false

show_help() {
echo "Usage: init-config.sh [options]"
echo "Options:"
echo " -h, --help Show this help message"
echo " --force Overwrite existing files without prompt"
echo " --skip Skip generation if file exists"
echo " --clean-config Clean all configuration files"
}

clean_config() {
echo "Cleaning configuration files..."
rm -f "${config_file}"
echo "Configuration files cleaned."
}

generate_config() {
echo "Generating configuration file..."
cp "${OPENIM_ROOT}/deployments/templates/config.yaml" "${config_file}"
echo "Configuration file generated."
}

overwrite_prompt() {
while true; do
read -p "Configuration file exists. Overwrite? [Y/N]: " yn
case $yn in
[Yy]* ) generate_config; break;;
[Nn]* ) echo "Skipping generation."; exit;;
* ) echo "Please answer yes or no.";;
esac
done
}

# Parse command line arguments
for i in "$@"
do
case $i in
-h|--help)
show_help
exit 0
;;
--force)
FORCE=true
shift
;;
--skip)
SKIP=true
shift
;;
--clean-config)
clean_config
exit 0
;;
*)
# unknown option
show_help
exit 1
;;
esac
done

if [[ "${FORCE}" == "true" ]]; then
generate_config
elif [[ "${SKIP}" == "true" ]] && [[ -f "${config_file}" ]]; then
echo "Configuration file already exists. Skipping generation."
else
if [[ -f "${config_file}" ]]; then
overwrite_prompt
else
generate_config
fi
fi

0 comments on commit 597dc01

Please sign in to comment.