Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #86 from fbelavenuto/51-virtual-machine-manager-cl…
Browse files Browse the repository at this point in the history
…uster-is-not-initialized

Loader init configfile with real MAC. Fixes many bugs with MAC
  • Loading branch information
fbelavenuto authored Aug 10, 2022
2 parents 3dc34b9 + 14eeae6 commit bddddb8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 28 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4-alpha1
0.4-alpha2
2 changes: 1 addition & 1 deletion files/board/arpl/overlayfs/opt/arpl/include/consts.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

ARPL_VERSION="0.4-alpha1"
ARPL_VERSION="0.4-alpha2"

# Define paths
TMP_PATH="/tmp"
Expand Down
27 changes: 18 additions & 9 deletions files/board/arpl/overlayfs/opt/arpl/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ if [ $NUM_PARTITIONS -ne 3 ]; then
die "Loader disk not found!"
fi

# Shows title
clear
TITLE="Welcome to Automated Redpill Loader v${ARPL_VERSION}"
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 ""

# Check partitions and ignore errors
fsck.vfat -aw ${LOADER_DISK}1 >/dev/null 2>&1 || true
fsck.ext2 -p ${LOADER_DISK}2 >/dev/null 2>&1 || true
Expand All @@ -42,6 +50,10 @@ ln -s "${CACHE_PATH}/ssh" "/etc/ssh"
rm -rf ~/.bash_history
ln -s ${CACHE_PATH}/.bash_history ~/.bash_history

# Get first MAC address
MAC=`ip link show eth0 | awk '/ether/{print$2}'`
MACF=`echo ${MAC} | sed 's/://g'`

# If user config file not exists, initialize it
if [ ! -f "${USER_CONFIG_FILE}" ]; then
touch "${USER_CONFIG_FILE}"
Expand All @@ -58,12 +70,17 @@ if [ ! -f "${USER_CONFIG_FILE}" ]; then
writeConfigKey "addons" "{}" "${USER_CONFIG_FILE}"
writeConfigKey "addons.misc" "" "${USER_CONFIG_FILE}"
writeConfigKey "addons.acpid" "" "${USER_CONFIG_FILE}"
# Initialize with real MAC
writeConfigKey "original-mac" "${MACF}" "${USER_CONFIG_FILE}"
writeConfigKey "cmdline.netif_num" "1" "${USER_CONFIG_FILE}"
writeConfigKey "cmdline.mac1" "${MACF}" "${USER_CONFIG_FILE}"
fi

# Set custom MAC if defined
MAC1=`readConfigKey "cmdline.mac1" "${USER_CONFIG_FILE}"`
if [ -n "${MAC1}" ]; then
if [ -n "${MAC1}" -a "${MAC1}" != "${MACF}" ]; then
MAC="${MAC1:0:2}:${MAC1:2:2}:${MAC1:4:2}:${MAC1:6:2}:${MAC1:8:2}:${MAC1:10:2}"
echo "Setting MAC to ${MAC}"
ip link set dev eth0 address ${MAC} >/dev/null 2>&1 && \
(/etc/init.d/S41dhcpcd restart >/dev/null 2>&1 &) || true
fi
Expand All @@ -83,14 +100,6 @@ fi
writeConfigKey "vid" ${VID} "${USER_CONFIG_FILE}"
writeConfigKey "pid" ${PID} "${USER_CONFIG_FILE}"

# Shows title
clear
TITLE="Welcome to Automated Redpill Loader v${ARPL_VERSION}"
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 ""

# Inform user
echo -en "Loader disk: \033[1;32m${LOADER_DISK}\033[0m ("
if [ "${BUS}" = "usb" ]; then
Expand Down
34 changes: 17 additions & 17 deletions files/board/arpl/overlayfs/opt/arpl/menu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -353,23 +353,23 @@ function cmdlineMenu() {
done
;;
c)
dialog --backtitle "`backtitle`" --title "User cmdline" \
--inputbox "Type a custom MAC address" 0 0 "${CMDLINE['mac1']}"\
2>${TMP_PATH}/resp
[ $? -ne 0 ] && continue
MAC1="`sed 's/://g' <"${TMP_PATH}/resp"`"
if [ -z "${MAC1}" ]; then
unset CMDLINE["mac1"]
unset CMDLINE["netif_num"]
deleteConfigKey "cmdline.mac1" "${USER_CONFIG_FILE}"
deleteConfigKey "cmdline.netif_num" "${USER_CONFIG_FILE}"
else
CMDLINE["mac1"]="${MAC1}"
CMDLINE["netif_num"]=1
writeConfigKey "cmdline.mac1" "${MAC1}" "${USER_CONFIG_FILE}"
writeConfigKey "cmdline.netif_num" "1" "${USER_CONFIG_FILE}"
fi
/etc/init.d/S30arpl-mac restart 2>&1 | dialog --backtitle "`backtitle`" \
while true; do
dialog --backtitle "`backtitle`" --title "User cmdline" \
--inputbox "Type a custom MAC address" 0 0 "${CMDLINE['mac1']}"\
2>${TMP_PATH}/resp
[ $? -ne 0 ] && continue
MAC="`<"${TMP_PATH}/resp"`"
[ -z "${MAC}" ] && MAC="`readConfigKey "original-mac" "${USER_CONFIG_FILE}"`"
MAC1="`echo "${MAC}" | sed 's/://g'`"
[ ${#MAC1} -eq 12 ] && break
dialog --backtitle "`backtitle`" --title "User cmdline" --msgbox "Invalid MAC" 0 0
done
CMDLINE["mac1"]="${MAC1}"
CMDLINE["netif_num"]=1
writeConfigKey "cmdline.mac1" "${MAC1}" "${USER_CONFIG_FILE}"
writeConfigKey "cmdline.netif_num" "1" "${USER_CONFIG_FILE}"
MAC="${MAC1:0:2}:${MAC1:2:2}:${MAC1:4:2}:${MAC1:6:2}:${MAC1:8:2}:${MAC1:10:2}"
ip link set dev eth0 address ${MAC} 2>&1 | dialog --backtitle "`backtitle`" \
--title "User cmdline" --progressbox "Changing mac" 20 70
/etc/init.d/S41dhcpcd restart 2>&1 | dialog --backtitle "`backtitle`" \
--title "User cmdline" --progressbox "Renewing IP" 20 70
Expand Down

0 comments on commit bddddb8

Please sign in to comment.