diff --git a/CHANGELOG.md b/CHANGELOG.md index ee250a2..067fbc9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +# Version 1.6.0 +## New Features +- Added `update` to dc-completion + +## Improvements +- Step back to previous directory after update +- Moved `version` to own function `show_version`, for consistency +- Moved `update` to own function `update`, for consistency +- Made the unzipping during the update quiet +- Added version to `dc-completion` + +## Bug fixes +- Fixed getting containers in stacks, due to #46 + # Version 1.5.5 ## Bug fixes - Update process bugfix diff --git a/build-files/CHANGELOG.md b/build-files/CHANGELOG.md index 9f59bce..b2acabc 100644 --- a/build-files/CHANGELOG.md +++ b/build-files/CHANGELOG.md @@ -1,3 +1,13 @@ -# Version 1.5.5 +# Version 1.6.0 +## New Features +- Added `update` to dc-completion + +## Improvements +- Step back to previous directory after update +- Moved `version` to own function `show_version`, for consistency +- Moved `update` to own function `update`, for consistency +- Made the unzipping during the update quiet +- Added version to `dc-completion` + ## Bug fixes -- Update process bugfix \ No newline at end of file +- Fixed getting containers in stacks, due to #46 \ No newline at end of file diff --git a/dc b/dc index 75b4788..aa3c512 100755 --- a/dc +++ b/dc @@ -3,7 +3,7 @@ # Copyright (C) 2022 Ben Hählen ################################## # VERSION -export DC_VERSION=v1.5.5 +export DC_VERSION=v1.6.0 ###### VARIABLES if [[ -z "${DC_DIR}" ]]; then @@ -55,7 +55,12 @@ function tmp_stack_files_age(){ printf "File is too old, refreshing \n" fi cd ${STACK} - ${DC_COMMAND} ps --services -a > ${TMP_DIR}/${STACK_NAME} + # Fix for change in behaviour, remove in v2.0.0 + if [ "${DC_CMD}" = "docker-compose" ]; then + ${DC_COMMAND} ps --services -a > ${TMP_DIR}/${STACK_NAME} + else + ${DC_COMMAND} config --services > ${TMP_DIR}/${STACK_NAME} + fi cd - > /dev/null fi else @@ -63,7 +68,12 @@ function tmp_stack_files_age(){ printf "File does not exist, creating \n" fi cd ${STACK} - ${DC_COMMAND} ps --services -a > ${TMP_DIR}/${STACK_NAME} + # Fix for change in behaviour, remove in v2.0.0 + if [ "${DC_CMD}" = "docker-compose" ]; then + ${DC_COMMAND} ps --services -a > ${TMP_DIR}/${STACK_NAME} + else + ${DC_COMMAND} config --services > ${TMP_DIR}/${STACK_NAME} + fi cd - > /dev/null fi done @@ -494,11 +504,63 @@ function list(){ printf "=================================== \n" printf "Stack ${RED}${STACK_NAME}${NC} contains services: \n" cd ${STACK} - ${DC_COMMAND} ps --services -a | tee ${TMP_DIR}/${STACK_NAME} + # Fix for change in behaviour, remove in v2.0.0 + if [ "${DC_CMD}" = "docker-compose" ]; then + ${DC_COMMAND} ps --services -a | tee ${TMP_DIR}/${STACK_NAME} + else + ${DC_COMMAND} config --services | tee ${TMP_DIR}/${STACK_NAME} + fi cd - > /dev/null done } +# VERSION +function show_version(){ + export LATEST_VERSION=$(curl --silent https://api.github.com/repos/brhahlen/dc/releases/latest | grep -Po '"tag_name": "\K.*?(?=")') + if [[ ${DC_VERSION} =~ "dev" ]]; then + printf "This is version ${RED}${DC_VERSION}${NC} of ${RED}dc${NC} \n" + printf "This is a development version \n" + printf "The latest release version is ${BLUE}${LATEST_VERSION}${NC} \n" + else + printf "This is version ${DC_VERSION} of ${RED}dc${NC} \n" + printf "Release notes can be found at https://github.com/brhahlen/dc/releases/tag/${DC_VERSION} \n" + if [ ! "$(printf '%s\n' "${LATEST_VERSION}" "${DC_VERSION}" | sort -V | head -n1)" = "${LATEST_VERSION}" ]; then + printf "#################################### \n" + printf "A newer version of ${RED}dc${NC} is avaiable \n" + printf "The latest release version is ${BLUE}${LATEST_VERSION}${NC} \n" + printf "This can be found at https://github.com/brhahlen/dc/releases/tag/${LATEST_VERSION} \n" + fi + fi +} + +function update(){ + export LATEST_VERSION=$(curl --silent https://api.github.com/repos/brhahlen/dc/releases/latest | grep -Po '"tag_name": "\K.*?(?=")') + export UPDATE_TMP=/tmp/dc_update + printf "You are on version ${DC_VERSION} of ${RED}dc${NC} \n" + if [ ! "$(printf '%s\n' "${LATEST_VERSION}" "${DC_VERSION}" | sort -V | head -n1)" = "${LATEST_VERSION}" ]; then + printf "Version ${BLUE}${LATEST_VERSION}${NC} of ${RED}dc${NC} is available and will be downloaded and installed \n" + if [ ! -d ${UPDATE_TMP} ]; then + printf "${UPDATE_TMP} does not exist. Creating... \n" + mkdir -p ${UPDATE_TMP} + else + printf "Cleanup previous update files... \n" + rm -rf ${UPDATE_TMP} + mkdir ${UPDATE_TMP} + fi + printf "Downloading... \n" + wget -q --show-progress https://github.com/brhahlen/dc/releases/download/${LATEST_VERSION}/dc-release.zip -O ${UPDATE_TMP}/dc-release.zip + printf "Extracting... \n" + unzip -q ${UPDATE_TMP}/dc-release.zip -d ${UPDATE_TMP} + printf "Updating... \n" + cd ${UPDATE_TMP} + bash ${UPDATE_TMP}/dc install + cd - > /dev/null + printf "Done \n" + else + printf "This is the latest version, no update needed \n" + fi +} + ###### CASES # Verbosity, yes, no? while getopts ":v" opt; do @@ -584,48 +646,11 @@ done ;; # ----------- update ------------ "update") - export LATEST_VERSION=$(curl --silent https://api.github.com/repos/brhahlen/dc/releases/latest | grep -Po '"tag_name": "\K.*?(?=")') - export UPDATE_TMP=/tmp/dc_update - printf "You are on version ${DC_VERSION} of ${RED}dc${NC} \n" - if [ ! "$(printf '%s\n' "${LATEST_VERSION}" "${DC_VERSION}" | sort -V | head -n1)" = "${LATEST_VERSION}" ]; then - printf "Version ${BLUE}${LATEST_VERSION}${NC} of ${RED}dc${NC} is available and will be downloaded and installed \n" - if [ ! -d ${UPDATE_TMP} ]; then - printf "${UPDATE_TMP} does not exist. Creating... \n" - mkdir -p ${UPDATE_TMP} - else - printf "Cleanup previous update files... \n" - rm -rf ${UPDATE_TMP} - mkdir ${UPDATE_TMP} - fi - printf "Downloading... \n" - wget -q --show-progress https://github.com/brhahlen/dc/releases/download/${LATEST_VERSION}/dc-release.zip -O ${UPDATE_TMP}/dc-release.zip - printf "Extracting... \n" - unzip ${UPDATE_TMP}/dc-release.zip -d ${UPDATE_TMP} - printf "Updating... \n" - cd ${UPDATE_TMP} - bash ${UPDATE_TMP}/dc install - printf "Done \n" - else - printf "This is the latest version, no update needed \n" - fi + update ;; # ----------- version ------------ "version") - export LATEST_VERSION=$(curl --silent https://api.github.com/repos/brhahlen/dc/releases/latest | grep -Po '"tag_name": "\K.*?(?=")') - if [[ ${DC_VERSION} =~ "dev" ]]; then - printf "This is version ${RED}${DC_VERSION}${NC} of ${RED}dc${NC} \n" - printf "This is a development version \n" - printf "The latest release version is ${BLUE}${LATEST_VERSION}${NC} \n" - else - printf "This is version ${DC_VERSION} of ${RED}dc${NC} \n" - printf "Release notes can be found at https://github.com/brhahlen/dc/releases/tag/${DC_VERSION} \n" - if [ ! "$(printf '%s\n' "${LATEST_VERSION}" "${DC_VERSION}" | sort -V | head -n1)" = "${LATEST_VERSION}" ]; then - printf "#################################### \n" - printf "A newer version of ${RED}dc${NC} is avaiable \n" - printf "The latest release version is ${BLUE}${LATEST_VERSION}${NC} \n" - printf "This can be found at https://github.com/brhahlen/dc/releases/tag/${LATEST_VERSION} \n" - fi - fi + show_version ;; # ----------- All others ------------ "help") diff --git a/dc-completion b/dc-completion index 18b1526..d426d93 100755 --- a/dc-completion +++ b/dc-completion @@ -1,6 +1,9 @@ #/usr/bin/env bash # Copyright (C) 2022 Ben Hählen # This is the completion file for `dc` +############## +# Version 1.6.0 +############## _dc_completions() { local CUR PREV OPTS BASE @@ -22,7 +25,7 @@ _dc_completions() fi # Basic/main options that will be completed - OPTS="install up down restart-stack-hard restart-stack-soft logs-stack start stop restart pull logs network list help version" + OPTS="install up down restart-stack-hard restart-stack-soft logs-stack start stop restart pull logs network list help update version" # Based on the arguments, we can run functions case "$cmd" in