Skip to content

Commit

Permalink
Some fixes for Ubuntu
Browse files Browse the repository at this point in the history
  • Loading branch information
T-vK committed Sep 13, 2021
1 parent c66e36f commit 4a1627a
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 23 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ Credits to [Cole Robinson](https://blog.wikichoon.com/) for giving me a lot of i
## TODO
### High prio
- Create a bootable live version of this project
- Test on Ubuntu
- Fix for Ubuntu (Fix file dependency installation)
- Document all the new features
- Create a first Beta release
- Test with an Nvidia notebook
Expand Down
14 changes: 8 additions & 6 deletions scripts/main/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@ alias buildFakeBatterySsdt="sudo '$COMMON_UTILS_SETUP_DIR/build-fake-battery-ssd
alias vbiosFinderSetup="sudo '$COMMON_UTILS_SETUP_DIR/vbios-finder-setup'"
alias lookingGlassSetup="sudo '$COMMON_UTILS_SETUP_DIR/looking-glass-setup'"
alias generateHelperIso="sudo '${MAIN_SCRIPTS_DIR}/generate-helper-iso.sh'"
alias nvidiaSetup="sudo '$DISTRO_UTILS_DIR/nvidia-setup'"
alias bumblebeeSetup="sudo '$DISTRO_UTILS_DIR/bumblebee-setup'"
alias downloadWindowsIso="$COMMON_UTILS_TOOLS_DIR/download-windows-iso"
alias createAutoStartService="'${SERVICE_MANAGER}' create-autostart-service"
alias removeAutoStartService="'${SERVICE_MANAGER}' remove-autostart-service"

mkdir -p "${THIRDPARTY_DIR}"
mkdir -p "${VM_FILES_DIR}"

if [ -f "${DISTRO_UTILS_DIR}/add-repos" ]; then
"${DISTRO_UTILS_DIR}/add-repos"
if [ -f "${DISTRO_UTILS_DIR}/pre-package-info-update" ]; then
"${DISTRO_UTILS_DIR}/pre-package-info-update"
fi

MISSING_EXECUTABLES="$(getMissingExecutables "$ALL_EXEC_DEPS")"
Expand All @@ -45,6 +43,10 @@ if [ "$MISSING_EXECUTABLES" != "" ] || [ "$MISSING_FILES" != "" ]; then
updatePkgInfo
fi

if [ -f "${DISTRO_UTILS_DIR}/pre-package-install" ]; then
"${DISTRO_UTILS_DIR}/pre-package-install"
fi

if [ "$MISSING_EXECUTABLES" != "" ]; then
echo "> Finding and installing packages containing executables that we need..."
getExecPkg "$ALL_EXEC_DEPS" # Find and install packages containing executables that we need
Expand Down Expand Up @@ -182,11 +184,11 @@ fi
if [ "$1" = "auto" ]; then
if [ "$REBOOT_REQUIRED" = true ]; then
echo "> Creating a temporary service that will run on next reboot and continue the installation..."
createAutoStartService "${PROJECT_DIR}/mbpt.sh auto"
createAutoStartService "${PROJECT_DIR}/mbpt.sh auto" "MobilePassthroughInitSetup"
echo "> Rebooting in 30 seconds... Press Ctrl+C to cancel."
sleep 30 && sudo shutdown -r 0
else
removeAutoStartService &> /dev/null
removeAutoStartService "MobilePassthroughInitSetup" &> /dev/null
echo "> No reboot required."
fi
else
Expand Down
3 changes: 2 additions & 1 deletion scripts/utils/common/libs/helpers
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ SCRIPTS_DIR="${PROJECT_DIR}/scripts"
COMMON_UTILS_PLUGINS_DIR="${COMMON_UTILS_DIR}/plugins"
COMMON_UTILS_SETUP_DIR="${COMMON_UTILS_DIR}/setup"
COMMON_UTILS_TOOLS_DIR="${COMMON_UTILS_DIR}/tools"
DISTRO_UTILS_DIR="${UTILS_DIR}/distro-specific/$("${COMMON_UTILS_TOOLS_DIR}/distro-info")"
DISTRO_UTILS_DIR="${UTILS_DIR}/distro-specific/$("${COMMON_UTILS_TOOLS_DIR}/distro-info" --exclude-version)"
DISTRO_VERSION_UTILS_DIR="${UTILS_DIR}/distro-specific/$("${COMMON_UTILS_TOOLS_DIR}/distro-info")"
MANAGER_UTILS_DIR="${UTILS_DIR}/manager-specific"
INITRAMFS_MANAGER="${MANAGER_UTILS_DIR}/initramfs/$(sudo "${COMMON_UTILS_TOOLS_DIR}/get-manager" initramfs)"
SERVICE_MANAGER="${MANAGER_UTILS_DIR}/service/$("${COMMON_UTILS_TOOLS_DIR}/get-manager" service)"
Expand Down
6 changes: 5 additions & 1 deletion scripts/utils/common/tools/distro-info
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ else
VER=$(uname -r)
fi

echo "${OS}/${VER}"
if [ "$1" = "--exclude-version" ]; then
echo "${OS}"
else
echo "${OS}/${VER}"
fi
10 changes: 7 additions & 3 deletions scripts/utils/common/tools/get-manager
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ COMMAND="$1"
if [ "$COMMAND" = "service" ]; then
if command -v "systemctl" &> /dev/null; then
echo "systemd"
elif [ -d "/etc/init.d/" ] && command -v "service" &> /dev/null; then
echo "sysvinit"
elif command -v "service" &> /dev/null; then
echo "service"
elif command -v "initctl" &> /dev/null; then
echo "initctl"
#elif [ -d "/etc/init.d/" ] && command -v "service" &> /dev/null; then
# echo "sysvinit"
else
exit 1
fi
Expand All @@ -22,7 +26,7 @@ elif [ "$COMMAND" = "initramfs" ]; then
exit 1
fi
elif [ "$COMMAND" = "kernelparams" ]; then
if [ -f "/etc/default/grub" ] && [ -f "/etc/grub2-efi.cfg" ]; then
if [ -f "/etc/default/grub" ]; then
echo "grub"
else
exit 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done

sudo add-apt-repository -y universe
sudo add-apt-repository -y universe
12 changes: 12 additions & 0 deletions scripts/utils/distro-specific/Ubuntu/pre-package-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done

alias commandAvailable="${COMMON_UTILS_TOOLS_DIR}/commands-available"

if ! commandAvailable "x86_64-w64-mingw32-g++"; then
sudo apt-get install -y g++-mingw-w64-x86-64-win32
fi

if ! commandAvailable "upx"; then
sudo apt-get install -y upx-ucl
fi
26 changes: 18 additions & 8 deletions scripts/utils/manager-specific/kernelparams/grub
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ GRUB_CFG_PATH=/etc/default/grub
COMMAND="$1" # Supported commands: add, remove, apply
PARAM="$2"

if sudo cat "$GRUB_CFG_PATH" | grep --quiet "GRUB_CMDLINE_LINUX_DEFAULT="; then
GRUB_CMDLINE_VAR="GRUB_CMDLINE_LINUX_DEFAULT"
else
GRUB_CMDLINE_VAR="GRUB_CMDLINE_LINUX"
fi

function addKernelParam() {
if ! sudo cat "$GRUB_CFG_PATH" | grep "GRUB_CMDLINE_LINUX=" | grep --quiet "$1"; then
sudo sed -i "s/^GRUB_CMDLINE_LINUX=\"/&$1 /" "$GRUB_CFG_PATH"
echo "addKernelParam: Added \"$1\" to GRUB_CMDLINE_LINUX in $GRUB_CFG_PATH"
if ! sudo cat "$GRUB_CFG_PATH" | grep "$GRUB_CMDLINE_VAR=" | grep --quiet "$1"; then
sudo sed -i "s/^$GRUB_CMDLINE_VAR=\"/&$1 /" "$GRUB_CFG_PATH"
echo "addKernelParam: Added \"$1\" to $GRUB_CMDLINE_VAR in $GRUB_CFG_PATH"
else
echo "addKernelParam: No action required. \"$1\" already exists in GRUB_CMDLINE_LINUX of $GRUB_CFG_PATH"
echo "addKernelParam: No action required. \"$1\" already exists in $GRUB_CMDLINE_VAR of $GRUB_CFG_PATH"
fi
}
function addKernelParams() {
Expand All @@ -19,11 +25,11 @@ function addKernelParams() {
done
}
function removeKernelParam() {
if sudo cat "$GRUB_CFG_PATH" | grep "GRUB_CMDLINE_LINUX=" | grep --quiet "$1"; then
if sudo cat "$GRUB_CFG_PATH" | grep "$GRUB_CMDLINE_VAR=" | grep --quiet "$1"; then
sudo sed -i "s/$1 //" "$GRUB_CFG_PATH"
echo "removeKernelParam: Removed \"$1\" from GRUB_CMDLINE_LINUX in $GRUB_CFG_PATH"
echo "removeKernelParam: Removed \"$1\" from $GRUB_CMDLINE_VAR in $GRUB_CFG_PATH"
else
echo "removeKernelParam: No action required. \"$1\" is not set in GRUB_CMDLINE_LINUX of $GRUB_CFG_PATH"
echo "removeKernelParam: No action required. \"$1\" is not set in $GRUB_CMDLINE_VAR of $GRUB_CFG_PATH"
fi
}
function removeKernelParams() {
Expand All @@ -33,7 +39,11 @@ function removeKernelParams() {
}

function applyKernelParamChanges() {
sudo sh -c 'grub2-mkconfig > /etc/grub2-efi.cfg'
if command -v update-grub &> /dev/null; then
sudo update-grub
elif [ -f "/etc/grub2-efi.cfg" ]; then
sudo sh -c 'grub2-mkconfig > /etc/grub2-efi.cfg'
fi
}

if [ "$COMMAND" = "add" ]; then
Expand Down
20 changes: 20 additions & 0 deletions scripts/utils/manager-specific/service/initctl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done
source "$PROJECT_DIR/scripts/utils/common/libs/helpers"

COMMAND="$1"
SERVICE_NAME="$2"

if [ "$COMMAND" = "create-autostart-service" ]; then
echo "Not implemented"
exit 1
elif [ "$COMMAND" = "remove-autostart-service" ]; then
echo "Not implemented"
exit 1
elif [ "$COMMAND" = "start" ]; then
sudo service start ${SERVICE_NAME} &> /dev/null
elif [ "$COMMAND" = "stop" ]; then
sudo service stop ${SERVICE_NAME} &> /dev/null
elif [ "$COMMAND" = "restart" ]; then
sudo initctl restart ${SERVICE_NAME} &> /dev/null
fi
21 changes: 21 additions & 0 deletions scripts/utils/manager-specific/service/service
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
while [[ "$PROJECT_DIR" != */MobilePassThrough ]]; do PROJECT_DIR="$(readlink -f "$(dirname "${PROJECT_DIR:-0}")")"; done
source "$PROJECT_DIR/scripts/utils/common/libs/helpers"

COMMAND="$1"
SERVICE_NAME="$2"

if [ "$COMMAND" = "create-autostart-service" ]; then
echo "Not implemented"
exit 1
elif [ "$COMMAND" = "remove-autostart-service" ]; then
echo "Not implemented"
exit 1
elif [ "$COMMAND" = "start" ]; then
sudo service ${SERVICE_NAME} start &> /dev/null
elif [ "$COMMAND" = "stop" ]; then
sudo service ${SERVICE_NAME} stop &> /dev/null
elif [ "$COMMAND" = "restart" ]; then
sudo service ${SERVICE_NAME} stop &> /dev/null
sudo service ${SERVICE_NAME} start &> /dev/null
fi
8 changes: 7 additions & 1 deletion scripts/utils/manager-specific/service/systemd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source "$PROJECT_DIR/scripts/utils/common/libs/helpers"

COMMAND="$1"

SERVICE_NAME="MobilePassthroughInitSetup"
SERVICE_NAME="$2"
if [ "$COMMAND" = "create-autostart-service" ]; then
COMMAND_TO_RUN="$2"
EXEC_START="'$GUI_TERMINAL' run-with-command '$COMMAND_TO_RUN'"
Expand All @@ -29,4 +29,10 @@ WantedBy=multi-user.target" > /etc/systemd/system/${SERVICE_NAME}.service
sudo systemctl enable ${SERVICE_NAME}.service
elif [ "$COMMAND" = "remove-autostart-service" ]; then
sudo systemctl disable ${SERVICE_NAME}.service &> /dev/null
elif [ "$COMMAND" = "start" ]; then
sudo systemctl start ${SERVICE_NAME}.service &> /dev/null
elif [ "$COMMAND" = "stop" ]; then
sudo systemctl stop ${SERVICE_NAME}.service &> /dev/null
elif [ "$COMMAND" = "restart" ]; then
sudo systemctl restart ${SERVICE_NAME}.service &> /dev/null
fi

0 comments on commit 4a1627a

Please sign in to comment.