Repository navigation
Expand file tree
/
Copy pathInstall
More file actions
executable file
·83 lines (66 loc) · 1.82 KB
/
Copy pathInstall
File metadata and controls
executable file
·83 lines (66 loc) · 1.82 KB
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
#!/bin/bash
set -e
# Go to the directory where this script is:
cd $(dirname "$(readlink -f "$0")")
if [ "$(id -u)" != 0 ] ; then
echo "You must be root (id = 0) to run this"
exit 1
fi
if [ ! -f config.bash ] ; then
# Get the configuation
echo "config.bash was not found."
echo
cp default_config.bash config.bash
source config.bash
chown $INST_USER:$INST_USER config.bash
echo "Copied default_config.bash to config.bash"
else
# Get the configuration
source config.bash
fi
stages="$(ls -1 stage*.root.bash stage*.user.bash | sort)"
# Usage: fail_stage STAGE_FILE
#
function fail_stage() {
date > $1.FAILED
chown $INST_USER:$INST_USER $1.FAILED
set +x
echo "$1 FAILED"
exit 1
}
# Usage: mark_stage_done STAGE USER
#
function mark_stage_done() {
[ -n "$2" ] || exit 1 # script error
date > $1.done
chown $INST_USER:$INST_USER $1.done
echo -e "\nRunning $1 as $2 SUCCEEDED\n"
}
set +e
set +x
mark='\n---------------------------------------------------------------\n'
export BASH_ENV=config.bash
for stage in $stages ; do
if [ ! -f $stage.done ] ; then
echo -en "${mark}Running: $stage"
if [[ "$stage" == stage*.root.bash ]]; then
# Running stage as root
echo -e " as root${mark}"
if bash $stage ; then
mark_stage_done $stage root
else
fail_stage $stage
fi
else
# Running stage as regular user
echo -e " as user $INST_USER${mark}"
if sudo -u $INST_USER --preserve-env bash $stage ; then
mark_stage_done $stage $INST_USER
else
fail_stage $stage
fi
fi
else
echo -e "\n--- stage $stage is marked as done, skipping it this time\n"
fi
done