-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhako-mmap-set.bash
61 lines (53 loc) · 1.66 KB
/
hako-mmap-set.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
show_usage() {
echo "Usage:"
echo " $0 [-r] -p /path/to # Set custom path or reset to default"
exit 1
}
# デフォルト値
default_shm_type="shm"
default_core_mmap_path="/var/lib/hakoniwa/mmap"
config_file="/etc/hakoniwa/cpp_core_config.json"
# 引数チェック
while getopts ":rp:" opt; do
case $opt in
r)
reset=1
;;
p)
path_to=$OPTARG
;;
\?)
show_usage
;;
esac
done
# パスが指定されていない場合の処理
if [ -z "$path_to" ] && [ -z "$reset" ]; then
echo "Error: Path must be specified with -p option."
show_usage
fi
# コンフィグファイルの存在チェック
if [ ! -f "$config_file" ]; then
echo "Error: Configuration file does not exist at $config_file"
exit 1
fi
# jqがインストールされているかチェック
if ! command -v jq &> /dev/null; then
echo "Error: jq is not installed. Please install jq to use this script."
exit 1
fi
# -r オプションが指定されている場合、デフォルト値にリセット
if [ ! -z "$reset" ]; then
jq --arg shm_type "$default_shm_type" --arg core_mmap_path "$default_core_mmap_path" \
'.shm_type = $shm_type | .core_mmap_path = $core_mmap_path' \
"$config_file" > tmp.$$.json && mv tmp.$$.json "$config_file"
echo "Configuration reset to default."
else
# カスタムパスで更新
jq --arg shm_type "mmap" --arg core_mmap_path "$path_to" \
'.shm_type = $shm_type | .core_mmap_path = $core_mmap_path' \
"$config_file" > tmp.$$.json && mv tmp.$$.json "$config_file"
echo "Configuration updated with custom path."
fi
echo "INFO: updated ${config_file}"