Subversion Repositories ALCASAR

Rev

Rev 2687 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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

Generated by GNU Enscript 1.6.6.
112

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