forked from aignas/LaTeX-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makezip.sh
executable file
·160 lines (144 loc) · 4.75 KB
/
makezip.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
151
152
153
154
155
156
157
158
159
#!/bin/bash
# ===============================================================================
# Environmental variables
#
TMP_FNAME="template_preamble.tex"
UP_FOLNAME="upload-dir"
# ===============================================================================
function del_logs {
echo "Deleting unnecessary files"
rm `find $1 | egrep '\.(log|aux|out|toc|tdo|bbl|blg|nav|snm)'`
}
# ===============================================================================
# Preparing publishing templates for zipping.
#
function prep_pub {
cd $1 || return 1
if [ `echo $1 | grep -q pub` ]; then
echo "Deleting unnecessary files and folders"
rm -r `ls -1 | egrep -v 'template'`
cp -a template/* ./
rm -r template
fi
cd ..
del_logs $1
}
# ===============================================================================
# ===============================================================================
# Preparing tutorials for ziping
#
function prep_tutorials {
cp template_preamble.tex ${1}
texname=${1:3}
sed -i "s/input{.\/\.\.\/${TMP_FNAME}}/input{\.\/${TMP_FNAME}}/" ${1}/${texname}.tex
del_logs $1
}
# ===============================================================================
# ===============================================================================
# Preparing the common templates for zipping.
#
function prep_templates {
del_logs $1
}
# ===============================================================================
# ===============================================================================
# Preparing the lecture material for zipping
#
function prep_templates {
del_logs $1
}
# ===============================================================================
# ===============================================================================
# Function for moving the newly created zip files to a common directory
#
function zip_move {
if [ ! -d ${UP_FOLNAME} ]; then
mkdir ${UP_FOLNAME} || return 1
fi
if [ ! -d ${UP_FOLNAME}/${1} ]; then
mkdir ${UP_FOLNAME}/${1} || return 1
fi
cd $1 || return 1
for file in *.zip; do
echo "Moving ${file} to the archive"
mv ${file} ../${UP_FOLNAME}/${1}/${file}
done;
cd ..
return 0
}
# ===============================================================================
# ===============================================================================
# Function for creating zip files
#
function zip_folders {
WORKING_DIR=$1
cd ${WORKING_DIR} || return 1
for dir in *; do
if [ ! -d ${dir} ]; then
continue
fi
echo "Making a backup dir for ${dir}"
cp -a ${dir} ${dir}-backup || return 1
if [[ "$1"=="tutorials" ]]; then
prep_tutorials ${dir}
elif [[ "$1"=="publishing" ]]; then
prep_pub ${dir}
elif [[ "$1"=="templates" ]]; then
prep_templates ${dir}
elif [[ "$1"=="lecture_material" ]]; then
prep_templates ${dir}
fi
echo "Generating ${dir}.zip"
zip -q -r ${dir} ${dir}
rm -r ${dir}
mv ${dir}-backup ${dir}
done
cd ..
zip_move ${WORKING_DIR}
return 0
}
# ===============================================================================
# ===============================================================================
# Function for uploading all scripts and then removing them
#
function upload_zips {
touch sftp_batch
for object in ${UP_FOLNAME}/*; do
echo "put -r ${object}" >> sftp_batch
done
echo "quit" >> sftp_batch
echo "Uploading everything by sftp to my pwf webspace"
sftp -o "batchmode no" -b sftp_batch [email protected]:public_html/ChemDptLaTeX/
rm sftp_batch
rm -r ${UP_FOLNAME}/*
return 0
}
# ===============================================================================
# ===============================================================================
# Execution of the script and various options
#
case $1 in
--zip|-z)
zip_folders tutorials
zip_folders templates
zip_folders publishing
zip_folders lecture_material
;;
--clean|-c)
clean_zips
;;
--upload|-u)
upload_zips
;;
--help|-h|help|h)
echo "Options for this script:"
echo " --zip | -z to compress all folders in this directory."
echo " --upload| -u to upload all compressed files to a pwf webspace."
echo " --clean | -c to delete all the .zip files in this directory."
echo " --help | -h to produce this help message."
;;
*)
echo "Please select the options"
;;
esac
# ===============================================================================