source: n4d-lliurexberry/trunk/fuentes/install/usr/sbin/create_llxberry_sd @ 5893

Last change on this file since 5893 was 5893, checked in by mabarracus, 3 years ago

Avoid errors when gui is interrupted

  • Property svn:executable set to *
File size: 2.9 KB
Line 
1#!/bin/bash
2today=$(date '+%Y%m%d')
3data_version=$(dpkg-query -f='${Version}' -W lliurexberry-data|tr -c '[:alnum:]' '_')
4diff_version=$(dpkg-query -f='${Version}' -W n4d-lliurexberry|tr -c '[:alnum:]' '_')
5
6temp_dir="/tmp/llxberry_${today}_${data_version}_${diff_version}"
7
8if [ -f "${temp_dir}/.lock" ]; then
9    logger "Warning 'create_llxberry_sd', ${temp_dir} is locked! Creating random workdir!"
10    temp_dir=${temp_dir}_$RANDOM
11fi
12
13if [ ! -d "${temp_dir}" ]; then
14    mkdir -p ${temp_dir}/fs
15fi
16touch ${temp_dir}/.lock
17
18if [ ! -e /var/run/remove_partitions ]; then
19        echo "not exists /var/run/remove_partitions."
20        rm ${temp_dir}/.lock
21        exit 1
22fi
23#
24# Check root permission
25#
26token_name="/var/run/remove_partitions_root_$RANDOM"
27touch $token_name 2> /dev/null || true
28if [ ! -e "$token_name" ]; then
29        echo "not exists /var/run/remove_partitions."
30        rm ${temp_dir}/.lock
31        exit 1
32fi
33rm $token_name
34
35#
36# Device is not null
37#
38if [ "$1" = "" ];then
39        echo "device is null"
40        exit 1
41fi
42
43#
44# Device exist
45#
46device="/dev/$1"
47if [ ! -e "$device" ]; then
48        echo "device not exists"
49        exit 1
50fi
51
52#
53# Device is removable
54#
55if [ "$2" != "--ignore-removable"  ];then 
56        removable=$(cat /sys/block/$1/removable)
57        if [ "$removable" = "0" ]; then
58                echo "device isn't removable"
59                ##
60                ## Dialog para preguntar si se esta seguro
61                echo "Device $1 isn't removable. Write yes to continue"
62                read pass
63                if [ "$pass" != "yes" ]; then
64                        exit 1
65                fi
66        fi
67fi
68
69umount -l ${device}? || true
70# Delete partitions table
71dd if=/dev/zero of=$device bs=512 count=1
72# Refresh partitions
73partprobe ${device}
74# Create new partitions table
75parted -s $device mklabel msdos
76# Create vfat 35 Mb partition with boot flag
77parted -a minimal -s $device mkpart primary fat32 '0%' 50
78parted -a minimal -s $device set 1 boot on
79parted -a minimal -s $device mkpart primary ext4 50 '100%'
80# Refresh partitions
81partprobe ${device}
82# Format partition
83partition_boot=$(get_first_partition $device boot)
84partition_system=$(get_first_partition $device system)
85if [ "$partition_boot" = "" -o "$partition_system" = "" ];then
86        echo "error"
87        exit 1
88fi
89mkfs.vfat -F 32 ${partition_boot}
90mkfs.ext4 -q -F ${partition_system}
91# Mount partition
92path_sd="/media/llxberry_$RANDOM"
93mkdir -p $path_sd
94mount ${partition_system} $path_sd
95mkdir -p $path_sd/boot
96mount ${partition_boot} $path_sd/boot
97
98if [ ! -d "${temp_dir}/fs/etc" ]; then
99    data_path=$(llx-berry-manager ${temp_dir}/fs/)
100else
101    data_path=$temp_dir/fs/
102fi
103
104# Cp berryboot files
105rsync -aHAXS "$data_path"/ $path_sd/
106
107# TODO
108# Modify cmdline.txt and replace _@_server_@_ by SRV_IP n4d var
109#
110#eval `n4d-vars getvalues SRV_IP`
111#sed -i -e "s%_@_SRV_IP_@_%${SRV_IP}%g" ${path_sd}/cmdline.txt
112echo 0 > /proc/sys/kernel/hung_task_timeout_secs
113sync
114echo 120 > /proc/sys/kernel/hung_task_timeout_secs
115umount $path_sd/boot
116umount $path_sd
117rm -rf $path_sd
118
119rm /var/run/remove_partitions
120rm $temp_dir/.lock
121# This line is very important to n4d clients
122echo "Ok"
Note: See TracBrowser for help on using the repository browser.