report_error() {
if [ ${#ERRORS[*]} -eq 0 ]; then
# No error message. Print stderr
- local lines=$(tail --lines=${STDERR_LINE_SIZE} "$STDERR_FILE" | wc -l)
+ local lines
+ lines=$(tail --lines=${STDERR_LINE_SIZE} "$STDERR_FILE" | wc -l)
echo -n "STDERR:${lines}:" > "$MONITOR"
tail --lines=$lines "$STDERR_FILE" > "$MONITOR"
else
}
get_distro() {
- local root_dir=$1
+ local root_dir distro
+ root_dir=$1
if [ -e "$root_dir/etc/debian_version" ]; then
distro="debian"
get_partition_table() {
- local dev="$1"
+ local dev output
+ dev="$1"
# If the partition table is gpt then parted will raise an error if the
# secondary gpt is not it the end of the disk, and a warning that has to
# do with the "Last Usable LBA" entry in gpt.
}
get_partition_table_type() {
- local ptable="$1"
+ local ptable dev field
+ ptable="$1"
- local dev="$(sed -n 2p <<< "$ptable")"
- declare -a field
+ dev="$(sed -n 2p <<< "$ptable")"
IFS=':' read -ra field <<< "$dev"
echo "${field[5]}"
}
get_extended_partition() {
- local ptable="$1"
- local dev="$(echo "$ptable" | sed -n 2p | cut -d':' -f1)"
+ local ptable dev
+ ptable="$1"
+ dev="$(echo "$ptable" | sed -n 2p | cut -d':' -f1)"
tail -n +3 <<< "$ptable" | while read line; do
part_num=$(cut -d':' -f1 <<< "$line")
}
get_logical_partitions() {
- local ptable="$1"
+ local ptable part_num
+ ptable="$1"
tail -n +3 <<< "$ptable" | while read line; do
part_num=$(cut -d':' -f1 <<< "$line")
}
get_last_primary_partition() {
- local ptable="$1"
- local dev=$(echo "ptable" | sed -n 2p | cut -d':' -f1)
+ local ptable dev output
+ ptable="$1"
+ dev=$(echo "ptable" | sed -n 2p | cut -d':' -f1)
for i in 4 3 2 1; do
if output=$(grep "^$i:" <<< "$ptable"); then
}
get_partition_to_resize() {
- local dev="$1"
+ local dev table table_type last_part last_part_num extended last_primary \
+ ext_num prim_num
+ dev="$1"
table=$(get_partition_table "$dev")
local part="$2"
local ptype="$3"
- declare -a fields
+ local fields=()
IFS=":;" read -ra fields <<< "$part"
local id="${fields[0]}"
local start="${fields[1]}"
}
enlarge_partition() {
- local device="$1"
- local part="$2"
- local ptype="$3"
- local new_end="$4"
+ local device part ptype new_end fields new_part table logical id
+ device="$1"
+ part="$2"
+ ptype="$3"
+ new_end="$4"
if [ -z "$new_end" ]; then
new_end=$(cut -d: -f 3 <<< "$(get_last_free_sector "$device")")
fi
- declare -a fields
+ fields=()
IFS=":;" read -ra fields <<< "$part"
fields[2]="$new_end"
- local new_part=""
+ new_part=""
for ((i = 0; i < ${#fields[*]}; i = i + 1)); do
new_part="$new_part":"${fields[$i]}"
done
# If this is an extended partition, removing it will also remove the
# logical partitions it contains. We need to save them for later.
if [ "$ptype" = "extended" ]; then
- local table="$(get_partition_table "$device")"
- local logical="$(get_logical_partitions "$table")"
+ table="$(get_partition_table "$device")"
+ logical="$(get_logical_partitions "$table")"
fi
id=${fields[0]}
}
get_last_free_sector() {
- local dev="$1"
- local unit="$2"
+ local dev unit last_line ptype
+ dev="$1"
+ unit="$2"
if [ -n "$unit" ]; then
unit="unit $unit"
fi
- local last_line="$("$PARTED" -s -m "$dev" "$unit" print free | tail -1)"
- local ptype="$(cut -d: -f 5 <<< "$last_line")"
+ last_line="$($PARTED -s -m "$dev" "$unit" print free | tail -1)"
+ ptype="$(cut -d: -f 5 <<< "$last_line")"
if [ "$ptype" = "free;" ]; then
echo "$last_line"
}
get_unattend() {
- local target="$1"
+ local target exists
+ target="$1"
# Workaround to search for $target/Unattend.xml in an case insensitive way.
exists=$(find "$target"/ -maxdepth 1 -iname unattend.xml)
}
task_cleanup() {
- rc=$?
+ local rc=$?
if [ $rc -eq 0 ]; then
report_task_end
}
check_if_excluded() {
- local name="$(tr [a-z] [A-Z] <<< ${PROGNAME:2})"
- local exclude="SNF_IMAGE_PROPERTY_EXCLUDE_TASK_${name}"
+ local name exclude
+ name="$(tr [a-z] [A-Z] <<< ${PROGNAME:2})"
+ exclude="SNF_IMAGE_PROPERTY_EXCLUDE_TASK_${name}"
if [ -n "${!exclude}" ]; then
warn "Task ${PROGNAME:2} was excluded and will not run."
exit 0
check_if_excluded
windows_password() {
- local target="$1"
- local password="$2"
+ local target password
+ target="$1"
+ password="$2"
echo "@echo off" > "$target/Windows/SnfScripts/ChangeAdminPassword.cmd"
}
linux_password() {
- local target="$1"
- local password="$2"
+ local target password hash users tmp_shadow
+ target="$1"
+ password="$2"
- local hash=$("@scriptsdir@/snf-passtohash.py" "$password")
+ hash=$("@scriptsdir@/snf-passtohash.py" "$password")
if [ ! -e "$target/etc/shadow" ]; then
log_error "No /etc/shadow found!"
fi
- declare -a users
+ users=()
if [ -n "$SNF_IMAGE_PROPERTY_USERS" ]; then
for usr in $SNF_IMAGE_PROPERTY_USERS; do
fi
for i in $(seq 0 1 $((${#users[@]}-1))); do
- local tmp_shadow="$(mktemp)"
+ tmp_shadow="$(mktemp)"
add_cleanup rm "$tmp_shadow"
echo -n "Setting ${users[$i]} password..."