sh 为LINE集成初始化REDIS
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 为LINE集成初始化REDIS相关的知识,希望对你有一定的参考价值。
#!/usr/bin/env bash
shopt -s extglob
set -o errtrace
#set -o errexit
set +o noclobber
# DEFAULTS
NOOP=
FORCE=0
VERBOSE=1
SHOW_TRACE=0
CONTAINER=
CONFIG_ADMIN_USER=admin
CONFIG_ADMIN_PASSWORD=admin
LINE_STICKERS_ROOT=/var/cache/line/stickers
LOCAL_STORE_PORT=80
LOCAL_STORE_ROOT=/tmp
function die() {
local message=$1
local errorlevel=$2
[[ -z $message ]] && message='Died'
[[ -z $errorlevel ]] && errorlevel=1
echo -e "\e[0;31m$message\e[0m" >&2
exit $errorlevel
}
function usage() { # {{{2
echo "$(basename $0) [options]"
echo " Initializes the REDIS database of a Line Integration"
echo " Options are:"
echo " --config_admin_user=username"
echo " Sets the username for the Configuration Service administror."
echo " Default: admin"
echo " --config_admin_password=password"
echo " Sets the password for the Configuration Service administror."
echo " Default: admin"
echo " --container=container"
echo " Sets the name of the Docker container to use."
echo " --local_store=path"
echo " Sets the local store root."
echo " --help, -h, -? "
echo " Prints some help on the output."
echo " --noop, --dry-run "
echo " Do not execute instructions that would make changes to the system (write files, install software, etc)."
echo " --quiet "
echo " Runs the script as silently as possible."
echo " --verbose "
echo " Runs the script verbosely, that's by default."
echo " --yes, --assumeyes, -y "
echo " Answers yes to any questions automatiquely."
} # 2}}}
function parse_args() { # {{{2
while :; do
case $1 in
--config_admin_user|--config_adminuser|--configadminuser|--config-admin-user|--config-adminuser)
[[ -z $2 || ${2:0:1} == '-' ]] && die "Argument for option $1 is missing"
CONFIG_ADMIN_USER=$2
shift 2
continue
;;
--config_admin_user=*?|--config_adminuser=*?|--configadminuser=*?|--config-admin-user=*?|--config-adminuser=*?)
CONFIG_ADMIN_USER=${1#*=} # delete everything up to =
;;
--config_admin_user=|--config_adminuser=|--configadminuser=|--config-admin-user=|--config-adminuser=)
die "Argument for option $1 is missing"
;;
--config_admin_password|--config_adminpassword|--configadminpassword|--config-admin-password|--config-adminpassword)
[[ -z $2 || ${2:0:1} == '-' ]] && die "Argument for option $1 is missing"
CONFIG_ADMIN_PASSWORD=$2
shift 2
continue
;;
--config_admin_password=*?|--config_adminpassword=*?|--configadminpassword=*?|--config-admin-password=*?|--config-adminpassword=*?)
CONFIG_ADMIN_PASSWORD=${1#*=} # delete everything up to =
;;
--config_admin_password=|--config_adminpassword=|--configadminpassword=|--config-admin-password=|--config-adminpassword=)
die "Argument for option $1 is missing"
;;
--container)
[[ -z $2 || ${2:0:1} == '-' ]] && die "Argument for option $1 is missing"
CONTAINER=$2
shift 2
continue
;;
--container=*)
CONTAINER=${1#*=} # delete everything up to =
;;
--container=)
die "Argument for option $1 is missing"
;;
--local_store|--local-store)
[[ -z $2 || ${2:0:1} == '-' ]] && die "Argument for option $1 is missing"
LOCAL_STORE_ROOT=$2
shift 2
continue
;;
--local_store=*|--local-store=*)
LOCAL_STORE_ROOT=${1#*=} # delete everything up to =
;;
--local_store=|--local-store)
die "Argument for option $1 is missing"
;;
# Standard options
--force)
echo "This program will overwrite the current configuration"
FORCE=1
;;
-h|-\?|--help)
usage
exit 0
;;
--noop|--dry_run|--dry-run)
echo "This program will execute in dry mode, your system will not be modified"
NOOP=:
NOOP=echo
;;
--quiet)
VERBOSE=0
;;
-v|--verbose)
VERBOSE=$((VERBOSE + 1))
;;
-y|--yes|--assumeyes|--assume_yes|--assume-yes) # All questions will get a "yes" answer automatically
ASSUMEYES=1
;;
-?*) # Invalid options
echo "Unknown option $1 will be ignored"
;;
--) # Force end of options
shift
break
;;
*) # End of options
break
;;
esac
shift
done
[[ -z $CONTAINER ]] && die "Missing Container" 0
return 0
} # 2}}}
function main() {
parse_args "$@" ; status=$? && [[ $status != 0 ]] && die "Failed to parse command line, error: $status" $status
$NOOP docker exec $CONTAINER redis-cli set "config:users:${CONFIG_ADMIN_USER}:password" "$CONFIG_ADMIN_PASSWORD"
$NOOP docker exec $CONTAINER redis-cli set "config:line:storage:type" "\"local\""
$NOOP docker exec $CONTAINER redis-cli set "config:line:storage:local_path" "$LINE_STICKERS_ROOT"
$NOOP docker exec $CONTAINER redis-cli set "config:pureconnect:storage:port" "$LOCAL_STORE_PORT"
$NOOP docker exec $CONTAINER redis-cli set "config:pureconnect:storage:local_path" "$LOCAL_STORE_ROOT/store"
$NOOP docker exec $CONTAINER redis-cli set "config:errors:error.generic:id" "\"error.generic\""
$NOOP docker exec $CONTAINER redis-cli set "config:errors:error.generic:messages:en" "\"We are sorry, but we cannot process your request at the moment. Please contact us again in a few moments.\""
$NOOP docker exec $CONTAINER redis-cli set "config:errors:error.generic:messages:fr" "\"Veuillez nous excuser car nous ne sommes pas en mesure de traiter votre demande en ce moment, Veuillez nous recontacter un peu plus tard.\""
$NOOP docker exec $CONTAINER redis-cli set "config:errors:error.generic:messages:ja" "\"申し訳ございません。しばらくしてから再度お試しください。\""
}
main "$@"
以上是关于sh 为LINE集成初始化REDIS的主要内容,如果未能解决你的问题,请参考以下文章