Skip to content

Commit

Permalink
update bin/deployHome.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
Grigory Efimov committed Nov 1, 2018
1 parent 1c7d76f commit a0ded3d
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 44 deletions.
33 changes: 1 addition & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
81 changes: 69 additions & 12 deletions bin/deployHome.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
usage: $0 [version]
example:
$0 $DEFAULT_VERSION
script for deploy home environment
usage: $0 [internal|external]
EOF
exit 1
}

# vars
URL_VERSIONS="http://v.i/g.efimov/home/version.txt"
URL_RELEASES="https://api.github.com/repos/fb929/home/releases/latest"
URL_TAR_PREFIX_INT="http://v.i/g.efimov/home/v"
URL_TAR_PREFIX_EXT="https://github.com/fb929/home/archive/v"

# check user
if [[ $USER == root ]];then
echo "ERROR: USER = root" 1>&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

0 comments on commit a0ded3d

Please sign in to comment.