Skip to content

Commit

Permalink
Merge pull request #48 from brhahlen/dev
Browse files Browse the repository at this point in the history
Version 1.6.0
  • Loading branch information
brhahlen authored Jun 15, 2022
2 parents 6a95a59 + a0542fa commit 76bd0ea
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 46 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 12 additions & 2 deletions build-files/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
- Fixed getting containers in stacks, due to #46
111 changes: 68 additions & 43 deletions dc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -55,15 +55,25 @@ 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
if [ "${VERBOSE}" = true ]; then
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
5 changes: 4 additions & 1 deletion dc-completion
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down

0 comments on commit 76bd0ea

Please sign in to comment.