-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun-mageia
executable file
·145 lines (133 loc) · 4.01 KB
/
run-mageia
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
#!/bin/bash
#
# Create a Mageia Docker Image if needed and instantiate a container out of it
#
# Detect force mode
if [ _"$1" = _"-f" ]; then
FORCE=1
shift
fi
# Support passing the distro to operate on as parameter
if [ _"$1" != _"" ]; then
MGAVER=$1
shift
fi
# Support passing the package to rebuild on as parameter
if [ _"$1" != _"" ]; then
PACKAGEL=$*
fi
APPNAME=${APPNAME:=mageia-docker}
# Support variable definitions from our own env
if [ -f $HOME/.$APPNAME ]; then
. $HOME/.$APPNAME
fi
# Default distro to consider
MGAVER=${MGAVER:=cauldron}
# Default temporary directory
TMPDM=${TMPDM:=$HOME/tmp/$APPNAME}
# Default mirror
MGAMIRROR=${MGAMIRROR:=http://distrib-coffee.ipsl.jussieu.fr/pub/linux/Mageia/distrib}
# Default Working directory where you svn co mageia-pkg
WORKDIR=${WORKDIR:=$HOME/mageia}
# Default architecture
MGAARCH=${MGAARCH:=x86_64}
mkdir -p $TMPDM
cd $TMPDM
MUID=`getent passwd $USER | cut -d: -f3`
MGID=`getent passwd $USER | cut -d: -f4`
DCKSRCIMG=${DCKSRCIMG:=mageia:$MGAVER}
#DCKBUILDIMG=mageiaofficial:$MGAVER-$MGAARCH
DCKBUILDIMG=pb:mageiabuild$MGAVER-$MGAARCH
# Build the Dockerfile
cat > Dockerfile << EOF
# Start from a good known image
FROM $DCKSRCIMG
MAINTAINER bcornec@mageia.org
# In case there is an issue with that mirror
#RUN perl -pi -e 's|http://distro.ibiblio.org/mageia|$MGAMIRROR|' /etc/urpmi/urpmi.cfg
# Point to the mirror we want
# Not useful if using mageiaofficial:$MGAVER-$MGAARCH
RUN urpmi.removemedia -a
RUN urpmi.addmedia --probe-hdlist --distrib mga $MGAMIRROR/$MGAVER/$MGAARCH
# Update metadata just in case 2 previous lines are not used
RUN echo "urpmi.update -a -c -f" > /usr/local/bin/upd
# Update packages
RUN echo "urpmi --auto --auto-select --no-recommends" >> /usr/local/bin/upd
RUN chmod 755 /usr/local/bin/upd
RUN /usr/local/bin/upd
# install what we need to work
RUN urpmi --auto --no-recommends bm subversion mgarepo colordiff sudo
# if dnf is installed fix repo:
#RUN perl -pi -e 's|mirrorlist=|#mirrorlist=|' /etc/yum.repos.d/*.repo
#RUN perl -pi -e 's|#baseurl=https://mirrors.kernel.org/mageia/distrib|baseurl=$MGAMIRROR|' /etc/yum.repos.d/*.repo
#RUN dnf makecache
# Fix group id
RUN sed -i "s/users:x:.*$/users:x:$MGID/" /etc/group
# Add ourselves to the image
RUN useradd $USER -u $MUID -g $MGID -N -M -d $HOME
# give us sudo power
RUN echo "$USER ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
# prepare home mount point
RUN mkdir -p $HOME
WORKDIR $WORKDIR
USER $USER
CMD /bin/bash
EOF
# Check whether the image already exist
stat=0
docker inspect $DCKBUILDIMG 2>&1 > /dev/null
if [ $? -eq 0 ]; then
# remove it if we force with -f
if [ "$FORCE" = "1" ]; then
docker rmi $DCKBUILDIMG
fi
else
# Build it as it doesn't exist yet
docker build --file=Dockerfile -t $DCKBUILDIMG .
stat=$?
fi
if [ $stat -eq 0 ]; then
DOCKEROPT="--rm -v $SSH_AUTH_SOCK:/ssh-agent -v $HOME:$HOME -v $TMPDM:$TMPDM -v /var/run/libvirt:/var/run/libvirt -e SSH_AUTH_SOCK=/ssh-agent -ti -u $USER -w $WORKDIR"
if [ _"$PACKAGEL" != _"" ]; then
if [ _"$MGAVER" != _"cauldron" ]; then
MGAREPOCOPT="-d $MGAVER"
MGAREPOSOPT="--define section=core/updates_testing"
else
MGAREPOCOPT=""
MGAREPOSOPT=""
fi
for p in $PACKAGEL; do
cat > $TMPDM/Dockerfile.$p << EOF
# Start from a good known image
FROM $DCKBUILDIMG
MAINTAINER bcornec@mageia.org
RUN sudo urpmi --auto --auto-select --no-requires
COPY SPECS/$p.spec /tmp
RUN sudo urpmi --auto /tmp/$p.spec
EOF
cat > $TMPDM/$p.build << EOF
#!/bin/bash
cd $WORKDIR/$p
bm -l
if [ \$? -eq 0 ]; then
echo "Do a svn ci -m '' and then "
echo "mgarepo submit $MGAREPOSOPT"
#echo "docker rm ctn$MGAVER-$p"
echo "docker rmi $DCKBUILDIMG-$p"
fi
EOF
chmod 755 $TMPDM/$p.build
cd $WORKDIR
mgarepo co $MGAREPOCOPT $p
cd $WORKDIR/$p
mgarepo sync -d
docker buildx build --file=$TMPDM/Dockerfile.$p -t $DCKBUILDIMG-$p .
docker rm ctn$MGAVER-$p
docker run $DOCKEROPT --name ctn$MGAVER-$p $DCKBUILDIMG-$p $TMPDM/$p.build
rm -f $TMPDM/$p.build $TMPDM/Dockerfile.$p
done
else
# Nothing to build - interactive mode
docker run $DOCKEROPT $DCKBUILDIMG
fi
fi