-
Notifications
You must be signed in to change notification settings - Fork 2
/
binhost
executable file
·145 lines (130 loc) · 3.47 KB
/
binhost
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
#!/usr/bin/env bash
source /etc/init.d/functions.sh
function BH_SHOW_HELP()
{
einfo "Build a package:"
echo -e " ./binhost install all/<env-name> app-editors/vim\n"
einfo "Update all packages:"
echo -e " ./binhost update all/<env-name>\n"
einfo "Re-build all packages:"
echo -e " ./binhost emptytree all/<env-name>\n"
einfo "Cleanup packages (depclean, python-updater, eclean, ect):"
echo -e " ./binhost cleanup all/<env-name>\n"
einfo "Full documentation:"
echo -e " https://github.com/p8952/binhost-utils"
exit
}
function BH_CHECK_ENV()
{
if [[ ! -d $1 ]]; then
eerror "Enviroment $1 does not exist"
exit 1
fi
for dir in bin boot dev etc home lib media mnt opt proc root run sbin sys tmp usr var; do
if [[ ! -d $1/$dir ]]; then
eerror "Enviroment $1 does not contain stage3 files"
exit 1
fi
done
if [[ ! -d $1/usr/portage ]]; then
mkdir -p $1/usr/portage
fi
for dir in dev proc sys usr/portage; do
if ! grep -qs $1/$dir /proc/mounts; then
einfo "Enviroment $(basename $1) does not have $dir mounted... mounting"
mount -o rbind /$dir /$1/$dir
mount -o remount,rbind,ro /$dir /$1/$dir
fi
done
}
function BH_CONFIG_UPDATE()
{
cp -r $BH_SCRIPT_DIR/conf/make.conf $1/etc/portage/
cp -r $BH_SCRIPT_DIR/conf/package.* $1/etc/portage/
cp -r $BH_SCRIPT_DIR/conf/resolv.conf $1/etc/
for dir in $(find $BH_SCRIPT_DIR/conf/* -type d); do
if [[ $(basename $1) -eq $(basename $dir) ]]; then
cp -r $BH_SCRIPT_DIR/conf/$(basename $dir)/make.conf $1/etc/portage/
cp -r $BH_SCRIPT_DIR/conf/$(basename $dir)/package.* $1/etc/portage/
cp -r $BH_SCRIPT_DIR/conf/$(basename $dir)/resolv.conf $1/etc/
fi
done
}
function BH_EMERGE()
{
if [[ $2 == "install" ]]; then
chroot $1 /usr/bin/emerge $3
elif [[ $2 == "update" ]]; then
chroot $1 /usr/bin/emerge --update --newuse --deep @world
elif [[ $2 == "emptytree" ]]; then
chroot $1 /usr/bin/emerge --emptytree @world
elif [[ $2 == "cleanup" ]]; then
chroot $1 /usr/bin/emerge --depclean
chroot $1 /usr/bin/revdep-rebuild
chroot $1 /usr/sbin/python-updater
chroot $1 /usr/sbin/perl-cleaner --all
chroot $1 /usr/bin/eclean packages
chroot $1 /usr/bin/eclean distfiles
fi
}
function BH_CLEANUP()
{
chroot $1 /usr/sbin/emaint -f binhost
for dir in dev proc sys usr/portage; do
if grep -qs $1/$dir /proc/mounts; then
einfo "Unmounting $dir from $(basename $1)"
umount -l /$1/$dir
fi
done
}
BH_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BH_CHROOT_DIR="$BH_SCRIPT_DIR/chroots/"
BH_CHROOT_ENV=("gentoo-amd64")
BH_SELECTED_OPTS=0
BH_SELECTED_ARCH=0
BH_SELECTED_PKGS=0
if [[ $1 == "install" ]]; then
if [[ $# -eq 3 ]]; then
BH_SELECTED_OPTS=$1
BH_SELECTED_ARCH=$2
BH_SELECTED_PKGS=$3
else
BH_SHOW_HELP
fi
elif [[ $1 == "update" ]]; then
if [[ $# -eq 2 ]]; then
BH_SELECTED_OPTS=$1
BH_SELECTED_ARCH=$2
BH_SELECTED_PKGS=0
else
BH_SHOW_HELP
fi
elif [[ $1 == "emptytree" ]]; then
if [[ $# -eq 2 ]]; then
BH_SELECTED_OPTS=$1
BH_SELECTED_ARCH=$2
BH_SELECTED_PKGS=0
else
BH_SHOW_HELP
fi
elif [[ $1 == "cleanup" ]]; then
if [[ $# -eq 2 ]]; then
BH_SELECTED_OPTS=$1
BH_SELECTED_ARCH=$2
BH_SELECTED_PKGS=0
else
BH_SHOW_HELP
fi
else
BH_SHOW_HELP
fi
if [[ ! $BH_SELECTED_ARCH == "all" ]]; then
unset -v BH_CHROOT_ENV
BH_CHROOT_ENV=$BH_SELECTED_ARCH
fi
for BH_ENV in ${BH_CHROOT_ENV[@]}; do
BH_CHECK_ENV $BH_CHROOT_DIR$BH_ENV
BH_CONFIG_UPDATE $BH_CHROOT_DIR$BH_ENV
BH_EMERGE $BH_CHROOT_DIR$BH_ENV $BH_SELECTED_OPTS $BH_SELECTED_PKGS
BH_CLEANUP $BH_CHROOT_DIR$BH_ENV
done