From a28238c98b75a4c7c097641cfe91c3878763617b Mon Sep 17 00:00:00 2001 From: Krystian Panek Date: Tue, 13 Dec 2022 09:43:36 +0100 Subject: [PATCH] AEM home dir --- .gitignore | 4 +- aem.sample.yml => aem/aem.sample.yml | 22 ++++++-- aem/api.sh | 54 +++++++++++++++++++ aem/resetup.sh | 4 -- aem/restart.sh | 4 -- aem/{ => script}/destroy.sh | 2 +- aem/{ => script}/down.sh | 0 aem/script/resetup.sh | 4 ++ aem/script/restart.sh | 4 ++ aem/{ => script}/setup.sh | 2 +- aem/{ => script}/up.sh | 0 aemw | 77 ++++++++++------------------ cmd/cli/cli.go | 6 +++ pkg/cfg/aem.yml | 2 +- pkg/cfg/config.go | 26 +++++----- pkg/instance_manager.go | 12 +++-- 16 files changed, 139 insertions(+), 84 deletions(-) rename aem.sample.yml => aem/aem.sample.yml (67%) create mode 100644 aem/api.sh delete mode 100755 aem/resetup.sh delete mode 100755 aem/restart.sh rename aem/{ => script}/destroy.sh (76%) rename aem/{ => script}/down.sh (100%) create mode 100755 aem/script/resetup.sh create mode 100755 aem/script/restart.sh rename aem/{ => script}/setup.sh (97%) rename aem/{ => script}/up.sh (100%) diff --git a/.gitignore b/.gitignore index 9ace7db4..8cca63ca 100644 --- a/.gitignore +++ b/.gitignore @@ -220,7 +220,5 @@ $RECYCLE.BIN/ *.iml /bin /lib -/aem.yml -aem.log dist/ -/config.yml +aem/home/ diff --git a/aem.sample.yml b/aem/aem.sample.yml similarity index 67% rename from aem.sample.yml rename to aem/aem.sample.yml index 4ce8b3ea..f776a6e4 100644 --- a/aem.sample.yml +++ b/aem/aem.sample.yml @@ -1,3 +1,5 @@ +# TODO before loaded by viper pre-process by some text/template engine and inject env vars + log: timestamp_format: "2006-01-02 15:04:05" full_timestamp: true @@ -8,16 +10,23 @@ log: # #output: # format: text -# file: aem.log +# file: aem/home/aem.log java: #home_path: /Library/Java/JavaVirtualMachines/jdk-11.0.15.jdk/Contents/Home instance: + # Processing mode + # 'auto' - for more than 1 local instances - 'serial', otherwise 'parallel' + # 'parallel' - for working with remote instances + # 'serial' - for working with local instances + processing_mode: auto + # Defined by single value (only remote) config_url: '' + # Defined strictly with full details (local or remote) config: local_author: http_url: http://localhost:4502 @@ -50,6 +59,13 @@ instance: license_path: '/Users/krystian.panek/Projects/gat/resource/remote/aem/instance/license.properties' unpack_path: '/Users/krystian.panek/Projects/aemc/out' -package: + package: + upload: + force: false + + osgi: + install: + start: true + start_level: 20 + refresh_packages: true - upload_force: true diff --git a/aem/api.sh b/aem/api.sh new file mode 100644 index 00000000..8e54864d --- /dev/null +++ b/aem/api.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env sh + +# print provisioning step header +step () { + DATE=$(date "+%Y-%m-%d %H:%M:%S") + echo "[$DATE]" "$@" +} + +# check last command +clc () { + if [ "$?" -ne 0 ]; then + exit "$?" + fi +} + +# format seconds to more nice format +duration () { + T=$1 + D=$((T/60/60/24)) + H=$((T/60/60%24)) + M=$((T/60%60)) + S=$((T%60)) + if [ $D -gt 0 ]; then + printf '%d day(s) ' $D + fi + if [ $H -gt 0 ]; then + printf '%d hour(s) ' $H + fi + if [ $M -gt 0 ]; then + printf '%d minute(s) ' $M + fi + if [ $D -gt 0 ] || [ $H -gt 0 ] || [ $M -gt 0 ]; then + printf 'and ' + fi + printf '%d second(s)\n' $S +} + +detectOs () { + case "$(uname)" in + 'Linux') + echo "linux" + ;; + 'Darwin') + echo "darwin" + ;; + *) + echo "windows" + ;; + esac +} + +detectArch () { + uname -m +} diff --git a/aem/resetup.sh b/aem/resetup.sh deleted file mode 100755 index 2ee48545..00000000 --- a/aem/resetup.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env sh - -. aem/destroy.sh -. aem/setup.sh diff --git a/aem/restart.sh b/aem/restart.sh deleted file mode 100755 index 67a701a8..00000000 --- a/aem/restart.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env sh - -. aem/down.sh -. aem/up.sh diff --git a/aem/destroy.sh b/aem/script/destroy.sh similarity index 76% rename from aem/destroy.sh rename to aem/script/destroy.sh index 248d9fd2..0912eddb 100755 --- a/aem/destroy.sh +++ b/aem/script/destroy.sh @@ -1,6 +1,6 @@ #!/usr/bin/env sh -. aem/down.sh +. aem/script/down.sh step "destroying instances" aem instance destroy diff --git a/aem/down.sh b/aem/script/down.sh similarity index 100% rename from aem/down.sh rename to aem/script/down.sh diff --git a/aem/script/resetup.sh b/aem/script/resetup.sh new file mode 100755 index 00000000..febc3fe0 --- /dev/null +++ b/aem/script/resetup.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env sh + +. aem/script/destroy.sh +. aem/script/setup.sh diff --git a/aem/script/restart.sh b/aem/script/restart.sh new file mode 100755 index 00000000..542be848 --- /dev/null +++ b/aem/script/restart.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env sh + +. aem/script/down.sh +. aem/script/up.sh diff --git a/aem/setup.sh b/aem/script/setup.sh similarity index 97% rename from aem/setup.sh rename to aem/script/setup.sh index a32465bc..8b58dbef 100755 --- a/aem/setup.sh +++ b/aem/script/setup.sh @@ -1,6 +1,6 @@ #!/usr/bin/env sh -. aem/up.sh +. aem/script/up.sh step "configuring replication agent on author instance" PROPS=" diff --git a/aem/up.sh b/aem/script/up.sh similarity index 100% rename from aem/up.sh rename to aem/script/up.sh diff --git a/aemw b/aemw index f7a50eed..e91b0365 100755 --- a/aemw +++ b/aemw @@ -1,74 +1,51 @@ #!/usr/bin/env sh -# Download tool - -VERSION=0.5.2 -OS="darwin" -ARCH="arm64" +. aem/api.sh -TOOL_DOWNLOAD_URL="https://github.com/wttech/aemc/releases/download/v${VERSION}/aemc-cli_${OS}_${ARCH}.tar.gz" -TOOL_BIN_ROOT="bin/aemw/$VERSION" -TOOL_BIN_ARCHIVE_FILE="$TOOL_BIN_ROOT/aemc-cli.tar.gz" -TOOL_BIN_ARCHIVE_DIR="$TOOL_BIN_ROOT/aemc-cli" -TOOL_BIN_EXEC_FILE="$TOOL_BIN_ARCHIVE_DIR/aemc-cli" +# Download tool -if [ ! -f "$TOOL_BIN_EXEC_FILE" ]; then - mkdir -p "$TOOL_BIN_ARCHIVE_DIR" - curl -o "$TOOL_BIN_ARCHIVE_FILE" -OJL "$TOOL_DOWNLOAD_URL" - tar -xvf "$TOOL_BIN_ARCHIVE_FILE" -C "$TOOL_BIN_ARCHIVE_DIR" - chmod +x "$TOOL_BIN_EXEC_FILE" +VERSION=${AEMC_VERSION:-"0.5.2"} +COMMAND_DEFAULT=${AEMC_COMMAND_DEFAULT:-"setup"} + +OS=$(detectOs) +ARCH=$(detectArch) +DOWNLOAD_URL="https://github.com/wttech/aemc/releases/download/v${VERSION}/aemc-cli_${OS}_${ARCH}.tar.gz" +BIN_ROOT="bin/aemw/$VERSION" +BIN_ARCHIVE_FILE="$BIN_ROOT/aemc-cli.tar.gz" +BIN_ARCHIVE_DIR="$BIN_ROOT/aemc-cli" +BIN_EXEC_FILE="$BIN_ARCHIVE_DIR/aemc-cli" + +if [ "$VERSION" = "dev" ]; then + make build + BIN_EXEC_FILE="bin/aemc-cli" +elif [ ! -f "$BIN_EXEC_FILE" ]; then + mkdir -p "$BIN_ARCHIVE_DIR" + curl -o "$BIN_ARCHIVE_FILE" -OJL "$DOWNLOAD_URL" + tar -xvf "$BIN_ARCHIVE_FILE" -C "$BIN_ARCHIVE_DIR" + chmod +x "$BIN_EXEC_FILE" fi -# Declare provisioning API - # shellcheck disable=SC2139 -alias aem="./$TOOL_BIN_EXEC_FILE" - -# print provisioning step header -step () { - DATE=$(date "+%Y-%m-%d %H:%M:%S") - echo "[$DATE] $@" -} - -# check last command -clc () { - if [ "$?" -ne 0 ]; then - exit "$?" - fi -} - -# format seconds to more nice format -duration () { - T=$1 - D=$((T/60/60/24)) - H=$((T/60/60%24)) - M=$((T/60%60)) - S=$((T%60)) - (( $D > 0 )) && printf '%d day(s) ' $D - (( $H > 0 )) && printf '%d hour(s) ' $H - (( $M > 0 )) && printf '%d minute(s) ' $M - (( $D > 0 || $H > 0 || $M > 0 )) && printf 'and ' - printf '%d second(s)\n' $S -} +alias aem="./$BIN_EXEC_FILE" # Include provisioning script that uses API -COMMAND_DEFAULT="setup" COMMAND="${1:-$COMMAND_DEFAULT}" -SCRIPT="aem/$COMMAND.sh" +SCRIPT="aem/script/$COMMAND.sh" if [ -f "$SCRIPT" ]; then export AEM_OUTPUT_FORMAT=${AEM_OUTPUT_FORMAT:-none} export AEM_INSTANCE_PROCESSING_MODE=${AEM_INSTANCE_PROCESSING_MODE:-parallel} - STARTED_TIMESTAMP=$SECONDS + STARTED_TIMESTAMP=$(date +%s) step "script '$COMMAND' started" + step "check progress using command 'tail -f aem/home/aem.log'" # shellcheck source=aem/*.sh . "$SCRIPT" - ENDED_TIMESTAMP=$SECONDS - ELAPSED=$((ENDED_TIMESTAMP - $STARTED_TIMESTAMP)) + ENDED_TIMESTAMP=$(date +%s) + ELAPSED=$((ENDED_TIMESTAMP - STARTED_TIMESTAMP)) step "script '$COMMAND' ended in $(duration $ELAPSED)" else aem "$@" diff --git a/cmd/cli/cli.go b/cmd/cli/cli.go index ba27fa03..41e8d8d9 100644 --- a/cmd/cli/cli.go +++ b/cmd/cli/cli.go @@ -11,9 +11,11 @@ import ( "github.com/wttech/aemc/pkg" "github.com/wttech/aemc/pkg/cfg" "github.com/wttech/aemc/pkg/common/fmtx" + "github.com/wttech/aemc/pkg/common/osx" "github.com/wttech/aemc/pkg/common/stringsx" "io" "os" + "path" "reflect" "sort" "strings" @@ -104,6 +106,10 @@ func (c *CLI) configureOutput() { } func (c *CLI) openOutputFile() *os.File { + err := osx.PathEnsure(path.Dir(c.outputFile)) + if err != nil { + return nil + } file, err := os.OpenFile(c.outputFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) if err != nil { log.Fatalf(fmt.Sprintf("cannot open/create AEM output file properly at path '%s': %s", c.outputFile, err)) diff --git a/pkg/cfg/aem.yml b/pkg/cfg/aem.yml index 4cb6e3fc..db18aecb 100644 --- a/pkg/cfg/aem.yml +++ b/pkg/cfg/aem.yml @@ -53,7 +53,7 @@ instance: quickstart: dist_path: "aem-sdk-quickstart.jar" license_path: "license.properties" - unpack_path: "out" + unpack_path: "aem/home/instance" package: upload: diff --git a/pkg/cfg/config.go b/pkg/cfg/config.go index 9c8cbb9a..daaa7e01 100644 --- a/pkg/cfg/config.go +++ b/pkg/cfg/config.go @@ -12,13 +12,11 @@ import ( ) const ( - // FileName indicates 'aem.yml' to be in CWD when launching app - FileName = "aem" - FileType = "yml" - FilePath = FileName + "." + FileType - - //EnvPrefix is a prefix that need to be added to all env vars to be used by app - EnvPrefix = "AEM" + FileBaseName = "aem" + FileType = "yml" + FileName = FileBaseName + "." + FileType + FilePath = "./aem/home" + EnvPrefix = "AEM" ) // Config defines a place for managing input configuration from various sources (YML file, env vars, etc) @@ -71,7 +69,7 @@ func readFromEnv(v *viper.Viper) { } func readFromFile(v *viper.Viper) { - v.SetConfigName(FileName) + v.SetConfigName(FileBaseName) v.SetConfigType(FileType) v.AddConfigPath(filePath()) @@ -83,7 +81,7 @@ func readFromFile(v *viper.Viper) { func filePath() string { path := os.Getenv("AEM_CONFIG_PATH") if len(path) == 0 { - path = "." + path = FilePath } return path } @@ -105,19 +103,19 @@ func (c *Config) ConfigureLogger() { var configYml string func (c *Config) Init() error { - if osx.PathExists(FilePath) { - return fmt.Errorf("config file already exists: '%s'", FilePath) + if osx.PathExists(FileName) { + return fmt.Errorf("config file already exists: '%s'", FileName) } - err := osx.FileWrite(FilePath, configYml) + err := osx.FileWrite(FileName, configYml) if err != nil { - return fmt.Errorf("cannot create initial config file: '%s'", FilePath) + return fmt.Errorf("cannot create initial config file: '%s'", FileName) } return nil } const ( InputStdin string = "STDIN" - OutputFile string = "aem.log" + OutputFile string = "aem/home/aem.log" ) func InputFormats() []string { diff --git a/pkg/instance_manager.go b/pkg/instance_manager.go index 706c60f1..fd8611c3 100644 --- a/pkg/instance_manager.go +++ b/pkg/instance_manager.go @@ -24,6 +24,12 @@ type InstanceManager struct { ProcessingMode instance.ProcessingMode } +const ( + RootPath = "aem/home/instance" + DistPath = "aem/lib/aem-sdk-quickstart.jar" + LicensePath = "aem/lib/license.properties" +) + func NewInstanceManager(aem *Aem) *InstanceManager { result := new(InstanceManager) result.aem = aem @@ -376,11 +382,11 @@ type LocalOpts struct { func (im *InstanceManager) NewLocalOpts() *LocalOpts { pathCurrent := osx.PathCurrent() return &LocalOpts{ - RootPath: pathCurrent + "/out/local_instance", + RootPath: pathCurrent + "/" + RootPath, JavaOpts: im.aem.javaOpts, QuickstartOpts: QuickstartOpts{ - DistPath: pathCurrent + "/lib/aem-sdk-quickstart.jar", - LicensePath: pathCurrent + "/lib/license.properties", + DistPath: pathCurrent + "/" + DistPath, + LicensePath: pathCurrent + "/" + LicensePath, }, } }