#!/bin/bash today=$(date '+%Y%m%d') data_version=$(dpkg-query -f='${Version}' -W lliurexberry-data|tr -c '[:alnum:]' '_') diff_version=$(dpkg-query -f='${Version}' -W n4d-lliurexberry|tr -c '[:alnum:]' '_') temp_dir="/tmp/llxberry_${today}_${data_version}_${diff_version}" if [ -f "${temp_dir}/.lock" ]; then logger "Warning 'create_llxberry_sd', ${temp_dir} is locked! Creating random workdir!" temp_dir=${temp_dir}_$RANDOM fi if [ ! -d "${temp_dir}" ]; then mkdir -p ${temp_dir}/fs fi touch ${temp_dir}/.lock if [ ! -e /var/run/remove_partitions ]; then echo "not exists /var/run/remove_partitions." rm ${temp_dir}/.lock exit 1 fi # # Check root permission # token_name="/var/run/remove_partitions_root_$RANDOM" touch $token_name 2> /dev/null || true if [ ! -e "$token_name" ]; then echo "not exists /var/run/remove_partitions." rm ${temp_dir}/.lock exit 1 fi rm $token_name # # Device is not null # if [ "$1" = "" ];then echo "device is null" exit 1 fi # # Device exist # device="/dev/$1" if [ ! -e "$device" ]; then echo "device not exists" exit 1 fi # # Device is removable # if [ "$2" != "--ignore-removable" ];then removable=$(cat /sys/block/$1/removable) if [ "$removable" = "0" ]; then echo "device isn't removable" ## ## Dialog para preguntar si se esta seguro echo "Device $1 isn't removable. Write yes to continue" read pass if [ "$pass" != "yes" ]; then exit 1 fi fi fi umount -l ${device}? || true # Delete partitions table dd if=/dev/zero of=$device bs=512 count=1 # Refresh partitions partprobe ${device} # Create new partitions table parted -s $device mklabel msdos # Create vfat 35 Mb partition with boot flag parted -a minimal -s $device mkpart primary fat32 '0%' 50 parted -a minimal -s $device set 1 boot on parted -a minimal -s $device mkpart primary ext4 50 '100%' # Refresh partitions partprobe ${device} # Format partition partition_boot=$(get_first_partition $device boot) partition_system=$(get_first_partition $device system) if [ "$partition_boot" = "" -o "$partition_system" = "" ];then echo "error" exit 1 fi mkfs.vfat -F 32 ${partition_boot} mkfs.ext4 -q -F ${partition_system} # Mount partition path_sd="/media/llxberry_$RANDOM" mkdir -p $path_sd mount ${partition_system} $path_sd mkdir -p $path_sd/boot mount ${partition_boot} $path_sd/boot if [ ! -d "${temp_dir}/fs/etc" ]; then data_path=$(llx-berry-manager ${temp_dir}/fs/) else data_path=$temp_dir/fs/ fi # Cp berryboot files rsync -aHAXS "$data_path"/ $path_sd/ # TODO # Modify cmdline.txt and replace _@_server_@_ by SRV_IP n4d var # #eval `n4d-vars getvalues SRV_IP` #sed -i -e "s%_@_SRV_IP_@_%${SRV_IP}%g" ${path_sd}/cmdline.txt echo 0 > /proc/sys/kernel/hung_task_timeout_secs sync echo 120 > /proc/sys/kernel/hung_task_timeout_secs umount $path_sd/boot umount $path_sd rm -rf $path_sd rm /var/run/remove_partitions rm $temp_dir/.lock # This line is very important to n4d clients echo "Ok"