This repository has been archived by the owner on Apr 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions-cvs
executable file
·165 lines (141 loc) · 4.04 KB
/
functions-cvs
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
#!/bin/bash
# Set of CVS-related functions
function cvs {
xcrun cvs "$@"
}
function cvscommit {
[[ $@ ]] && cvs -q commit -m$@ || cvs -q commit -m"" .
}
function cvsadd {
[[ $@ ]] && cvs add $@ || cvs add index.html
}
function copycourse(){
if [ $# -eq 0 ]; then
echo "Error: This function takes 3 inputs:"
echo " 1: original course number"
echo " 2: new course number"
echo " 3: title of new course"
echo "> copycourse cl220 cl221 Red Hat Hybrid Cloud Administration"
else
# collect variable data
orig=$(echo $1 | tr '[:upper:]' '[:lower:]')
new=$(echo $2 | tr '[:upper:]' '[:lower:]')
title=""
count=3
while [ $count -le $# ]; do
title+="${!count} "
let count++
done
# move to correct directory
cd ~/html/courses
# copy old file but delete CVS directory
cp -R "$orig" "$new" && echo "Copy $orig to $new"
rm -rf "${new}/CVS" && rm -rf "${new}/enroll/CVS" && echo "Remove CVS directories"
# add new content to cvs
cvs add $new && echo "Add $new"
#--specific to courses
cvs add ${new}/enroll && echo "Add $new/enroll"
#--specific to courses
file="${new}/enroll/index.html"
tmp="${new}/enroll/tmp"
# update content for the new course
sed "s/${orig}/${new}/g" "$file" > "$tmp" && mv "$tmp" "$file" && echo "Update text in file"
orig_up=$(echo $orig | tr '[:lower:]' '[:upper:]')
new_up=$(echo $new | tr '[:lower:]' '[:upper:]')
#--specific to courses
sed "s/${orig_up}/${new_up}/g" "$file" > "$tmp" && mv "$tmp" "$file"
sed "s/<h1>.*<\/h1>/<h1>${title}(${new_up})<\/h1>/g" "$file" > "$tmp" && mv "$tmp" "$file"
# add new content to cvs
cvs add $file && echo "CVS add new files"
fi
}
function cvstag {
files=()
opt2="-R"
while [[ $# > 0 ]]; do
key="$1"
case $key in
-q)
q="-Q"
shift # move to next argument
;;
-d)
opt2="${rm}d"
shift # move to next argument
;;
-test)
test=true
shift # move to next argument
;;
*)
# if it doesn't match an argument, add to files list
files+=($key)
shift
;;
esac
done
# check that directory was provided
if [ ${#files[@]} -eq 0 ]; then
echo "Error: This function requires at least 1 input."
echo " * File(s) to be tagged"
echo "> cvstag index.html"
echo "Options:"
echo " -q : Quiet mode"
echo " -rm : Remove tag"
else
for file in "${files[@]}"; do
[[ -z $q ]] && opt="-q"
cvs $opt tag $opt2 LIVE $file
cvs $opt tag $opt2 QA $file
cvs $opt tag $opt2 TEST $file
cvs $opt tag $opt2 STAGE $file
done
fi
}
function cvsrm {
files=()
while [[ $# > 0 ]]; do
key="$1"
case $key in
-q)
quiet=true
shift # move to next argument
;;
*)
# if it doesn't match an argument, add to files list
files+=($key)
shift
;;
esac
done
# check that directory was provided
if [ ${#files[@]} -eq 0 ]; then
echo "Error: This function requires at least 1 input."
echo " * Director[y|ies] to be removed."
echo "> cvsrm jb344"
else
# iterate through all files provided as inputs
for file in "${files[@]}"; do
echo ""
# don't prompt in quiet mode
[[ -n $quiet ]] && continue="y" || read -p "Continue with removal of: $file? (y/n): " continue
# untag and delete files from directory, cvs rm + remove directories at end
if [ $(lowcase $continue) == "y" ]; then
[[ -n $quiet ]] && cvstag -q -rm $file || cvsrmtag $file
cmd=$(find $file -type f ! -path "CVS/*" ! -path "*/CVS/*")
if [[ -n $cmd ]]; then
if [[ -z quiet ]]; then
echo "----------------"
find $file -type f ! -path "CVS/*" ! -path "*/CVS/*"
echo "----------------"
fi
[[ -n $quiet ]] && answer="y" || read -p "Continue with delete? (y/n): " answer
[[ $(lowcase $answer) == "y" ]] && find $file -type f ! -path "CVS/*" ! -path "*/CVS/*" -delete
fi
cvs rm $file && cvscommit "Remove outdated document" . && rm -rf $file
fi
done
#[[ -n $quiet ]] && commit="y" || read -p "Commit changes? (y/n): " commit
#[[ $(lowcase $commit) == "y" ]] && cvscommit "Remove files $@" .
fi
}