forked from dvdesolve/l2-multimd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·124 lines (86 loc) · 3.06 KB
/
install.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
123
124
#!/usr/bin/bash
### error codes
E_SCRIPT=255
### script directory
SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
### global functions
source "${SCRIPTDIR}/global.sh" 2> /dev/null || { echo "ERROR: library file global.sh not found! Exiting"; exit ${E_SCRIPT}; }
### perform some checks
check_bash ${L2_PRINT_INT}
# print header
print_header ${L2_PRINT_INT} "Lomonosov-2 batch wrapper installation script v${L2_MMD_VER}" "Written by Viktor Drobot"
echo
echo
# check for the rest of necessary tools
check_exec ${L2_PRINT_INT} "awk"
check_exec ${L2_PRINT_INT} "sed"
check_exec ${L2_PRINT_INT} "md5sum"
### global settings
INSTALLPATH="${HOME}/_scratch/opt/l2-multimd"
FILELIST=$(<distfiles)
### main script starts here
# print installation path and check our distrib for consistency
echo -e "${C_PURPLE}INFO:${C_NC} will install everything into ${C_YELLOW}[${INSTALLPATH}]${C_NC}"
echo -e "${C_PURPLE}INFO:${C_NC} checking integrity of source package..."
for f in ${FILELIST}
do
srcf="${SCRIPTDIR}/${f}"
fhash=$(md5sum "${srcf}" | awk '{print $1}')
fdisthash=$(awk "\$2 == \"${f}\" {print \$1}" disthashes)
if [[ ! -e "${srcf}" ]]
then
echo -e "${C_RED}ERROR:${C_NC} file ${C_YELLOW}[${f}]${C_NC} wasn't found in source tree. Exiting" >&2
exit ${E_INST_NO_FILES}
fi
if [[ "${fhash}" != "${fdisthash}" ]]
then
echo -e "${C_RED}ERROR:${C_NC} checksum of ${C_YELLOW}[${f}]${C_NC} differs from source tree. Exiting" >&2
exit ${E_INST_BAD_HASH}
fi
done
echo -e "${C_GREEN}OK:${C_NC} source tree looks good"
echo
if [[ ! -d "${INSTALLPATH}" ]]
then
echo -e "${C_PURPLE}INFO:${C_NC} doing a fresh install"
else
echo -e "${C_PURPLE}INFO:${C_NC} previous installation was found, will overwrite all destination files"
fi
echo
echo -e -n "Press ${C_RED}<ENTER>${C_NC} to continue or ${C_RED}<Ctrl+C>${C_NC} to exit"
read
# perform installation
mkdir -p "${INSTALLPATH}"
for f in ${FILELIST}
do
srcf="${SCRIPTDIR}/${f}"
echo -n -e "${C_PURPLE}INFO:${C_NC} installing file ${C_YELLOW}[${f}]${C_NC}... "
MODE="644"
if [[ "${f}" == *".sh" ]]
then
MODE="755"
fi
if [[ -e "${INSTALLPATH}/${f}" ]]
then
POSTFIX=' (overwritten)'
else
POSTFIX=''
fi
install -Dm${MODE} "${srcf}" "${INSTALLPATH}/${f}"
if [[ "$?" -eq 0 ]]
then
echo -e "${C_GREEN}ok${POSTFIX}${C_NC}"
else
echo -e "${C_RED}fail${C_NC}"
echo
echo -e "${C_RED}ERROR:${C_NC} something went wrong with installation! Can't write to ${C_YELLOW}[${INSTALLPATH}/${f}]${C_NC} file. Exiting" >&2
exit ${E_INST_ERR_IO}
fi
done
# store info about install root
sed -i "s#L2_ROOT=#L2_ROOT=${INSTALLPATH}#g" "${INSTALLPATH}/global.sh"
echo
echo -e "${C_GREEN}OK:${C_NC} installation completed"
echo -e "${C_PURPLE}INFO:${C_NC} if you want use bash-completion feature and ${C_GREEN}[l2-multimd]${C_NC} alias then source ${C_YELLOW}[${INSTALLPATH}/bash-completion/multimd]${C_NC} file manually or at login via your .bashrc"
# we're done here
exit 0