-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·147 lines (129 loc) · 3.68 KB
/
install.sh
File metadata and controls
executable file
·147 lines (129 loc) · 3.68 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
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
#!/usr/bin/env bash
shopt -s nullglob
cpulook_prefix=${PREFIX-}
if [[ ! $cpulook_prefix ]]; then
if [[ ${XDG_DATA_HOME-} &&${XDG_DATA_HOME%/} == */share ]]; then
cpulook_prefix=${XDG_DATA_HOME%/}
cpulook_prefix=${cpulook_prefix%/share}
else
cpulook_prefix=~/.local
fi
fi
cpudir=$cpulook_prefix/share/cpulook
function print { printf '%s\n' "${1-}"; }
function create-dir {
if [[ ! -d $1 ]]; then
print "cpulook/install: creating directory '$1'"
mkdir -p "$1"
fi
}
function install {
local src=$1
local dst=${2:-$cpudir/$src}
if [[ $src -nt $dst ]]; then
print "cpulook/install: updating '$dst'..."
cp -p "$src" "$dst"
fi
}
function install-script {
local src=$1
local dst=${2:-$cpudir/$src}
if [[ $src -nt $dst ]]; then
print "cpulook/install: updating '$dst'..."
make/cmd.bash install-script "$src" "$dst" "$cpudir"
fi
}
#------------------------------------------------------------------------------
# <cpudir>
function install-files {
# <cpudir>/lib
create-dir "$cpudir/lib"
install lib/echox.bash
install lib/cpudef.bash
install lib/cpujobs.awk
install-script lib/cpugetdata.sh
# <cpudir>/m
create-dir "$cpudir/m"
for f in m/*.bash; do
install "$f"
done
create-dir "$cpudir/m/rsh"
install-script m/rsh/rshexec.sh
install-script m/rsh/rshkill.sh
# <cpudir>/hosts
create-dir "$cpudir/hosts"
install hosts/sh
install hosts/ssh
# <cpudir>/m/switch: create if non-existent
local switch=$cpudir/m/switch
if [[ -d $switch || -L $switch && ! -e $switch ]]; then
# This is the symbolic link for an old implementation of cpulook. If the
# corresponding file is found, we create a new symbolic link. If not, we
# remove the old symbolic link.
local old=$(readlink "$switch")
rm -f "$switch"
[[ -s m/$old.bash ]] && ln -sf "$old.bash" "$switch"
fi
if [[ ! -e $switch ]]; then
if type bsub &>/dev/null; then
ln -fs bsub.bash "$switch"
else
ln -fs rsh.bash "$switch"
fi
fi
# update scripts
install cpulist-default.cfg
install-script cpukill
install-script cpulast
install-script cpulook
install-script cpups
install-script cpuseekd
install-script cpusub
install-script cputop
# create configuration
local config_cpulist=$cpudir/cpulist.cfg
if [[ ! -s $config_cpulist ]]; then
print "cpulook/install: creating default '$config_cpulist'."
cp -f "$cpudir/cpulist-default.cfg" "$config_cpulist"
local nproc=$(
if type nproc &>/dev/null; then
nproc 2>/dev/null
elif [[ -f /proc/cpuinfo ]]; then
grep -c ^processor /proc/cpuinfo
else
print 1
fi)
((nproc=nproc<=0?1:nproc))
print "${HOSTNAME##*.} $nproc $nproc 20 $nproc" >> "$config_cpulist"
print "cpulook/install: [1mplease edit '$config_cpulist'.[m"
fi
}
if [[ ${cpudir%/} != ${PWD%/} ]]; then
install-files
fi
#------------------------------------------------------------------------------
# <cpulook_prefix>/bin
if [[ ! -d $cpulook_prefix/bin ]]; then
create-dir "$cpulook_prefix/bin"
fi
# check PATH
if ! [[ $PATH =~ (^|:)"$cpulook_prefix/bin"/?(:|$) ]]; then
print "cpulook/install: [1mplease add '$cpulook_prefix/bin' to the environment variable PATH.[m"
fi
function install-bin {
local file=$1
local entity=$cpudir/$file
local target=$cpulook_prefix/bin/$file
if [[ ! -e $target ]]; then
print "cpulook/install: creating link '$target' -> '$entity'"
ln -fs "$entity" "$target"
fi
}
install-bin cpulook
install-bin cputop
install-bin cpups
install-bin cpulast
install-bin cpuseekd
install-bin cpusub
install-bin cpukill
#------------------------------------------------------------------------------