summaryrefslogtreecommitdiffstats
path: root/setup_env_container.sh
blob: 3c293e580bb1cbfe32f4d483c626c2d74be51405 (plain)
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/bin/bash
#  Script to setup the LinHES development enviroment
# ./setup_env.sh ( i686|x86_64 )  devID
# This script assumes that /tmp is usable.
START_DIR=`pwd`
TS=`date  +%Y%h%d_%H%M%S`

function arg_check {
    case $1 in
        i686) ARCH=$1 ;;
        x86_64) ARCH=$1 ;;
        *)
            echo "invalid arch specified"
            echo "valid options include i686 and x86_64"
            echo "EX:  ./setup_env.sh i686 "
            echo "EX:  ./setup_env.sh x86_64 "
            exit 1
            ;;
        esac


    case $2 in
        release) BENV="release" ;;
        testing) BENV="testing" ;;

        *)
            echo "invalid env specified"
            echo "valid options include release, testing"
            echo "EX:  ./setup_env.sh i686 testing"
            echo "EX:  ./setup_env.sh x86_64 testing"
            exit 1
            ;;
        esac


    if [ ! x$3 = x ]
    then
        USER=$3
        #check if developer template is present
    fi

}


function pacman_check {
    for i in pacman pacstrap
    do
        which $i
        status=$?
        if [ ! $status = 0 ]
        then
            echo "Can not find $i in the path."
            exit 1
        fi
    done


}


function checkout_repo {
    mkdir -p  $BENV/$ARCH
    cd $BENV/$ARCH

    git clone git@linhes.org:linhes_dev
    git clone git@linhes.org:linhes_pkgbuild

    # git clone $USER@knoppmyth.net:linhes_pkgbuild
    # git clone $USER@knoppmyth.net:linhes_dev


    if [ $BENV  == "testing" ]
    then
        echo "====================================="
        echo "switching linhes_pkgbuild to testing"

        cd linhes_pkgbuild
        git checkout -b testing origin/testing
        cd -

        echo "====================================="
    fi

    if [ $BENV  == "testing" ]
    then
        echo "====================================="
        echo "switching linhes_dev to testing"

        cd linhes_dev
        git checkout -b testing origin/testing
        cd -

    echo "====================================="
    fi

}

create_pkg_mirror_dir(){
    #create the local pkg dir's for mirror and creating pkg's

    [ -e $MIRROR_DIR     ] || mkdir -p $MIRROR_DIR

    for i in i686 x86_64
    do
        [ -e $MIRROR_DIR/$i     ] || mkdir -p $MIRROR_DIR/$i
        for y in core extra core-testing extra-testing
        do
            [ -e $MIRROR_DIR/$i/$y     ] || mkdir -p $MIRROR_DIR/$i/$y
            [ -e $MIRROR_DIR/src_packages/$y     ] || mkdir -p $MIRROR_DIR/src_packages/$y
        done
    done

    [ -e $MIRROR_DIR/sources     ] || mkdir -p $MIRROR_DIR/sources
    [ -e $MIRROR_DIR/packages    ] || mkdir -p $MIRROR_DIR/packages

}

create_container(){
    #correct pacman.conf to use the correct ARCH to build the chroot
    cd $START_DIR/$BENV/$ARCH/linhes_dev
    sed -e "s/REPLACEME/$ARCH/g" templates/pacman.conf.chroot > /tmp/pacman.conf.chroot

    #create the container
    cd $START_DIR
    #mkdir -p $START_DIR/$BENV/$ARCH/linhes_container_root.$ARCH
    mkdir -p $CONTAINER_DIR
    pacstrap -i -c -d -C /tmp/pacman.conf.chroot $CONTAINER_DIR  base base-devel openssh unison
    status=$?

    if [ !  $status  = 0 ]
    then
        printf "\n"
        printf "%s\n" "********************************************************"
        printf "*** %-48s ***\n" "      An error occured creating the container"
        printf "%s\n" "********************************************************"
        exit 1
    fi
}


copy_custom_developer_file(){
    cd $START_DIR/$BENV/$ARCH/linhes_dev
    if [ -d templates/developers/$USER ]
    then
        #check for login run
        if [ -f templates/developers/$USER/loginrun.sh ]
        then
            echo "copy loginrun.sh for $USER"
            cp -f templates/developers/$USER/loginrun.sh $CONTAINER_DIR/root/loginrun.sh
        fi

        if [ -f templates/developers/$USER/custom_chroot.sh ]
        then
            echo "running custom_chroot.sh for $USER"
            cd templates/developers/$USER
            BROOT=$CONTAINER_DIR ./custom_chroot.sh $ARCH
            cd -
        fi

    fi
}

create_entry_files() {

    #create custom enter_dev_chroot.sh script
    cp  templates/enter_dev_container.sh ../enter_dev_container.$ARCH.$TS
    sed -i "s/REPLACE_ARCH/$ARCH/" ../enter_dev_container.$ARCH.$TS
    sed -i "s/REPLACE_TS/$TS/" ../enter_dev_container.$ARCH.$TS

    chmod 755 ../enter_dev_container.$ARCH.$TS

    printf "%s\n" "********************************************************"
    printf "** %-50s **\n" "    To enter the container (linhes_container_root.$ARCH.$TS) run:"
    printf "** %-50s **\n" "            cd  $BENV/$ARCH"
    printf "** %-50s **\n" "            ./enter_dev_container.$ARCH.$TS"
    printf "%s\n" "********************************************************"

    #copy makepkg.conf into the chroot
    sed -e "s/REPLACEME/$ARCH/g" templates/makepkg.conf >  ../linhes_container_root.$ARCH.$TS/etc/makepkg.conf

    #copy pacman.conf into the chroot
    sed -e "s/REPLACEME/$ARCH/g" templates/pacman.conf.chroot > ../linhes_container_root.$ARCH.$TS/etc/pacman.conf
}




#-----------------------------------------------

arg_check $1 $2 $3
#checkout_repo
pacman_check

MIRROR_DIR=$START_DIR/$BENV/pkg_repo
create_pkg_mirror_dir

CONTAINER_DIR=$START_DIR/$BENV/$ARCH/linhes_container_root.$ARCH.$TS
create_container
copy_custom_developer_file
create_entry_files