Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.10)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# Set the project name and language
Expand Down
42 changes: 31 additions & 11 deletions cli/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <fcntl.h>
#include <pwd.h>
#include <iostream>
#include <filesystem>

#include "incbin.h"
#include "chown.h"
Expand All @@ -50,8 +51,11 @@

INCTXT(PATCHED_START_SCRIPT, "../../scripts/posix/start.sh");

#define START_SCRIPT_PATH "/usr/bin/steam"
// #define START_SCRIPT_PATH "/usr/bin/steam"
#define BACKUP_PATH "/usr/bin/steam.millennium.bak"
const char * start_script_path = "/usr/bin/steam";
const char * start_script_usrlocal_path = "/usr/local/bin/steam";
const char * start_script_available_path;

void check_sudo() {
if (getuid() != 0) {
Expand All @@ -62,10 +66,11 @@ void check_sudo() {

const void patch_steam()
{
start_script_available_path = start_script_path;
std::cout << "Resolving permissions...\n";
check_sudo();

if (access(START_SCRIPT_PATH, F_OK) == -1)
if (access(start_script_path, F_OK) == -1)
{
std::cerr << "Error: Steam start script not found. Ensure you're Steam installation is not flatpak, or snap.\n";
return;
Expand All @@ -74,8 +79,23 @@ const void patch_steam()
if (access(BACKUP_PATH, F_OK) == -1)
{
std::cout << "Backing up the original start script...\n";
rename(START_SCRIPT_PATH, BACKUP_PATH);
std::cout << "Backup made at: " << BACKUP_PATH << "\n";
rename(start_script_path, BACKUP_PATH);
if (access(BACKUP_PATH, F_OK) == -1) {
std::cout << "Backing up the original start script failed.\n";
std::cout << "Attemting to create copy in /usr/local/bin...\n";
std::filesystem::copy(start_script_path, start_script_usrlocal_path);
if (access(start_script_usrlocal_path, F_OK) == -1) {
std::cout << "Copying to /usr/local/bin failed, exiting.\n";
return;
}
else {
std::cout << "Copy created at: " << start_script_usrlocal_path << "\n";
start_script_available_path = start_script_usrlocal_path;
}
}
else {
std::cout << "Copy created at: " << start_script_path << "\n";
}
}
else
{
Expand All @@ -86,15 +106,15 @@ const void patch_steam()
if (response[0] == 'y' || response[0] == 'Y')
{
remove(BACKUP_PATH);
rename(START_SCRIPT_PATH, BACKUP_PATH);
rename(start_script_path, BACKUP_PATH);
}
else {
std::cout << "Skipping backup...\n";
}
}

std::cout << "Patching the Steam start script...\n";
FILE *file = fopen(START_SCRIPT_PATH, "w");
FILE *file = fopen(start_script_available_path, "w");
if (!file)
{
perror("Failed to open script for writing");
Expand All @@ -103,22 +123,22 @@ const void patch_steam()
fputs(PATCHED_START_SCRIPT_data, file);
fclose(file);

chmod(START_SCRIPT_PATH, 0555);
std::cout << "Successfully wrote: " << START_SCRIPT_PATH << "\n";
chmod(start_script_available_path, 0555);
std::cout << "Successfully wrote: " << start_script_available_path << "\n";
return;
};

const void check_patch_status()
{
check_sudo();

if (access(START_SCRIPT_PATH, F_OK) == -1)
if (access(start_script_path, F_OK) == -1)
{
std::cerr << "Steam start script not found.\n";
return;
}

FILE *file = fopen(START_SCRIPT_PATH, "r");
FILE *file = fopen(start_script_path, "r");
if (!file)
{
perror("Failed to open script");
Expand Down Expand Up @@ -150,7 +170,7 @@ const void check_patch_status()

int is_patched = (strcmp(buffer, PATCHED_START_SCRIPT_data) == 0);
std::cout << "\n\033[32m>\e[0m \033[1mPatched:\033[0m \033[" << (is_patched ? 92 : 91) << "m" << (is_patched ? "yes" : "no") << "\033[0m\n";
std::cout << "\033[32m>\e[0m \033[1mPath:\033[0m \033[92m" << START_SCRIPT_PATH << "\033[0m\n";
std::cout << "\033[32m>\e[0m \033[1mPath:\033[0m \033[92m" << start_script_path << "\033[0m\n";

free(buffer);
};
Expand Down
28 changes: 25 additions & 3 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ if ! is_root; then
exit 1
fi

if [ -w /usr/bin/steam ] ; then
log "/usr/bin/steam is writable."
else
log "/usr/bin/steam is NOT writable."
if [ -w /usr/local/bin/ ] ; then
log "/usr/local/bin is writable. Install location will be /usr/local/bin."
USE_USRLOCAL=1
else
log "${BOLD_RED}!!${RESET} /usr/local/bin is not writable. Exiting."
exit 2
fi
fi

case $(uname -sm) in
"Linux x86_64") target="linux-x86_64" ;;
*) log "${BOLD_RED}!!${RESET} Unsupported platform $(uname -sm). x86_64 is the only available platform."; exit ;;
Expand Down Expand Up @@ -89,13 +102,22 @@ tar xzf "$tar" -C "$extract_path"
folder_size=$(du -sb "$extract_path" | awk '{print $1}' | numfmt --to=iec-i --suffix=B --padding=7 | sed 's/\([0-9]\)\([A-Za-z]\)/\1 \2/')
log "\nTotal Install Size: $folder_size"

cp -r "$extract_path"/* / || true
if ! [[ $USE_USRLOCAL ]] ; then
# Default installation method with writable /usr/bin.
cp -r "$extract_path"/* / || true
chmod +x /usr/bin/millennium
else
# Alternate installation method with writable /usr/local/bin.
cp -r "$extract_path"/usr/* /usr/local/
cp -r "$extract_path"/opt/* /opt/
chmod +x /usr/local/bin/millennium
fi

chmod +x /usr/bin/millennium
# This step is the same on both methods
chmod +x /opt/python-i686-3.11.8/bin/python3.11

log "cleaning up packages..."
rm -rf "$millennium_install"
log "done."

log "\n${BOLD_PINK}::${RESET} To get started, see https://docs.steambrew.app/users/installing#post-installation.\n Your base installation of Steam has not been modified, this is simply an extension."
log "\n${BOLD_PINK}::${RESET} To get started, see https://docs.steambrew.app/users/installing#post-installation.\n Your base installation of Steam has not been modified, this is simply an extension."
4 changes: 2 additions & 2 deletions scripts/posix/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ export OPENSSL_CONF=/dev/null

# Only set LD_PRELOAD if MILLENNIUM_RUNTIME_PATH is not set
if [ -z "${MILLENNIUM_RUNTIME_PATH}" ]; then
export LD_PRELOAD="/usr/lib/millennium/libmillennium_x86.so${LD_PRELOAD:+:$LD_PRELOAD}" # preload Millennium into Steam
export LD_PRELOAD="/usr/lib/millennium/libmillennium_x86.so:/usr/local/lib/millennium/libmillennium_x86.so${LD_PRELOAD:+:$LD_PRELOAD}" # preload Millennium into Steam
else
export LD_PRELOAD="${MILLENNIUM_RUNTIME_PATH}${LD_PRELOAD:+:$LD_PRELOAD}" # use custom LD_PRELOAD if set
fi

export LD_LIBRARY_PATH="/usr/lib/millennium/${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
export LD_LIBRARY_PATH="/usr/lib/millennium/:/usr/local/lib/millennium/${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"

# Millennium hooks __libc_start_main to initialize itself, which is a function that is called before main.
# Besides that, Millennium does not alter Steam memory and runs completely disjoint.
Expand Down
20 changes: 17 additions & 3 deletions src/sys/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <stdlib.h>
#include <string>
#include <unistd.h>
#include <filesystem>

#if defined(__linux__) || defined(__APPLE__)
extern char** environ;
Expand Down Expand Up @@ -157,7 +158,11 @@ const void SetupEnvironmentVariables()
#ifdef _NIX_OS
const auto shimsPath = fmt::format("{}/share/millennium/shims", __NIX_SHIMS_PATH);
#else
const auto shimsPath = "/usr/share/millennium/shims";
const char * shimsPath;
if (std::filesystem::exists("/usr/local/bin/millennium"))
shimsPath = "/usr/local/share/millennium/shims";
else
shimsPath = "/usr/share/millennium/shims";
#endif
#elif __APPLE__
const auto shimsPath = "/usr/local/share/millennium/shims";
Expand All @@ -174,7 +179,11 @@ const void SetupEnvironmentVariables()
#ifdef _NIX_OS
const auto assetsPath = fmt::format("{}/share/millennium/assets", __NIX_ASSETS_PATH);
#else
const auto assetsPath = "/usr/share/millennium/assets";
const char * assetsPath;
if (std::filesystem::exists("/usr/local/bin/millennium"))
assetsPath = "/usr/local/share/millennium/assets";
else
assetsPath = "/usr/share/millennium/assets";
#endif
#elif __APPLE__
const auto assetsPath = "/usr/local/share/millennium/assets";
Expand Down Expand Up @@ -208,14 +217,19 @@ const void SetupEnvironmentVariables()
}

const std::string customLdPreload = GetEnv("MILLENNIUM_RUNTIME_PATH");
const char * millenium_runtime_path;
if (std::filesystem::exists("/usr/local/bin/millennium"))
millenium_runtime_path = "/usr/local/lib/millennium/libmillennium_x86.so";
else
millenium_runtime_path = "/usr/lib/millennium/libmillennium_x86.so";

std::map<std::string, std::string> environment_unix = {
{"OPENSSL_CONF", "/dev/null"},
{"MILLENNIUM_RUNTIME_PATH", customLdPreload != "" ? customLdPreload :
#ifdef _NIX_OS
fmt::format("{}/lib/millennium/libMillennium_x86.so", __NIX_SELF_PATH)
#else
"/usr/lib/millennium/libmillennium_x86.so"
millenium_runtime_path
#endif
},

Expand Down