--- /dev/null
+# Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Function uuid2dev() converts UUID stored in $FILE
+# to corresponding /dev/sd*.
+#
+# Syntax is:
+# * uuid2dev $FILE
+# * change_uuid $FILE $DEV_SDCARD
+#
+# Author: Aleksander Mistewicz <a.mistewicz@samsung.com>
+
+uuid2dev() {
+ FILE="$1"
+ test -n "${FILE}" || die "Missing argument: file!"
+ test -f "${FILE}" || die "${FILE} does not exist!"
+
+ UUID="`cat ${FILE}`"
+ DEV="`readlink /dev/disk/by-uuid/${UUID}`"
+ SLEEP=2
+
+ echo "Searching: ${UUID}" >&2
+
+ while [ -z "${DEV}" -a ${SLEEP} -le 30 ]
+ do
+ sleep "${SLEEP}"
+ SLEEP=$((SLEEP+2))
+ DEV="`readlink /dev/disk/by-uuid/${UUID}`"
+ done
+
+ test -n "${DEV}" || die "DEV is empty, device not found!"
+
+ DEV="${DEV##*/}"
+
+ echo "/dev/${DEV%[0-9]}"
+}
+
+change_uuid() {
+ FILE="$1"
+ DEV_SDCARD="$2"
+ test -n "${FILE}" || die "Missing argument: file!"
+ test -n "${DEV_SDCARD}" || die "Missing argument: dev_sdcard!"
+
+ NEW_UUID="`uuidgen`"
+ # 2nd partition is used because:
+ # * 1st partition is vfat (boot)
+ # * 3rd partition sometimes does not exists (i.e. wayland-efi)
+ PART="${DEV_SDCARD}2"
+
+ # remove uninit_bg option from filesystem for UUID change. result is:
+ # * e2fsck is not required
+ # * UUID change is successful
+ sudo tune2fs -O "^uninit_bg" "${PART}"
+ sudo tune2fs "${PART}" -U "${NEW_UUID}"
+ sudo tune2fs -O "+uninit_bg" "${PART}"
+
+ echo "${NEW_UUID}" > "${FILE}"
+}