40AddSwap.in 1.94 KB
Newer Older
Nikos Skalkotos's avatar
Nikos Skalkotos committed
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
#! /bin/bash

# Copyright (C) 2011 GRNET S.A. 
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.

### BEGIN TASK INFO
# Provides:		AddSwap
# RunBefore:            UmountImage
# RunAfter:             MountImage
# Short-Description:    Set up the swap partition and add an entry in fstab
### END TASK INFO

set -e
. "@commondir@/common.sh"

30
31
32
trap task_cleanup EXIT
report_start_task

Nikos Skalkotos's avatar
Nikos Skalkotos committed
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
# Check if the task should be prevented from running.
check_if_excluded

if [ ! -d "$SNF_IMAGE_TARGET" ]; then
    log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing."
fi

if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" != "linux" ]; then
    exit 0
fi

if [ -z "$SNF_IMAGE_PROPERTY_SWAP" ]; then
    warn "No swap partition defined"
    exit 0
fi

if [[ "$SNF_IMAGE_PROPERTY_SWAP" =~ ^([0-9]+):[0-9]+$ ]]; then
    swap_id=${BASH_REMATCH[1]}
else
    log_error "SWAP property \`$SNF_IMAGE_PROPERTY_SWAP' is not valid"
fi

swap_dev="${SNF_IMAGE_DEV}${swap_id}"

if [ ! -b "$swap_dev" ]; then
    log_error "Swap partition \`$swap_dev' is missing."
fi

$MKSWAP "$swap_dev"

UUID=$(cut -d" " -f2 <<< $($BLKID -s UUID "$swap_dev"))

if [ -f "$SNF_IMAGE_TARGET/etc/fstab" ]; then
    echo -e "$UUID\tnone\tswap\tsw\t0\t0" >> "$SNF_IMAGE_TARGET/etc/fstab"
else
    log_error "/etc/fstab file is missing"
fi

exit 0

# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :