-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Grigory Efimov
committed
Nov 1, 2018
1 parent
1c7d76f
commit a0ded3d
Showing
2 changed files
with
70 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |