Subversion Repositories ALCASAR

Rev

Rev 2672 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2672 Rev 2687
-
 
1
# Mageia (Mageia + ALCASAR) ISO builder
-
 
2
# By Aurélien DUBOIS 
-
 
3
 
1
#!/bin/bash
4
#!/bin/bash
2
 
5
 
3
#######################
6
#######################
4
###### Variables ######
7
###### Variables ######
5
################################################################################
8
################################################################################
6
 
9
 
7
# Script variables
10
# Script variables
8
CURRENT_DIR="$(readlink -f "$(dirname $0)")"
11
CURRENT_DIR="$(readlink -f "$(dirname $0)")"
9
RESSOURCES="$CURRENT_DIR/ressources"
12
RESSOURCES="$CURRENT_DIR/ressources"
10
SCRIPTS_DIR="$CURRENT_DIR/scripts"
13
SCRIPTS_DIR="$CURRENT_DIR/scripts"
11
SCRIPTS_TMP_DIR="$CURRENT_DIR/scripts_tmp"
14
SCRIPTS_TMP_DIR="$CURRENT_DIR/scripts_tmp"
12
BUILDER_SCRIPT="build-image.sh"
15
BUILDER_SCRIPT="build-image.sh"
13
LOG_FILE="${CURRENT_DIR}/mageiarBuilder.log"
16
LOG_FILE="${CURRENT_DIR}/mageiarBuilder.log"
14
 
17
 
15
 
18
 
16
#######################
19
#######################
17
###### Functions ######
20
###### Functions ######
18
################################################################################
21
################################################################################
19
# Print the given error message and exit 1
22
# Print the given error message and exit 1
20
function errorExit()
23
function errorExit()
21
{
24
{
22
    tput bold
25
    tput bold
23
    echo -e "ERROR : $1 \nAborting\n" >&2
26
    echo -e "ERROR : $1 \nAborting\n" >&2
24
    echo "$1" > "$LOG_FILE"
27
    echo "$1" > "$LOG_FILE"
25
    tput sgr0
28
    tput sgr0
26
    exit 1
29
    exit 1
27
}
30
}
28
#-------------------------------------------------------------------------------
31
#-------------------------------------------------------------------------------
29
function printBold()
32
function printBold()
30
{
33
{
31
    tput bold 2>/dev/null
34
    tput bold 2>/dev/null
32
    echo $1
35
    echo $1
33
    tput sgr0 2>/dev/null
36
    tput sgr0 2>/dev/null
34
}
37
}
35
#######################
38
#######################
36
######   Main    ######
39
######   Main    ######
37
################################################################################
40
################################################################################
38
 
41
 
39
# Check root
42
# Check root
40
[[ $(whoami) != 'root' ]] && errorExit 'Please run as root'
43
[[ $(whoami) != 'root' ]] && errorExit 'Please run as root'
41
 
44
 
42
# Check options
45
# Check options
43
while getopts "a:h" option; do
46
while getopts "a:h" option; do
44
    case $option in
47
    case $option in
45
        a) # Alcasar image
48
        a) # Alcasar image
46
            alcasarTar="$(echo $OPTARG | rev | cut -d '/' -f 1 | rev)"
49
            alcasarTar="$(echo $OPTARG | rev | cut -d '/' -f 1 | rev)"
47
            [[ ! -f "$OPTARG" ]] && errorExit "could not find $OPTARG"
50
            [[ ! -f "$OPTARG" ]] && errorExit "could not find $OPTARG"
48
            # Copy the image in the ressource directory to be accessible from the docker
51
            # Copy the image in the ressource directory to be accessible from the docker
49
            printBold "Copying $OPTARG" in $RESSOURCES
52
            printBold "Copying $OPTARG" in $RESSOURCES
50
            rsync -usP "$OPTARG" "$RESSOURCES/$alcasarTar" || \
53
            rsync -usP "$OPTARG" "$RESSOURCES/$alcasarTar" || \
51
            errorExit "could not copy $OPTARG to $RESSOURCES"
54
            errorExit "could not copy $OPTARG to $RESSOURCES"
52
 
55
 
53
        ;;
56
        ;;
54
        *)
57
        *)
55
            echo "Usage : buildMageiar [-a alcasar.tar.gz]"
58
            echo "Usage : buildMageiar [-a alcasar.tar.gz]"
56
            exit 1
59
            exit 1
57
        ;;
60
        ;;
58
    esac
61
    esac
59
done
62
done
60
 
63
 
61
# Check if auto_inst.cfg.pl is present
64
# Check if auto_inst.cfg.pl is present
62
[[ ! -f "$RESSOURCES/auto_inst.cfg.pl_template" ]] && errorExit "No auto_inst.cfg.pl_template file in $RESSOURCES"
65
[[ ! -f "$RESSOURCES/auto_inst.cfg.pl_template" ]] && errorExit "No auto_inst.cfg.pl_template file in $RESSOURCES"
63
 
66
 
64
#-------------------------------------------------------------------------------
67
#-------------------------------------------------------------------------------
65
# If needed, download Alcasar image
68
# If needed, download Alcasar image
66
#-------------------------------------------------------------------------------
69
#-------------------------------------------------------------------------------
67
 
70
 
68
if [[ -z $alcasarTar ]]; then
71
if [[ -z $alcasarTar ]]; then
69
    latestAlcasarVersion="-$(dig version.alcasar.net txt | \
72
    latestAlcasarVersion="-$(dig version.alcasar.net txt | \
70
        grep "ANSWER SECTION" -A 1 | \
73
        grep "ANSWER SECTION" -A 1 | \
71
        grep version | cut -d '"' -f2 || \
74
        grep version | cut -d '"' -f2 || \
72
        errorExit "could not retrieve Alcasar latest version")"
75
        errorExit "could not retrieve Alcasar latest version")"
73
    alcasarTar="alcasar$latestAlcasarVersion.tar.gz"
76
    alcasarTar="alcasar$latestAlcasarVersion.tar.gz"
74
 
77
 
75
    printBold "Downloading Alcasar image"
78
    printBold "Downloading Alcasar image"
76
    wget -O "$RESSOURCES/$alcasarTar" "ftp.alcasar.net:/pub/stable/$alcasarTar" || errorExit 'could not download Alcasar'
79
    wget -O "$RESSOURCES/$alcasarTar" "ftp.alcasar.net:/pub/stable/$alcasarTar" || errorExit 'could not download Alcasar'
77
fi
80
fi
78
 
81
 
79
#
82
#
80
# If Mageia image isn't provided here, it will be downloaded in the docker.
83
# If Mageia image isn't provided here, it will be downloaded in the docker.
81
# This is because the version has to match the one in the docker
84
# This is because the version has to match the one in the docker
82
#
85
#
83
 
86
 
84
#-------------------------------------------------------------------------------
87
#-------------------------------------------------------------------------------
85
# Run docker image
88
# Run docker image
86
#-------------------------------------------------------------------------------
89
#-------------------------------------------------------------------------------
87
systemctl start docker || errorExit 'could not start docker service'
90
systemctl start docker || errorExit 'could not start docker service'
88
 
91
 
89
# Copy script folder to temporary one
92
# Copy script folder to temporary one
90
cp -r "$SCRIPTS_DIR" "$SCRIPTS_TMP_DIR"
93
cp -r "$SCRIPTS_DIR" "$SCRIPTS_TMP_DIR"
91
 
94
 
92
 
95
 
93
printBold "Running mageia docker"
96
printBold "Running mageia docker"
94
docker run --privileged --rm --volume "$RESSOURCES":/var/iso --volume "$SCRIPTS_TMP_DIR":/root/ -it mageia "/root/$BUILDER_SCRIPT" "$alcasarTar"
97
docker run --privileged --rm --volume "$RESSOURCES":/var/iso --volume "$SCRIPTS_TMP_DIR":/root/ -it mageia "/root/$BUILDER_SCRIPT" "$alcasarTar"
95
 
98
 
96
[[ -d "$SCRIPTS_TMP_DIR" ]] && rm -Rf "$SCRIPTS_TMP_DIR" 2>/dev/null
99
[[ -d "$SCRIPTS_TMP_DIR" ]] && rm -Rf "$SCRIPTS_TMP_DIR" 2>/dev/null
97
 
100
 
98
# Retrieve created iso image
101
# Retrieve created iso image
99
mv "$RESSOURCES"/Mageia*Alcasar* "$CURRENT_DIR" 2>/dev/null
102
mv "$RESSOURCES"/Mageia*Alcasar* "$CURRENT_DIR" 2>/dev/null
100
 
103
 
101
# Give it to SUDO_USER if exists
104
# Give it to SUDO_USER if exists
102
[[ ! -z $SUDO_USER ]] && chown -R $SUDO_USER "$CURRENT_DIR"/* 2>/dev/null
105
[[ ! -z $SUDO_USER ]] && chown -R $SUDO_USER "$CURRENT_DIR"/* 2>/dev/null
103
 
106
 
104
#-------------------------------------------------------------------------------
107
#-------------------------------------------------------------------------------
105
# Stopping
108
# Stopping
106
#-------------------------------------------------------------------------------
109
#-------------------------------------------------------------------------------
107
read -p 'Stop docker service ? [Y/n] : ' ynAnswer
110
read -p 'Stop docker service ? [Y/n] : ' ynAnswer
108
[[ ! $ynAnswer = [nN] ]] && systemctl stop docker
111
[[ ! $ynAnswer = [nN] ]] && systemctl stop docker
109
#-------------------------------------------------------------------------------
112
#-------------------------------------------------------------------------------
110
 
113
 
111
 
114
 
112

Generated by GNU Enscript 1.6.6.
115

Generated by GNU Enscript 1.6.6.
113
 
116
 
114
 
117
 
115
 
118