]> git.somenet.org - root/pub/somesible.git/blob - update_somesible.sh
roles/base/munin-node/files
[root/pub/somesible.git] / update_somesible.sh
1 #!/bin/sh
2 #
3 ##############################
4 ## somenet.org ansible tool ##
5 ##############################
6 # Part of: https://git.somenet.org/root/pub/somesible.git
7 # 2017-2024 by someone <someone@somenet.org>
8 #
9 # update git repository
10 #
11 # This is always run inside the somesible repo only.
12 #
13
14 # .git may be a file, if checked out as submodule.
15 if [ ! -e ".git" ]; then
16   echo "*** ERROR (update_somesible.sh): this is not a git repo. abort."
17   exit 1
18 fi
19
20 SOMESIBLE_GIT_REV_START="$(git --git-dir ./.git --no-pager log --pretty=format:'%h' -n 1 HEAD --)"
21
22 echo "***"
23 echo "*** DEBUG (update.sh) start: [${SOMESIBLE_GIT_REV_START}] $(date -Isec)"
24 echo "***"
25
26 # (try to) read config in parent dir.
27 if [ -e "../somesible.conf" ]; then
28     . "../somesible.conf"
29 fi
30 if [ -z "$SOMESIBLE_VERSION" ]; then
31     SOMESIBLE_VERSION="tags/activeVersion"
32 else
33     echo "***********************************************************"
34     echo "*** WARNING (update_somesible.sh): using non-default version: ${SOMESIBLE_VERSION} ***"
35     echo "***********************************************************"
36     echo "***"
37 fi
38
39
40 ################################
41 # update self (somesible repo) #
42 ################################
43 chmod -R u=rwX,go-rwx "./"
44 chmod u+x *.sh
45
46 git config protocol.ext.allow always
47 git config remote.origin.url "ext::ssh -F ./.ssh/config git.somenet.org %S /root/pub/somesible"
48 git config remote.update.url 'git@git.somenet.org:/root/pub/somesible'
49 git config fetch.prune true
50
51 git ls-remote --exit-code -t origin > /dev/null 2>&1
52 USERCONFIG_OFFLINE=$?
53 if [ $USERCONFIG_OFFLINE -ne 0 ]; then
54     echo "****************************************************************************"
55     echo "*** INFO (update.sh): git repo unreachable. Offline? - Retry in 120 sec. ***"
56     echo "****************************************************************************"
57     echo "***"
58     sleep 120
59     git ls-remote --exit-code -t origin > /dev/null 2>&1
60     USERCONFIG_OFFLINE=$?
61 fi
62
63 if [ $USERCONFIG_OFFLINE -ne 0 ]; then
64     echo "***************************************************************************"
65     echo "*** WARNING (update.sh): git repo unreachable. Offline? - Retry failed. ***"
66     echo "***************************************************************************"
67     echo "***"
68 else
69     git tag | xargs -n1 git tag -d
70     git fetch origin --tags
71 fi
72 unset USERCONFIG_OFFLINE
73
74 git checkout -f "master"
75 git reset --hard "$SOMESIBLE_VERSION" --
76 if [ $? -ne 0 ]; then
77     echo "******************************************************************"
78     echo "*** WARNING (update_somesible.sh): invalid SOMESIBLE_VERSION? ***"
79     echo "******************************************************************"
80     echo "***"
81     git reset --hard "tags/activeVersion" --
82 fi
83
84 # one --force is not enought!
85 git clean -ffdx
86 git gc --prune=all
87
88 # Do this twice to be sure.
89 chmod -R u=rwX,go-rwx "./"
90 chmod u+x *.sh
91
92
93 echo "***"
94 echo "*** DONE (update_somesible.sh) [${SOMESIBLE_GIT_REV_START}] -> [$(git --git-dir ./.git --no-pager log --pretty=format:'%h' -n 1 HEAD --)] $(date -Isec)"
95 echo "***"
96
97 ###########
98 # cleanup #
99 ###########
100 unset SOMESIBLE_VERSION
101 unset SOMESIBLE_GIT_REV_START