-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebinithelper
executable file
·86 lines (78 loc) · 2.09 KB
/
debinithelper
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
#1 name[-b] optional 2 is_restore 0 aborting else continuing
name=${1}
root=`pwd`/
swt () {
if [ "`git rev-parse --abbrev-ref HEAD`" != "${1}" ]; then
git switch ${1}
fi
}
parent=
if [ -e "parent" ]; then
parent=`cat parent`
files=( `cat ${parent}` )
fi
proj=`cat debian/changelog | head -1 | grep -o ^[^\ ]*`
if [ -z "${2}" ]; then
cd ~/sync && \
swt ${name} && \
#git switch will ignore deletions and at switch back will put them back
mv debian/patches ${root}debian && \
mv .pc ${root} && \
if [ "${parent}" != "" ]; then
swt ${proj}-${parent} || exit 1
cd .pc || exit 1
for var in "${files[@]}"; do
mv ${var} ${root}.pc || exit 1
#&& break will result in $?=0
done
#done && is useless, same $?=0
cd ../debian/patches || exit 1
for var in "${files[@]}"; do
mv ${var} ${root}debian/patches || exit 1
done
fi
exit $?
fi
#need to sync now, but can't delete parent because need to put it back if local debuild and can't put it back if not commiting sync folder
#the solution is to move parent to tmp and back
a=../tmp/.pc
b=../tmp/debian/patches
if [ "${parent}" != "" ]; then
mkdir ${a} || exit 1
cd .pc || exit 1
for var in "${files[@]}"; do
mv ${var} ../${a} || exit 1
done
cd .. || exit 1
mkdir ../tmp/debian || exit 1
mkdir ${b} || exit 1
cd ./debian/patches || exit 1
for var in "${files[@]}"; do
mv ${var} ../../${b} || exit 1
done
fi
cd ~/sync && \
swt ${name} && \
cd ${root} && \
#
#this is better when no switch and in normal flow
if [ "${2}" != "0" ]; then
rsync -av .pc ~/sync && \
rsync -av debian/patches ~/sync/debian
else
# assuming was restored at switch from parent
{ mv .pc ~/sync || rm -r .pc; } && \
# no space after \ or && is always true
{ mv debian/patches ~/sync/debian || rm -r debian/patches; }
#if files are restored at switch, mv cannot overwrite even with -f
fi && \
#and now, put parent back, needed at local debuild
if [ "${parent}" != "" ]; then
if [ "${2}" != "0" ]; then
mv ${a}/* .pc && \
mv ${b}/* debian/patches
fi && \
rm -r ${a} && \
rm -r ${b} && \
rm -r ../tmp/debian
fi