-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprj-helper
More file actions
executable file
·140 lines (119 loc) · 3.47 KB
/
prj-helper
File metadata and controls
executable file
·140 lines (119 loc) · 3.47 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
#!/bin/bash
# Deprecated, moved to separage scripts
##usage
case $1 in
vi ) vi $0; exit 1;;
esac
if test "$1" == "script"
then
echo '#Script used to call prj-helper
export user host # Use for remote locations
export project # Defaults to current directory (local)
export projects # Defaults /home/$user/projects
export subversion # Defaults /home/$user/subversion
case $1 in
remote ) user=myuser; host=myhost ;;
local ) host=localhost;; # Commands work locally too
help ) prj-helper help; exit 1;;
vi ) vi $0; exit 1;; # Edit this file
* ) cat $0; exit 1;; # Display this file
esac
shift 1
prj-helper $*
'
exit 1
fi
function prj_help {
echo "
Usage: $0 [command]
No command will ssh to the host. Any unrecognized command
becomes a remote execution command.
Command: get or put #Preview then rsync project.
scpfrom (file) | scpto (file) #SCP individual files.
co [trunk] or ci #New Subversion project checkout or checkin
lnk #Append local DSA key to remote authorized_keys. Used for
#SSH authentication.
env #Source functions in this environment
"
}
_pwd=`pwd`
export user_host=$user${user:+@}$host
export project=${project:-`basename "$_pwd"`}
export projects=${projects:-/home/$user/projects}
export subversion=${subversion:-/home/$user/subversion}
export rsync_path=${rsync_path:-$projects/$project}
export svn_path=${svn_path:-$subversion/$project}
function ssh_lnk {
[ ! -f $HOME/.ssh/id_dsa.pub ] && ssh-keygen -t dsa
[ -f $HOME/.ssh/id_dsa.pub ] && \
ssh $user_host mkdir .ssh\; echo "`cat $HOME/.ssh/id_dsa.pub` >> .ssh/authorized_keys" && \
echo SSH Link established...
}
function rsync_test_and_run {
tmp=`mktemp /tmp/rsync.XXXXXXXX`
trap 'rm $tmp' EXIT
rsync_cmd=$1
echo rsync $rsync_cmd --dry-run | tee $tmp
sh $tmp
read -p "Proceed (y/n)? " yn
case $yn in
[Yy] )
echo rsync $rsync_cmd > $tmp
sh $tmp
;;
[Nn] ) return 1;;
* ) echo "Please answer y or n.";;
esac
}
function rsync_filters {
test -f rsync_includes && rsync_parms="--include-from=rsync_includes"
test -f rsync_excludes && rsync_parms="$rsync_parms --exclude-from=rsync_excludes"
test -f rsync_filters && rsync_parms="$rsync_parms --filter='merge rsync_filters'"
}
function rsync_put {
echo UPLOAD Test Run...
${host:+ssh $user_host} mkdir -vp "$rsync_path"
rsync_filters
rsync_test_and_run "$rsync_parms --delete --compress -e ssh -va '${1:-.}' '$user_host${user_host:+:}$rsync_path/$1'"
}
function rsync_get {
echo DOWNLOAD Test Run...
rsync_filters
rsync_test_and_run "$rsync_parms --delete --compress -e ssh -va '$user_host${user_host:+:}$rsync_path/${1:-.}' '${1:-.}'"
}
function svn_uri {
if [ "$user_host" == "" ] && test -e "$svn_path"
then
svn_uri=file:$svn_path
else
svn_uri=svn+ssh://$user_host$svn_path
fi
}
function svn_co {
svn_uri
svn co $svn_uri/$* .
}
function svn_ci {
if [ "$user_host" == "" ]
then
svnadmin create $svn_path
svn import file:$svn_path
else
ssh $user_host svnadmin create $svn_path
svn_uri
svn import $svn_uri
fi
}
command=$1
case $command in
help ) prj_help ;;
env ) ;; # user is after environment only
lnk ) ssh_lnk ;;
get ) shift 1; rsync_get $1 ;;
put ) shift 1; rsync_put $1 ;;
co ) shift 1; svn_co $*;;
ci ) svn_ci ;;
scpto ) shift 1; scp -rp "$1" $user@$host:"${2-.}" ;;
scpfrom ) shift 1; scp -rp $user@$host:"$1" "${2-.}" ;;
* ) ssh $user_host $* ;;
esac