-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathlink-set.sh
executable file
·145 lines (130 loc) · 3.23 KB
/
link-set.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
#!/bin/bash
# This script looks for
# sub-directories in notebooks and replicates
# these to any other notebooks directory
# as well as the work directory. This means that if
# you copy trhe notebooks to either
# notebooks/work or notebooks_xx or notebooks_xx/work
# you will have access to the same local directories
#
# P. Lewis [email protected]
# Thu 3 Sep 2020
#
# which dirs
opdirs=$(echo notebooks/work docs docs/work notebooks_lab notebooks_lab/work)
here=$(pwd)
echo "----> running $0 from $here"
echo "--> making links in ${opdirs[*]}"
base="$(cd $(dirname "$0") && cd .. && pwd -P && cd "$here")"
echo "--> location: $base"
repo=$(echo $base | awk -F/ '{print $NF}')
echo "--> repo: $repo"
# HOME may not be set on windows
if [ -z "$HOME" ] ; then
cd ~
HOME=$(pwd)
echo "--> HOME $HOME"
cd "$here"
fi
# link to here from ~ for some scripts
cd $HOME
if [ ! "$HOME/$repo" == "$here" ]
then
echo "--> linking $here $repo"
rm -f "$repo"
ln -s $here "$repo"
fi
cd $here
# put links in all notebooks* directories
echo "--> linking ${subs[*]}"
subs=('bin' 'data' "$repo" 'images')
mkdir -p notebooks/work ${subs[*]}
# outer loop
#for n in ${opdirs[@]}
#do
# cd $base
# echo "--> sorting links in $n"
# mkdir -p "$n"
# cd ${base}/$n
# for link in ${subs[@]}
# do
# echo "--> $link"
# rm -f $link
# # dont link work
# if [ $link != "work" ]; then
# ln -s ../$link $link
# fi
# done
#done
cd "${here}"
echo "--> examining UCLDATA"
if [ -z "$UCLDATA" ] ; then
echo "--> UCLDATA not set"
export UCLDATA="/shared/groups/jrole001/geog0111/work"
fi
echo "--> setting UCLDATA=$UCLDATA"
touch ~/.profile
echo "export UCLDATA=$UCLDATA" > /tmp/tmp.geog0111.$$
grep -v 'UCLDATA=' < ~/.profile >> /tmp/tmp.geog0111.$$
echo "--> testing"
source /tmp/tmp.geog0111.$$
if [ "$?" -eq 0 ]; then
mv /tmp/tmp.geog0111.$$ ~/.profile
echo "--> done testing"
else
echo "---> failure setting active env to ${course_name}"
exit 1
fi
echo "--> done examining UCLDATA"
isUCL=$(uname -n | awk -Frstudio '{print $2}' | wc -w)
echo "--> examining CACHE_FILE"
if [ -z "$CACHE_FILE" ] ; then
echo "--> CACHE_FILE not set"
if [ "$isUCL" == 0 ] ; then
export CACHE_FILE="${HOME}/.url_db/.db.yml"
else
export CACHE_FILE="/shared/groups/jrole001/geog0111/work/database.db"
fi
fi
echo "--> setting CACHE_FILE=$CACHE_FILE"
touch ~/.profile
echo "export CACHE_FILE=$CACHE_FILE" > /tmp/tmp.geog0111.$$
grep -v 'CACHE_FILE=' < ~/.profile >> /tmp/tmp.geog0111.$$
echo "--> testing"
source /tmp/tmp.geog0111.$$
if [ "$?" -eq 0 ]; then
mv /tmp/tmp.geog0111.$$ ~/.profile
echo "--> done testing"
else
echo "---> failure setting active env to ${course_name}"
exit 1
fi
echo "--> done examining CACHE_FILE"
# UCL data link
#cd $base
#echo "--> sorting link to UCL data store"
#rm -f data/ucl
#cd data
#ln -s $UCLDATA ucl
#echo "--> done"
csubs=('docs' 'bin' 'notebooks' 'notebooks_lab')
# outer loop
for n in ${csubs[@]}
do
cd $base/$n
if [ -L bin ] ; then
rm -f bin
fi
echo "linking $n/bin to ../bin"
ln -s ../bin bin
if [ -L copy ] ; then
rm -f copy
fi
echo "linking $n/copy to ../copy"
ln -s ../copy copy
cd $base
done
# dont want this!
rm -f notebooks/bin/bin
rm -f notebooks/copy/copy
echo "----> done running $0 from $here"