From 0fe4048ab3a33291be1fea2fb7b1453c5ffa09c0 Mon Sep 17 00:00:00 2001 From: pvincent Date: Fri, 16 Apr 2021 13:18:59 +0400 Subject: [PATCH] debian_bash_upgrade --- .vscode/extensions.json | 5 +++++ install.sh | 3 ++- tools/debian_bash_upgrade | 28 ++++++++++++++++++++++- tools/wget_release | 6 ++--- tools/wget_semver | 47 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 .vscode/extensions.json create mode 100755 tools/wget_semver diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..8a3f144 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "mads-hartmann.bash-ide-vscode", + ] +} diff --git a/install.sh b/install.sh index 22c9f5a..7609ea3 100755 --- a/install.sh +++ b/install.sh @@ -2,6 +2,7 @@ BASEDIR=$PWD +TAG=$(cat /opt/debian-bash/.semver_git_tag) function usage { echo 'usage: --host | --containers | --full | --one-container ' @@ -66,7 +67,7 @@ function install_containers { # install inside active LXC containers if [[ -f '/snap/bin/lxc' ]]; then - for container in `/snap/bin/lxc list -c n --format csv`; do + for container in `lxc list --format=json | jq -r '.[] | select(.state.status == "Running") | .name'`; do install_one_container $container echo done diff --git a/tools/debian_bash_upgrade b/tools/debian_bash_upgrade index 19716fe..a74fe81 100755 --- a/tools/debian_bash_upgrade +++ b/tools/debian_bash_upgrade @@ -1,3 +1,29 @@ #!/bin/bash -curl https://git.artcode.re/pvincent/debian-bash/raw/master/install.sh | sudo bash -s -- --full \ No newline at end of file +if [[ -d /opt/debian-bash ]]; then + local_release=$(cat /opt/debian-bash/.semver_git_tag) +fi +remote_release=$(wget_semver artcode pvincent/debian-bash) + +if [[ $local_release != $remote_release ]];then + echo "upgrading from <$local_release> to <$remote_release> ..." + curl https://git.artcode.re/pvincent/debian-bash/raw/master/install.sh | sudo bash -s -- --full +else + + echo "debian-bash version $local_release already up-to-date!" + # install inside active LXC containers + if [[ -f '/snap/bin/lxc' ]]; then + echo "refreshing containers ..." + for container in `lxc list --format=json | jq -r '.[] | select(.state.status == "Running") | .name'`; do + container_release=$(lxc exec $container -- cat /opt/debian-bash/.semver_git_tag) + if [[ $container_release != $remote_release ]];then + echo "upgrade container <$container> from <$container_release> to <$remote_release>" + /snap/bin/lxc file push /opt/debian-bash "${container}/opt/" -r + /snap/bin/lxc exec "$container" -- sh -c "cd /opt/debian-bash && ./install.sh --host" + else + echo "debian-bash version on container <$container> already up-to-date!" + fi + done + fi + +fi \ No newline at end of file diff --git a/tools/wget_release b/tools/wget_release index 9a932aa..2fe1d8c 100755 --- a/tools/wget_release +++ b/tools/wget_release @@ -18,9 +18,9 @@ function usage { exit -1 } -function get-github { +function get_github { local BASE="https://github.com" - local release=$(curl -s $BASE/${REPO_NAME}/releases/latest | grep -oe "releases/tag/.*\"" | cut -d '/' -f3 | cut -d '"' -f1 ) + local release=$( wget_semver $REPO_TYPE $REPO_NAME ) local url="$BASE/${REPO_NAME}/archive/refs/tags/${release}.tar.gz" if [[ -d $DESTINATION ]]; then DESTINATION="$DESTINATION/$(echo $REPO_NAME | cut -d '/' -f2 )-${release}.tgz" @@ -33,7 +33,7 @@ function get-github { case $REPO_TYPE in github ) - get-github + get_github ;; * ) echo "repository type <${REPO_TYPE}> not yet supported!" && exit 1 diff --git a/tools/wget_semver b/tools/wget_semver new file mode 100755 index 0000000..41d1a31 --- /dev/null +++ b/tools/wget_semver @@ -0,0 +1,47 @@ +#!/bin/bash + +REPO_TYPE=$1 +REPO_NAME=$2 + +function usage { + local BASECMD=$(basename "$0") + echo 'usage: [DESTINATION]' + echo 'example:' + echo -e '\t# REPO_TYPE=github' + echo -e "\t$BASECMD github Dolibarr/dolibarr\n" + echo -e '\t# REPO_TYPE=artcode' + echo -e "\t$BASECMD artcode pvincent/debian-gnome\n" + exit -1 +} + +function get_github { + release=$( git ls-remote --tags --sort="v:refname" \ + git://github.com/$REPO_NAME \ + | tail -n1 | cut -f2 | cut -d '/' -f3 ) + release=${release%^\{\}} # remove extra characters ^{} from github + echo $release +} + +function get_artcode { + release=$( git ls-remote --tags --sort="v:refname" \ + https://git.artcode.re/$REPO_NAME \ + | tail -n1 | cut -f2 | cut -d '/' -f3 ) + echo $release +} + + +[[ $# -ne 2 ]] && usage + +case $REPO_TYPE in + github ) + get_github + ;; + artcode ) + get_artcode + ;; + * ) + echo "repository type <${REPO_TYPE}> not yet supported!" && exit 1 + ;; +esac + +