-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtemplate.sh
executable file
·79 lines (56 loc) · 1.96 KB
/
template.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
#!/bin/bash
# Installs the ???
### Stage 1 - general setup
echo "# CycleStreets: install ???"
# Ensure this script is run as root
if [ "$(id -u)" != "0" ]; then
echo "# This script must be run as root." 1>&2
exit 1
fi
# Bomb out if something goes wrong
set -e
# Lock directory
lockdir=/var/lock/cyclestreets
mkdir -p $lockdir
# Set a lock file; see: http://stackoverflow.com/questions/7057234/bash-flock-exit-if-cant-acquire-lock/7057385
(
flock -n 9 || { echo '# An installation is already running' ; exit 1; }
### CREDENTIALS ###
# Get the script directory see: http://stackoverflow.com/a/246128/180733
# The multi-line method of geting the script directory is needed to enable the script to be called from elsewhere.
SOURCE="${BASH_SOURCE[0]}"
DIR="$( dirname "$SOURCE" )"
while [ -h "$SOURCE" ]
do
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SCRIPTDIRECTORY=$DIR
# Use this to remove the ../ to get the repository root; assumes the script is always down one level
ScriptHome=$(readlink -f "${SCRIPTDIRECTORY}/..")
# Define the location of the credentials file relative to script directory
configFile=$ScriptHome/.config.sh
# Generate your own credentials file by copying from .config.sh.template
if [ ! -x $configFile ]; then
echo "# The config file, ${configFile}, does not exist or is not executable - copy your own based on the ${configFile}.template file." 1>&2
exit 1
fi
# Load the credentials
. $configFile
# Announce starting
echo "# ??? installation $(date)"
## Main body
# Shortcut for running commands as the cyclestreets user
asCS="sudo -u ${username}"
# Update sources and packages
apt-get update
apt-get upgrade
apt-get dist-upgrade
apt-get autoremove
# Report completion
echo "# Installing ??? completed"
# Remove the lock file - ${0##*/} extracts the script's basename
) 9>$lockdir/${0##*/}
# End of file