-
Notifications
You must be signed in to change notification settings - Fork 1
/
prepare_update-all.sh
123 lines (96 loc) · 2.16 KB
/
prepare_update-all.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash
cd `dirname $0`
. ./common.sh
usage="
Installs update-all repository
The script can be run either as a root or normal user
Usage:
$(basename $0) --user <username> [--help] [--install-dir <install dir>] [--debug] [--log log]
where
--install-dir <install dir> - Place to install the repository
--user <username> - Username to install update to its ~/tmp/update-all. Defaults to the
current user.
--puppet-bootstrap - Clone also puppet-bootstrap
--debug - Flag that sets debugging mode.
--log - Path to the log file that will log all meaningful commands
Example:
$(basename $0)
"
dir_resolve()
{
cd "$1" 2>/dev/null || return $? # cd to desired directory; if fail, quell any error messages but return exit status
echo "`pwd -P`" # output full, link-resolved path
}
mypath=${0%/*}
mypath=`dir_resolve $mypath`
cd $mypath
puppet_bootstrap=0
debug=0
wormhole=0
user=${USER}
while [[ $# > 0 ]]
do
key="$1"
shift
case $key in
--debug)
debug=1
;;
--help)
echo "$usage"
exit 0
;;
--puppet-bootstrap)
puppet_bootstrap=1
;;
--log)
log=$1
shift
;;
--install-dir)
install_dir=$1
shift
;;
--user)
user=$1
shift
;;
-*)
echo "Error: Unknown option: $1" >&2
echo "$usage" >&2
;;
esac
done
if [ "${user}" == "root" ]; then
install_dir="/usr/local/lib"
else
install_dir="$(get_home_dir ${user})/tmp"
fi
if [ -n "$debug" ]; then
if [ -z "$log" ]; then
log=/dev/stdout
fi
fi
logmkdir "${install_dir}" ${user}
if [ ! -w ${install_dir} ] ; then
errcho "${install_dir} is not writable for ${user}"
exit 1
fi
install_apt_package git-core git
if [ -d "${install_dir}/update-all" ]; then
logexec pushd "${install_dir}/update-all"
logexec git pull
else
logexec pushd "${install_dir}"
git clone --depth 1 https://github.com/adamryczkowski/update-all
fi
if [ "${puppet_bootstrap}" == "1" ]; then
if [ -d "${install_dir}/puppet-bootstrap" ]; then
logexec pushd "${install_dir}/puppet-bootstrap"
logexec git pull
else
logexec pushd "${install_dir}"
git clone --depth 1 https://github.com/adamryczkowski/puppet-bootstrap
fi
fi
logexec popd