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

if [ `whoami` != 'root' ] ; then
  echo "This script must be run with 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]: "
read response
if [ -n "$response" ]; then
    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/live-rw
mkdir -p $rw_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=/live/image/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/

# 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="-t unionfs -o noatime,dirs=$rw_dir=rw:$READ_ROOT=ro unionfs $INST_ROOT"
if ! try_mount "$margs"; then
  echo 'Exiting...'
  exit 1
fi

becho "Done!"

exit 0