diff --git a/README.md b/README.md index 2dd0ba2..047cc0a 100644 --- a/README.md +++ b/README.md @@ -1,36 +1,5 @@ # home deploy: ``` -URL="https://api.github.com/repos/fb929/home/releases/latest" -CURL_OPTIONS="--fail --connect-timeout 1 --max-time 1" -CURL="curl $CURL_OPTIONS" -VERSION=$( $CURL --silent $URL | grep -Po '"tag_name": "\K.*?(?=")' | sed 's|^v||' ) -if ! echo "$VERSION" | grep -qP "^[0-9\.]+$"; then - echo "ERROR: failed get version from $URL" - exit 1 -fi -if [[ -s $HOME/.home_version ]]; then - CURRENT_VERSION=$(cat $HOME/.home_version ) - if [[ $VERSION == $CURRENT_VERSION ]]; then - # home in actual - exit 0 - fi -fi - -install -d $HOME/tmp/ && -if [[ -d $HOME/tmp/home-$VERSION ]]; then - rm -rf $HOME/tmp/home-$VERSION -fi -wget --quiet --output-document=$HOME/tmp/v$VERSION.tar.gz https://github.com/fb929/home/archive/v$VERSION.tar.gz && -tar --gzip --extract --directory=$HOME/tmp/ --exclude=README.md --file=$HOME/tmp/v$VERSION.tar.gz && -rsync -a $HOME/tmp/home-$VERSION/ $HOME/ -sh $HOME/bin/fixPerm.sh -sh $HOME/bin/fixHtopCfg.sh && - -# fix owner -tar --list --file=$HOME/tmp/v$VERSION.tar.gz | sed "s|home-$VERSION/|$HOME/|" | grep -v README.md | xargs chown $USER:$USER && - -echo $VERSION > $HOME/.home_version +curl https://raw.githubusercontent.com/fb929/home/master/bin/deployHome.sh | bash ``` - -or run bin/deployHome.sh diff --git a/bin/deployHome.sh b/bin/deployHome.sh index 8cffddd..5173825 100755 --- a/bin/deployHome.sh +++ b/bin/deployHome.sh @@ -1,26 +1,83 @@ #!/bin/bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin -DEFAULT_VERSION=$( cat $HOME/.home_version ) -VERSION=${1:-$DEFAULT_VERSION} - -if ! echo "$VERSION" | grep -qP "^[0-9\.]+$"; then +# usage +do_usage(){ cat <&2 + exit 1 fi +# check curl :\ +CURL_OPTIONS="--fail --connect-timeout 1 --max-time 1" +if which .curl &>/dev/null; then + CURL=".curl $CURL_OPTIONS" +elif which curl &>/dev/null; then + CURL="curl $CURL_OPTIONS" +else + echo "ERROR: programm curl not found" + exit 1 +fi + +# check zones +ZONE=${1:-internal} # network zones +case $ZONE in + int|internal) + VERSION=$( $CURL --silent $URL_VERSIONS ) + URL_TAR_PREFIX=$URL_TAR_PREFIX_INT + ;; + ext|external) + VERSION=$( $CURL --silent $URL_RELEASES | grep -Po '"tag_name": "\K.*?(?=")' | sed 's|^v||' ) + URL_TAR_PREFIX=$URL_TAR_PREFIX_EXT + ;; + *) do_usage +esac + +# check version +if ! echo "$VERSION" | grep -qP "^[0-9\.]+$"; then + echo "ERROR: failed version ($VERSION)" + exit 1 +fi +if [[ -s $HOME/.home_version ]]; then + CURRENT_VERSION=$(cat $HOME/.home_version ) + if [[ $VERSION == $CURRENT_VERSION ]]; then + # home in actual + exit 0 + fi +fi +URL_TAR="${URL_TAR_PREFIX}${VERSION}.tar.gz" + +# get and extract home tar install -d $HOME/tmp/ && if [[ -d $HOME/tmp/home-$VERSION ]]; then rm -rf $HOME/tmp/home-$VERSION fi -wget --quiet --output-document=$HOME/tmp/v$VERSION.tar.gz https://github.com/fb929/home/archive/v$VERSION.tar.gz && +wget --quiet --output-document=$HOME/tmp/v$VERSION.tar.gz $URL_TAR && tar --gzip --extract --directory=$HOME/tmp/ --exclude=README.md --file=$HOME/tmp/v$VERSION.tar.gz && -rsync -a $HOME/tmp/home-$VERSION/ $HOME/ -sh $HOME/bin/fixPerm.sh -chown -R $USER:$USER $HOME -echo $VERSION > $HOME/.home_version +rsync -a $HOME/tmp/home-$VERSION/ $HOME/ && +sh $HOME/bin/fixPerm.sh && +sh $HOME/bin/fixHtopCfg.sh && +# fix owner +tar --list --file=$HOME/tmp/v$VERSION.tar.gz | sed "s|home-$VERSION/|$HOME/|" | grep -v README.md | xargs chown $USER:$USER && +# set home version +echo $VERSION > $HOME/.home_version +chown $USER:$USER $HOME/.home_version 2>/dev/null