-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdotbash_gentoo
executable file
·146 lines (132 loc) · 2.9 KB
/
dotbash_gentoo
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
#!/bin/bash
#
# Gentoo Related Bash Functions
#
# These are various tools for manipulating a local
# portage structure (which can be part of an overlay)
#
# These functions allow you to list, clone, delete and diff ebuilds
#
if [ -d /usr/portage ];
then
LOCAL_PORTAGE=$HOME/mysrc/gentoo-overlay.git
MASTER_PORTAGE=/usr/portage
export PORTAGE_TMPDIR=$HOME/src/gentoo/tmp
alias ls_le="find $LOCAL_PORTAGE -mindepth 2 -maxdepth 2 -xtype d -and -not -path \"*/.git*\" | sed s#$LOCAL_PORTAGE##"
alias ls_me="find $MASTER_PORTAGE -mindepth 2 -maxdepth 2 -xtype d | sed s#$MASTER_PORTAGE##"
fi
#
# guess_ebuild
#
# Take a string, possibly partial and match it a proper group/ebuild
#
function guess_ebuild()
{
n=`ls_me | grep $1 | wc -l`
tmp=`ls_me | grep $1`
if [ "$n" == "1" ]; then
group=`echo $tmp | perl -ne 'm#/([^/]*)#; print "$1"'`
ebuild=`echo $tmp | perl -ne 'm#/([^/]*)/(.*)$#; print "$2"'`
echo "guess_ebuild: $group/$ebuild"
else
unset group
unset ebuild
echo "guess_ebuild: not unique enough"
echo $tmp
fi
}
#
# diff ebuild
#
# Do a diff for a given ebuild
#
function diff_ebuild()
{
result=0
if [ "$1" ]
then
guess_ebuild $1
if [[ "$group" && "$ebuild" ]]
then
if [ -d $MASTER_PORTAGE/$group/$ebuild ]; then
diff -r -N -ub -x Manifest $MASTER_PORTAGE/$group/$ebuild $LOCAL_PORTAGE/$group/$ebuild
else
echo "$group/$ebuild not in master portage"
fi
fi
else
for ebuild in `ls_le`
do
if [ -d $MASTER_PORTAGE/$ebuild ]; then
diff -ub $MASTER_PORTAGE/$ebuild $LOCAL_PORTAGE/$ebuild
else
echo "$ebuild not in master portage"
fi
done
fi
}
#
# Clone an ebuild from the master tree into the local tree
#
#
function clone_ebuild()
{
if [ "$1" ]
then
guess_ebuild $1
if [[ "$group" && "$ebuild" ]]
then
echo "Cloning ebuild $group/$ebuild"
mkdir -p $LOCAL_PORTAGE/$group
cp -aP $MASTER_PORTAGE/$group/$ebuild $LOCAL_PORTAGE/$group/
else
echo "$1 not in Master Portage"
fi
else
echo "No ebuild specified"
fi
}
#
# Sync Ebuild
#
# Bring changes from maintree into local portage
#
function sync_ebuild()
{
old_cwd=`pwd`
if [ "$1" ]
then
guess_ebuild $1
if [[ "$group" && "$ebuild" ]]
then
echo "Syncing ebuild $group/$ebuild"
cd $LOCAL_PORTAGE
rsync --ignore-existing -r /usr/portage/${group}/${ebuild}/ ${group}/${ebuild}/
git status
fi
else
echo "No ebuild specified"
fi
cd $old_cwd
}
#
# Clean ebuilds
#
# Delete untouched ebuilds from local portage
#
function clean_ebuilds()
{
for ebuild in `ls_le`
do
if [ -d $MASTER_PORTAGE/$ebuild ]; then
result=`diff -br --brief $MASTER_PORTAGE/$ebuild $LOCAL_PORTAGE/$ebuild`
if [ "x$result" == "x" ]
then
echo "Removing local copy of $ebuild"
rm -rf $LOCAL_PORTAGE/$ebuild
fi
else
echo "$ebuild does not exist in master portage"
fi
done
}