Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
wjz304 committed Aug 20, 2023
1 parent fa21e70 commit a83532f
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 93 deletions.
22 changes: 11 additions & 11 deletions files/board/arpl/overlayfs/opt/arpl/include/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,28 @@ function dieLog() {
###############################################################################
# Generate a number with 6 digits from 1 to 30000
function random() {
printf "%06d" $(($RANDOM % 30000 + 1))
printf "%06d" $((${RANDOM} % 30000 + 1))
}

###############################################################################
# Generate a hexa number from 0x00 to 0xFF
function randomhex() {
printf "&02X" "$(($RANDOM % 255 + 1))"
printf "&02X" "$((${RANDOM} % 255 + 1))"
}

###############################################################################
# Generate a random letter
function generateRandomLetter() {
for i in A B C D E F G H J K L M N P Q R S T V W X Y Z; do
echo $i
echo ${i}
done | sort -R | tail -1
}

###############################################################################
# Generate a random digit (0-9A-Z)
function generateRandomValue() {
for i in 0 1 2 3 4 5 6 7 8 9 A B C D E F G H J K L M N P Q R S T V W X Y Z; do
echo $i
echo ${i}
done | sort -R | tail -1
}

Expand Down Expand Up @@ -118,7 +118,7 @@ function validateSerial() {
echo 0
return
fi
echo ${PREFIX} | grep -q ${S}
echo "${PREFIX}" | grep -q "${S}"
if [ $? -eq 1 ]; then
echo 0
return
Expand Down Expand Up @@ -162,19 +162,19 @@ function _get_conf_kv() {
# 3 - path
function _set_conf_kv() {
# Delete
if [ -z "$2" ]; then
sed -i "$3" -e "s/^$1=.*$//"
if [ -z "${2}" ]; then
sed -i "${3}" -e "s/^${1}=.*$//"
return $?
fi

# Replace
if grep -q "^$1=" "$3"; then
sed -i "$3" -e "s\"^$1=.*\"$1=\\\"$2\\\"\""
if grep -q "^${1}=" "${3}"; then
sed -i "${3}" -e "s\"^${1}=.*\"${1}=\\\"${2}\\\"\""
return $?
fi

# Add if doesn't exist
echo "$1=\"$2\"" >>$3
echo "${1}=\"${2}\"" >>"${3}"
}

###############################################################################
Expand All @@ -184,7 +184,7 @@ function findAndMountDSMRoot() {
[ $(mount | grep -i "${DSMROOT_PATH}" | wc -l) -gt 0 ] && return 0
dsmrootdisk="$(blkid /dev/sd* | grep -i raid | awk '{print $1 " " $4}' | grep UUID | grep sd[a-z]1 | head -1 | awk -F ":" '{print $1}')"
[ -z "${dsmrootdisk}" ] && return -1
[ $(mount | grep -i "${DSMROOT_PATH}" | wc -l) -eq 0 ] && mount -t ext4 $dsmrootdisk "${DSMROOT_PATH}"
[ $(mount | grep -i "${DSMROOT_PATH}" | wc -l) -eq 0 ] && mount -t ext4 "${dsmrootdisk}" "${DSMROOT_PATH}"
if [ $(mount | grep -i "${DSMROOT_PATH}" | wc -l) -eq 0 ]; then
echo "Failed to mount"
return -1
Expand Down
20 changes: 10 additions & 10 deletions files/board/arpl/overlayfs/opt/arpl/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ done

[ -z "${LOADER_DISK}" ] && die "$(TEXT "Loader disk not found!")"
NUM_PARTITIONS=$(blkid | grep "${LOADER_DISK}[0-9]\+" | cut -d: -f1 | wc -l)
[ $NUM_PARTITIONS -lt 3 ] && die "$(TEXT "Loader disk seems to be damaged!")"
[ $NUM_PARTITIONS -gt 3 ] && die "$(TEXT "There are multiple loader disks, please insert only one loader disk!")"
[ ${NUM_PARTITIONS} -lt 3 ] && die "$(TEXT "Loader disk seems to be damaged!")"
[ ${NUM_PARTITIONS} -gt 3 ] && die "$(TEXT "There are multiple loader disks, please insert only one loader disk!")"

# Check partitions and ignore errors
fsck.vfat -aw ${LOADER_DISK}1 >/dev/null 2>&1 || true
Expand All @@ -39,10 +39,10 @@ mount ${LOADER_DISK}3 ${CACHE_PATH} || die "$(printf "$(TEXT "Can't mount %s")"
# Shows title
clear
TITLE="$(printf "$(TEXT "Welcome to %s")" "${ARPL_TITLE}")"
printf "\033[1;44m%*s\n" $COLUMNS ""
printf "\033[1;44m%*s\033[A\n" $COLUMNS ""
printf "\033[1;32m%*s\033[0m\n" $(((${#TITLE} + $COLUMNS) / 2)) "${TITLE}"
printf "\033[1;44m%*s\033[0m\n" $COLUMNS ""
printf "\033[1;44m%*s\n" ${COLUMNS} ""
printf "\033[1;44m%*s\033[A\n" ${COLUMNS} ""
printf "\033[1;32m%*s\033[0m\n" $(((${#TITLE} + ${COLUMNS}) / 2)) "${TITLE}"
printf "\033[1;44m%*s\033[0m\n" ${COLUMNS} ""

# Move/link SSH machine keys to/from cache volume
[ ! -d "${CACHE_PATH}/ssh" ] && cp -R "/etc/ssh" "${CACHE_PATH}/ssh"
Expand Down Expand Up @@ -146,17 +146,17 @@ ENDSECTOR=$(($(fdisk -l ${LOADER_DISK} | awk '/'${LOADER_DEVICE_NAME}3'/{print$3
if [ ${SIZEOFDISK} -ne ${ENDSECTOR} ]; then
echo -e "\033[1;36m$(printf "$(TEXT "Resizing %s")" "${LOADER_DISK}3")\033[0m"
echo -e "d\n\nn\n\n\n\n\nn\nw" | fdisk "${LOADER_DISK}" >"${LOG_FILE}" 2>&1 || dieLog
resize2fs ${LOADER_DISK}3 >"${LOG_FILE}" 2>&1 || dieLog
resize2fs "${LOADER_DISK}3" >"${LOG_FILE}" 2>&1 || dieLog
fi

# Load keymap name
LAYOUT="$(readConfigKey "layout" "${USER_CONFIG_FILE}")"
KEYMAP="$(readConfigKey "keymap" "${USER_CONFIG_FILE}")"

# Loads a keymap if is valid
if [ -f /usr/share/keymaps/i386/${LAYOUT}/${KEYMAP}.map.gz ]; then
if [ -f "/usr/share/keymaps/i386/${LAYOUT}/${KEYMAP}.map.gz" ]; then
echo -e "$(TEXT "Loading keymap") \033[1;32m${LAYOUT}/${KEYMAP}\033[0m"
zcat /usr/share/keymaps/i386/${LAYOUT}/${KEYMAP}.map.gz | loadkeys
zcat "/usr/share/keymaps/i386/${LAYOUT}/${KEYMAP}.map.gz" | loadkeys
fi

# Decide if boot automatically
Expand Down Expand Up @@ -186,7 +186,7 @@ while [ ${COUNT} -lt 30 ]; do
hasConnect="true"
fi
done
if [ ${hasConnect} = "true" ]; then
if [ "${hasConnect}" = "true" ]; then
echo -en "connected.\n"
break
fi
Expand Down
Loading

0 comments on commit a83532f

Please sign in to comment.