-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.sh
150 lines (105 loc) · 3.22 KB
/
common.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
declare centraldir=~/ai/;
declare centralconfigsdir=${centraldir}configs/;
declare centrallogsdir=${centraldir}logs/;
declare centralmodelsdir=${centraldir}models/;
declare centraloutputsdir=${centraldir}outputs/;
declare centraltrainingdir=${centraldir}training-data/;
declare elevate="";
declare rootdir=~/devel/github/;
if ! [ $(id --user) == 0 ]; then
echo "Script may require root priviledge.";
elevate="sudo";
fi
function _linkdir() {
declare usagelink;
declare commonsubdir=${1};
declare usagepath=${2};
usagelink=${usagepath%/};
if [ ! -L "${usagelink}" ]; then
mkdir --parents --verbose "${commonsubdir}";
mkdir --parents --verbose "${usagepath}";
rsync --archive --hard-links --ignore-existing --update --verbose "${usagepath}/" "${commonsubdir}";
mv --verbose "${usagelink}"{,.orig};
ln --force --symbolic "${commonsubdir}" "${usagelink}";
fi
}
function aptinstall() {
declare grepstr;
declare installedcnt;
declare packagecnt=${#};
declare packagelist="${@}";
grepstr="^($(echo ${packagelist} | tr " " "|"))/";
installedcnt=$(apt list --installed |
grep --extended-regexp "${grepstr}" |
wc --lines) || :
if [ ${installedcnt} -ne ${packagecnt} ]; then
"${elevate}" apt-get update;
"${elevate}" apt-get install ${packagelist} --yes;
fi
}
function downloadpkg() {
declare grepstr;
declare url="$1";
declare package=${url##*/};
declare packagename=$(echo $package | cut --delimiter "_" --fields 1);
grepstr="^($(echo ${packagename} | tr " " "|"))/";
installedcnt=$(apt list --installed |
grep --extended-regexp "${grepstr}" |
wc --lines) || :
if [ ${installedcnt} -lt 1 ]; then
wget --verbose ${url};
fi
}
function dpkginstall() {
declare grepstr;
declare package="$1";
declare packagename=$(echo $package | cut --delimiter "_" --fields 1);
grepstr="^($(echo ${packagename} | tr " " "|"))/";
installedcnt=$(apt list --installed |
grep --extended-regexp "${grepstr}" |
wc --lines) || :
if [ ${installedcnt} -lt 1 ]; then
"${elevate}" dpkg --install ${package};
fi
}
function linkcentraldir() {
declare usagelink;
declare commonsubdir=${1};
declare usagepath=${2};
_linkdir "${centraldir}/${commonsubdir}" "${usagepath}";
}
function linkconfigsdir() {
declare usagelink;
declare commonsubdir=${1};
declare usagepath=${2};
_linkdir "${centralconfigsdir}/${commonsubdir}" "${usagepath}";
}
function linklogsdir() {
declare usagelink;
declare commonsubdir=${1};
declare usagepath=${2};
_linkdir "${centrallogsdir}/${commonsubdir}" "${usagepath}";
}
function linkmodelsdir() {
declare usagelink;
declare commonsubdir=${1};
declare usagepath=${2};
_linkdir "${centralmodelsdir}/${commonsubdir}" "${usagepath}";
}
function linkoutputsdir() {
declare usagelink;
declare commonsubdir=${1};
declare usagepath=${2};
_linkdir "${centraloutputsdir}/${commonsubdir}" "${usagepath}";
}
function mvlinkfile() {
declare file=${1};
declare dir=${2};
touch "${file}";
if [ ! -L "${file}" ]; then
mkdir --parents --verbose "${dir}";
cp --archive --no-clobber --verbose "${file}" "${dir}";
mv --verbose "${file}"{,.orig}
ln --force --symbolic "${dir}/${file}" .;
fi
}