-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaplot
executable file
·170 lines (143 loc) · 4.98 KB
/
aplot
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#Takes all .pdf's from pdf_dir and converts them to .png's at png_dir
pdf_to_png(){
# $1=pdf_dir, $2=png_dir
echo -n "Working: ["
for file in ${1}/*.pdf ; do
pdf_name=${file##*/}
convert -density 50 -trim -fuzz 1% $file ${2}/${pdf_name%.pdf}.png
echo -n "#"
done
echo -n "]"
echo " "
}
setup(){
# $1 : public_html directory, ${2} : target directory
if [[ -e ${1} ]] ; then
aplot=${1}/autoplotter
if [[ -e ${aplot}/${2} ]] ; then
echo "Updating ${2} in AutoPlotter"
else
echo "Adding ${2} to AutoPlotter..."
mkdir ${aplot}/${2}
mkdir ${aplot}/${2}/pdfs
mkdir ${aplot}/${2}/pngs
mkdir ${aplot}/${2}/txts
curl https://raw.githubusercontent.com/jkguiang/AutoPlotter/master/index.php > ${aplot}/${2}/index.php
curl https://raw.githubusercontent.com/jkguiang/AutoPlotter/master/favicon.ico > ${aplot}/${2}/favicon.ico
echo "Added ${2}."
fi
else
echo "Public html directory not found, please log in to your UAF account to complete set up."
exit 0
fi
}
updt(){
# $1 : target directory, $2 : origin directory
if [[ -e ${1} ]] ; then
if [[ -e ${1}/pdfs ]] ; then
rm -rf ${1}/pdfs/* ${1}/pngs/* ${1}/txts/*
found=false
echo "Looking for pdfs..."
if [[ -n "$(ls ${2}/*.pdf 2>/dev/null)" ]] ; then
found=true
for file in ${2}/*.pdf ; do
cp ${file} ${1}/pdfs
done
pdf_to_png ${1}/pdfs ${1}/pngs
fi
echo "Looking for pngs..."
if [[ -n "$(ls ${2}/*.png 2>/dev/null)" ]] ; then
found=true
for file in ${2}/*.png ; do
cp ${file} ${1}/pngs
done
fi
echo "Looking for txts..."
if [[ -n "$(ls ${2}/*.txt 2>/dev/null)" ]] ; then
for file in ${2}/*.txt ; do
cp ${file} ${1}/txts
done
fi
if [[ "$found" = true ]] ; then
chmod -R 755 ${1}/pdfs
chmod -R 755 ${1}/pngs
chmod -R 755 ${1}/txts
chmod -R 755 ${1}
else
echo "Error: no .pdf or .png files found"
rm -rf ${1}
exit 0
fi
fi
else
echo "Error: ${1} not found."
exit 0
fi
}
html=/home/users/${USER}/public_html
if [[ -e ${1} ]] ; then
if [[ -d ${1} ]] ; then
to_orig=$(cd "$(dirname "$1")"; pwd -P)
targ=$(basename ${1})
orig=${to_orig}/${targ}
if [[ -e ${1}/.aplot ]] ; then
while true; do
echo "Overwrite ${targ}? (y/n): "
read resp
if [[ "${resp}" == "n" ]] ; then
echo "Please enter a new target directory name, then hit ENTER: "
read new_name
targ=${new_name}
break
elif [[ "${resp}" == "y" ]] ; then
targ=$(cat ${1}/.aplot)
break
fi
done
fi
if [[ ${2} ]] ; then
touch ${1}/.aplot
echo ${2} > ${1}/.aplot
targ=${2}
fi
if [[ ! -e ${html}/autoplotter ]] ; then
mkdir ${html}/autoplotter
curl https://raw.githubusercontent.com/jkguiang/AutoPlotter/master/main.php > ${html}/autoplotter/index.php
curl https://raw.githubusercontent.com/jkguiang/AutoPlotter/master/main.js > ${html}/autoplotter/main.js
curl https://raw.githubusercontent.com/jkguiang/AutoPlotter/master/favicon.ico > ${html}/autoplotter/favicon.ico
curl https://home.cern/sites/home.web.cern.ch/files/image/update-for_the_public/2015/01/cms.jpg > ${html}/autoplotter/cms.jpg
fi
setup ${html} ${targ}
updt ${html}/autoplotter/${targ} ${orig}
chmod -R 755 ${html}/autoplotter/
echo "Finished. Navigate to the link below to view plots:"
echo "uaf-8.t2.ucsd.edu/~${USER}/autoplotter/${targ}"
exit 0
else
echo "${1} is not a directory."
exit 0
fi
else
if [[ "${1}" == "rm" ]] ; then
if [[ "${2}" != "" ]] ; then
if [[ ! -e ${html}/autoplotter/${2} ]] ; then
echo "No entry named ${2} exists in ${html}/autoplotter."
exit 0
else
rm -rf ${html}/autoplotter/${2}
echo "Removed ${2}."
exit 0
fi
else
echo "Usage: aplot rm <target_directory>"
exit 0
fi
else
if [[ ${1} ]] ; then
echo "Error: ${1} does not exit."
else
echo "Default Usage: aplot <origin_directory> <optional_target>"
fi
exit 0
fi
fi