summaryrefslogtreecommitdiff
path: root/scripts/install/install-image-new
blob: d6427500ece044e0f4b995793c480fcd03b1ec1d (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
#!/bin/bash

if [ $(id -u) != 0 ]; then
    echo "Image installation requires root privileges!"
    exit 1
fi

# source in the functions
source /opt/vyatta/sbin/install-functions

# the INSTALL_LOG env var should be exported by the "caller".
# it will be used to log messages.

# the install partition e.g. sda1
ROOT_PARTITION=$1

becho "Mounting /dev/$ROOT_PARTITION..."

# mount the partition
mkdir -p $WRITE_ROOT
if ! try_mount "/dev/$ROOT_PARTITION $WRITE_ROOT"; then
  echo 'Exiting...'
  exit 1
fi

version=$(get_new_version)
image_name=$version
if [ -z "$image_name" ]; then
  echo 'Cannot find new version. Exiting...'
  exit 1
fi

echo -n "What would you like to name this image? [$image_name]: "
if [ "$VYATTA_PROCESS_CLIENT" == "gui2_rest" ]; then
    response=$NEWNAME
else
    read response
fi
if [ -n "$response" ]; then
    badchars=`echo $response | sed -e 's/[a-zA-Z0-9\.\_+-]//g'`
    if [ -n "$badchars" ]; then
        echo "Image name must be composed of a-z, A-Z, 0-9, or one of ._+-"
        exit 1
    fi
    image_name=$response
fi

# Validate image name
if [ "$image_name" = "grub" -o "${image_name:0:7}" = "vmlinuz" -o \
    "${image_name:0:6}" = "initrd" -o "${image_name:0:10}" = "System.map" -o \
    "$image_name" = "Old-non-image-installation" ]; then
    echo "Can't use $image_name.  It is a reserved image name."
    exit 1;
fi

if [ -z "$image_name" ]; then
  failure_exit 'Invalid image name.'
fi

echo "OK.  This image will be named: $image_name"

# make the dir for the new version 
mkdir -p $WRITE_ROOT/boot/$image_name
# make dir for backing store
rw_dir=$WRITE_ROOT/boot/$image_name/rw
mkdir -p $rw_dir
work_dir=$WRITE_ROOT/boot/$image_name/work
mkdir -p $work_dir

echo Copying squashfs image...
# these are the defaults if installing from a specified ISO image file.
# in such cases, the ISO image has already been mounted by caller.
squash_img=${CD_ROOT}/live/filesystem.squashfs
boot_dir=${CD_SQUASH_ROOT}/boot
boot_files=$(find $boot_dir -maxdepth 1 -type f -o -type l 2>/dev/null)
if [ ! -f "$squash_img" ] || [ -z "$boot_files" ]; then
  # maybe installing from a live CD boot?
  squash_img=/lib/live/mount/medium/live/filesystem.squashfs
  boot_dir=/boot
  boot_files=$(find $boot_dir -maxdepth 1 -type f -o -type l 2>/dev/null)
  if [ ! -f "$squash_img" ] || [ -z "$boot_files" ]; then
    # not a live CD boot either. give up.
    becho 'Cannot find the squashfs image. Exiting...'
    exit 1
  fi
fi

target_squash=$WRITE_ROOT/boot/$image_name/$version.squashfs
cp -p $squash_img $target_squash
echo Copying kernel and initrd images...
cp -dp $boot_files $WRITE_ROOT/boot/$image_name/

# create persistence.conf file
echo "/ union" > $WRITE_ROOT/persistence.conf

# set up union root for postinst
mkdir -p $INST_ROOT $READ_ROOT
if ! try_mount "-o loop,ro -t squashfs $target_squash $READ_ROOT"; then
  echo 'Exiting...'
  exit 1
fi
margs=$(gen_mopts "overlay" $rw_dir $READ_ROOT $work_dir $INST_ROOT)
if ! try_mount "$margs"; then
  echo 'Exiting...'
  exit 1
fi

becho "Done!"

exit 0