chore: shim

This commit is contained in:
7a72 2025-11-30 11:28:28 +08:00
commit 4dbafab99d
No known key found for this signature in database
GPG key ID: 000AA5D07A725A52
4 changed files with 361 additions and 227 deletions

View file

@ -1,75 +0,0 @@
name: build meta-mm
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
workflow_call:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 10
- uses: actions/setup-node@v6
with:
node-version: 22
- name: Setup zig
uses: mlugg/setup-zig@v2
with:
version: latest
- name: grab sstrip from ELFkickers
run: |
curl -L https://www.muppetlabs.com/~breadbox/pub/software/ELFkickers-3.2.tar.gz -o sstrip.tar.gz
tar xf sstrip.tar.gz
make -C ELFkickers-3.2 sstrip
cp ELFkickers-3.2/sstrip/sstrip ./strip
chmod +x strip
sudo mv strip /usr/bin/strip
- name: Build
run: |
cd webui
pnpm i
pnpm build
cd ..
bash build.sh --release
cd build
artifact_name=$(basename meta-*release.zip .zip)
unzip "$artifact_name".zip
mv "$artifact_name".zip "${artifact_name/release/ci}".zip
echo "ARTIFACT_NAME=${artifact_name/release/ci}" >> $GITHUB_ENV
- name: Notify Telegram
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
run: |
TAG_NAME=${GITHUB_REF##*/}
CAPTION="*CI ${TAG_NAME}*"
RELEASE_FILE=$(find build -maxdepth 1 -type f -name "meta*ci.zip")
curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendDocument" \
-F chat_id="${TELEGRAM_CHAT_ID}" \
-F parse_mode="Markdown" \
-F caption="$CAPTION" \
-F document=@"${RELEASE_FILE}"
rm build/{*.zip,*.json,*.md}
- name: Upload artifact
uses: actions/upload-artifact@v5
with:
name: ${{ env.ARTIFACT_NAME }}
path: build

View file

@ -1,85 +0,0 @@
name: Release
on:
push:
tags:
- "v*.*.*"
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repo
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 10
- uses: actions/setup-node@v6
with:
node-version: 22
- name: Setup zig
uses: mlugg/setup-zig@v2
with:
version: latest
- name: grab sstrip from ELFkickers
run: |
curl -L https://www.muppetlabs.com/~breadbox/pub/software/ELFkickers-3.2.tar.gz -o sstrip.tar.gz
tar xf sstrip.tar.gz
make -C ELFkickers-3.2 sstrip
cp ELFkickers-3.2/sstrip/sstrip ./strip
chmod +x strip
sudo mv strip /usr/bin/strip
- name: Build
run: |
cd webui
pnpm i
pnpm build
cd ..
bash build.sh --release
- name: Release
uses: softprops/action-gh-release@v2
with:
body_path: build/changelog.md
files: |
build/*.zip
- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Switch to public branch and push
run: |
git fetch origin
git switch public
cat build/version.json > version.json
cat build/changelog.md > changelog.md
git add version.json changelog.md
git commit -m "[skip ci] Update build files"
git push origin public
- name: Notify Telegram
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
run: |
TAG_NAME=${GITHUB_REF##*/}
CAPTION="*[Release ${TAG_NAME}](https://magic-mount.zrlab.org/changelog)*"
RELEASE_FILE=$(find build -maxdepth 1 -type f -name "meta*release.zip")
curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendDocument" \
-F chat_id="${TELEGRAM_CHAT_ID}" \
-F parse_mode="Markdown" \
-F caption="$CAPTION" \
-F document=@"${RELEASE_FILE}"

290
build.sh
View file

@ -11,6 +11,7 @@ BASE_URL="https://magic-mount.zrlab.org/download"
UPDATE_JSON_URL="https://magic-mount.zrlab.org/version"
CHANGELOG_URL="https://magic-mount.zrlab.org/changelog"
MODULE_ID="org.zrlab.magic_mount"
SHIM_ID="meta-mm"
# Build state
BUILD_TYPES=()
@ -18,6 +19,7 @@ VERSION=""
VERSION_FULL=""
GIT_COMMIT=""
TEMP_DIRS=()
BUILD_SHIM=false
# Logging functions
log_info() { echo -e "${GREEN}$*${NC}" >&2; }
@ -31,6 +33,7 @@ cleanup() {
log_warn "Cleaning up temporary directories..."
# Clean up other temp directories
for dir in "${TEMP_DIRS[@]}"; do
if [ -d "$dir" ]; then
rm -rf "$dir"
@ -56,16 +59,23 @@ usage() {
Usage: $0 [OPTIONS]
OPTIONS:
--release Build release version only
--debug Build debug version only
--release Build release version
--debug Build debug version
--shim Build shim versions (creates both normal and shim variants)
-h, --help Show this help message
(no option) Build both versions
(no option) Build both release and debug versions
When --shim is combined with --release or --debug, both normal and shim
versions will be built, sharing binaries for efficiency.
Version is automatically obtained from git tags.
EXAMPLES:
$0 # Build both release and debug
$0 --release # Build release only
$0 # Build release and debug (normal)
$0 --release # Build release only (normal)
$0 --release --shim # Build release normal + shim
$0 --debug --shim # Build debug normal + shim
$0 --shim # Build both types, each with normal + shim
EOF
exit 1
}
@ -74,8 +84,9 @@ EOF
parse_args() {
while [[ $# -gt 0 ]]; do
case $1 in
--release) BUILD_TYPES+=("release"); shift ;;
--debug) BUILD_TYPES+=("debug"); shift ;;
-r|--release) BUILD_TYPES+=("release"); shift ;;
-d|--debug) BUILD_TYPES+=("debug"); shift ;;
-s|--shim) BUILD_SHIM=true; shift ;;
-h|--help) usage ;;
*) log_error "Unknown parameter: $1"; usage ;;
esac
@ -189,7 +200,7 @@ EOF
build_binaries() {
local build_type=$1
log_step 2 8 "Building binaries ($build_type)"
log_step 2 9 "Building binaries ($build_type)"
cd src || return 1
make clean > /dev/null 2>&1
@ -209,8 +220,19 @@ configure_module() {
local build_dir=$1
local build_type=$2
local version_code=$3
local is_shim=${4:-false} # Optional parameter, defaults to false
log_step 3 8 "Configuring module files"
# Determine module ID and metamodule value based on variant type
local module_id_to_use="$MODULE_ID"
local metamodule_value="1"
if [ "$is_shim" = true ]; then
module_id_to_use="$SHIM_ID"
metamodule_value="0"
log_info " Configuring shim variant (ID: $module_id_to_use, metamodule: $metamodule_value)"
else
log_info " Configuring normal variant (ID: $module_id_to_use, metamodule: $metamodule_value)"
fi
# Configure module.prop
local module_prop="$build_dir/module.prop"
@ -221,19 +243,20 @@ configure_module() {
local module_version="$VERSION_FULL"
sed -i "s|^id=.*|id=$MODULE_ID|" "$module_prop"
sed -i "s|^id=.*|id=$module_id_to_use|" "$module_prop"
sed -i "s|^version=.*|version=$module_version|" "$module_prop"
sed -i "s|^versionCode=.*|versionCode=$version_code|" "$module_prop"
sed -i "s|^updateJson=.*|updateJson=$UPDATE_JSON_URL|" "$module_prop"
sed -i "s|^metamodule=.*|metamodule=$metamodule_value|" "$module_prop"
log_info "module.prop configured ($module_version, code $version_code)"
log_info " module.prop configured ($module_version, code $version_code)"
}
# Generate checksums for all files
generate_checksums() {
local build_dir=$1
log_step 5 8 "Generating checksums"
log_info " Generating checksums"
local checksum_file="$build_dir/checksums"
@ -248,14 +271,14 @@ generate_checksums() {
fi
local count=$(wc -l < "$checksum_file")
log_info "Generated checksums for $count files"
log_info " Generated checksums for $count files"
}
# Normalize timestamps for reproducible builds
normalize_timestamps() {
local build_dir=$1
log_step 6 8 "Normalizing timestamps for reproducible build"
log_info " Normalizing timestamps"
# Use git commit timestamp for reproducibility
local git_timestamp=$(git log -1 --format=%ct 2>/dev/null)
@ -272,13 +295,6 @@ normalize_timestamps() {
log_error "Failed to convert git timestamp"
return 1
fi
# Show human-readable commit time
local human_time=$(date -d "@$git_timestamp" '+%Y-%m-%d %H:%M:%S %Z' 2>/dev/null)
if [ -z "$human_time" ]; then
human_time=$(date -r "$git_timestamp" '+%Y-%m-%d %H:%M:%S %Z' 2>/dev/null)
fi
log_info "Using git commit time: $human_time"
else
timestamp=$(date '+%Y%m%d%H%M.%S')
log_warn "Git timestamp not available, using current time"
@ -289,86 +305,190 @@ normalize_timestamps() {
return 1
fi
log_info "All timestamps normalized to: $timestamp"
log_info " Timestamps normalized"
}
# Build single type
build_single_type() {
local build_type=$1
local build_dir="build/${build_type}_temp"
local version_code=$(git rev-list --count HEAD)
local output_name="meta-magic_mount-${VERSION_FULL}-${build_type}.zip"
# Package variant
package_variant() {
local base_dir=$1
local output_name=$2
local is_shim=$3
local variant_name=$4
# Register this temp directory for cleanup
TEMP_DIRS+=("$build_dir")
TEMP_DIRS+=("src/bin")
log_info " Packaging $variant_name variant"
log_info ""
log_info "========================================"
log_info "Building $build_type version"
log_info "Version: $VERSION_FULL"
log_info "========================================"
# Clean and create build directory
rm -rf "$build_dir"
mkdir -p "$build_dir" || {
log_error "Failed to create build directory: $build_dir"
return 1
}
# Step 1: Copy template
log_step 1 8 "Copying template"
if ! cp -r template/* "$build_dir/"; then
log_error "Failed to copy template"
# Create a copy for this variant
local variant_dir="${base_dir}_${variant_name}"
if ! cp -r "$base_dir" "$variant_dir"; then
log_error "Failed to create variant directory"
return 1
fi
# Step 2: Build binaries
build_binaries "$build_type" || return 1
# Determine module ID and metamodule value
local module_id="$MODULE_ID"
local metamodule_value="1"
# Step 3: Configure module
configure_module "$build_dir" "$build_type" "$version_code" || return 1
# Step 4: Copy binaries
log_step 4 8 "Copying binaries"
if [ ! -d "src/bin" ]; then
log_error "src/bin not found"
return 1
if [ "$is_shim" = true ]; then
module_id="$SHIM_ID"
metamodule_value="0"
log_info " Configuring as shim (ID: $module_id, metamodule: $metamodule_value)"
fi
if ! cp -r src/bin "$build_dir/"; then
log_error "Failed to copy binaries"
# Configure for this module ID and metamodule setting
local module_prop="$variant_dir/module.prop"
sed -i "s|^id=.*|id=$module_id|" "$module_prop"
sed -i "s|^metamodule=.*|metamodule=$metamodule_value|" "$module_prop"
# Regenerate checksums with the new module.prop
if ! (cd "$variant_dir" && \
find . -type f ! -name "checksums" -print0 | \
LC_ALL=C sort -z | \
xargs -0 sha256sum | \
sed 's|^\./||' > checksums); then
log_error "Failed to regenerate checksums"
return 1
fi
# Step 5: Generate checksums
generate_checksums "$build_dir" || return 1
# Re-normalize timestamps
local git_timestamp=$(git log -1 --format=%ct 2>/dev/null)
if [ -n "$git_timestamp" ]; then
local timestamp=$(date -d "@$git_timestamp" '+%Y%m%d%H%M.%S' 2>/dev/null)
if [ -z "$timestamp" ]; then
timestamp=$(date -r "$git_timestamp" '+%Y%m%d%H%M.%S' 2>/dev/null)
fi
else
timestamp=$(date '+%Y%m%d%H%M.%S')
fi
find "$variant_dir" -exec touch -m -t "$timestamp" {} +
# Step 6: Normalize timestamps
normalize_timestamps "$build_dir" || return 1
# Step 7: Package
log_step 7 8 "Creating package"
if ! (cd "$build_dir" && zip -qr "../../build/$output_name" ./*); then
# Package
if ! (cd "$variant_dir" && zip -qr "../../build/$output_name" ./*); then
log_error "Failed to create package"
return 1
fi
# Step 8: Generate misc for release
if [ "$build_type" = "release" ]; then
log_step 8 8 "Generating misc"
generate_changelog
generate_update_json "$output_name" "$version_code"
else
log_step 8 8 "Skipping misc (debug build)"
fi
# Clean up variant directory
rm -rf "$variant_dir"
local size=$(du -h "build/$output_name" | cut -f1)
log_info " Created: $output_name ($size)"
}
# Build single type with variants
build_single_type() {
local build_type=$1
local build_shim=$2
local version_code=$(git rev-list --count HEAD)
# Set base directory and register for cleanup
BASE_DIR="build/${build_type}_base"
# Register other directories for cleanup
TEMP_DIRS+=("src/bin" "$BASE_DIR")
log_info ""
log_info "========================================"
if [ "$build_shim" = true ]; then
log_info "Building $build_type (normal + shim variants)"
else
log_info "Building $build_type (normal)"
fi
log_info "Version: $VERSION_FULL"
log_info "========================================"
# Clean and create build directory
rm -rf "$BASE_DIR"
mkdir -p "$BASE_DIR" || {
log_error "Failed to create build directory: $BASE_DIR"
return 1
}
# Step 1: Copy template
log_step 1 9 "Copying template"
if ! cp -r template/* "$BASE_DIR/"; then
log_error "Failed to copy template"
return 1
fi
# Step 2: Build binaries (shared)
build_binaries "$build_type" || return 1
# Step 3: Initial configuration (will be overridden per variant)
log_step 3 9 "Configuring base module files"
configure_module "$BASE_DIR" "$build_type" "$version_code" false || return 1
# Step 4: Copy binaries (shared)
log_step 4 9 "Copying binaries"
if [ ! -d "src/bin" ]; then
log_error "src/bin not found"
return 1
fi
if ! cp -r src/bin "$BASE_DIR/"; then
log_error "Failed to copy binaries"
return 1
fi
# Step 5: Generate checksums (will be regenerated per variant)
log_step 5 9 "Generating base checksums"
generate_checksums "$BASE_DIR" || return 1
# Step 6: Normalize timestamps (will be reapplied per variant)
log_step 6 9 "Normalizing timestamps"
normalize_timestamps "$BASE_DIR" || return 1
# Step 7: Package variants
log_step 7 9 "Packaging variants"
local built_artifacts=()
# Normal variant
local normal_output="meta-magic_mount-${VERSION_FULL}-${build_type}.zip"
if package_variant "$BASE_DIR" "$normal_output" false "normal"; then
built_artifacts+=("$normal_output")
else
log_error "Failed to package normal variant"
return 1
fi
# Shim variant (if requested)
if [ "$build_shim" = true ]; then
local shim_output="meta-magic_mount-${VERSION_FULL}-${build_type}-shim.zip"
if package_variant "$BASE_DIR" "$shim_output" true "shim"; then
built_artifacts+=("$shim_output")
else
log_error "Failed to package shim variant"
return 1
fi
fi
# Step 8: Generate misc files
log_step 8 9 "Generating metadata files"
if [ "$build_type" = "release" ]; then
# Generate changelog once (shared between variants)
generate_changelog
# Generate update JSON only for normal variant
# Shim variant doesn't need separate version.json since it converts to normal module after installation
generate_update_json "$normal_output" "$version_code"
log_info " Generated version.json (normal variant only)"
else
log_info " Skipped (debug build)"
fi
log_step 9 9 "Done. "
log_info ""
log_info "========================================="
log_info "Build complete: $output_name ($size)"
log_info "Build complete for $build_type:"
for artifact in "${built_artifacts[@]}"; do
local size=$(du -h "build/$artifact" | cut -f1)
log_info " - $artifact ($size)"
done
log_info "========================================="
artifact="$output_name"
# Return artifacts via global variable
artifacts=("${built_artifacts[@]}")
}
# Main build process
@ -383,12 +503,12 @@ main() {
# Build each type
local success=0
local failed=0
local built_files=()
local all_built_files=()
for build_type in "${BUILD_TYPES[@]}"; do
if build_single_type "$build_type"; then
if build_single_type "$build_type" "$BUILD_SHIM"; then
((success++))
built_files+=("$artifact")
all_built_files+=("${artifacts[@]}")
else
((failed++))
log_error "Failed to build $build_type"
@ -402,14 +522,20 @@ main() {
log_info "========================================"
log_info "Version: $VERSION_FULL"
log_info "Commit: $GIT_COMMIT"
log_info "Build mode: $([ "$BUILD_SHIM" = true ] && echo "NORMAL + SHIM" || echo "NORMAL ONLY")"
log_info "Module IDs: $MODULE_ID$([ "$BUILD_SHIM" = true ] && echo ", $SHIM_ID" || echo "")"
log_info "Success: $success | Failed: $failed"
log_info "----------------------------------------"
log_info "Generated files:"
# Show metadata files
if [[ " ${BUILD_TYPES[*]} " =~ " release " ]]; then
log_info " build/changelog.md"
log_info " build/version.json"
fi
for file in "${built_files[@]}"; do
# Show all artifacts
for file in "${all_built_files[@]}"; do
local size=$(du -h "build/$file" | cut -f1)
log_info " build/$file ($size)"
done

View file

@ -6,6 +6,7 @@ SKIPUNZIP=1
module_id="org.zrlab.magic_mount"
module_data_dir="/data/adb/magic_mount"
metamodule_link="/data/adb/metamodule"
module_shim_id="meta-mm"
ui_print "- File integrity check"
@ -117,8 +118,7 @@ module_dirs="
# Copy regular module files
for f in ${module_files}; do
if [ ! -f "$TMPDIR/$f" ]; then
ui_print " ! Warning: $f not found, skipping"
continue
abort " ! Failed: $f not found"
fi
if ! cp "$TMPDIR/$f" "$MODPATH/$f"; then
@ -132,8 +132,7 @@ done
# Copy executable scripts
for f in ${executable_scripts}; do
if [ ! -f "$TMPDIR/$f" ]; then
ui_print " ! Warning: $f not found, skipping"
continue
abort " ! Failed: $f not found"
fi
if ! cp "$TMPDIR/$f" "$MODPATH/$f"; then
@ -180,6 +179,77 @@ else
ui_print " ℹ Existing configuration preserved"
fi
# Detect current installation type
ui_print "- Detecting installation type"
current_modid=$(basename "$MODPATH")
modules_dir="/data/adb/modules"
modules_update_dir="/data/adb/modules_update"
if [ "$current_modid" = "$module_shim_id" ]; then
ui_print " ⚠ Shim installation detected"
INSTALL_TYPE="shim"
elif [ "$current_modid" = "$module_id" ]; then
ui_print " ✓ Normal installation detected"
INSTALL_TYPE="normal"
else
ui_print " ! Unknown installation type: $current_modid"
INSTALL_TYPE="unknown"
fi
# Handle shim cleanup for normal installations
if [ "$INSTALL_TYPE" = "normal" ]; then
ui_print "- Checking for existing shim installation"
shim_removed=0
# Check and remove shim from modules directory
if [ -d "$modules_dir/$module_shim_id" ]; then
ui_print " Found shim in modules directory"
# Verify it's actually a shim by checking module.prop
if [ -f "$modules_dir/$module_shim_id/module.prop" ]; then
shim_real_id=$(grep "^id=" "$modules_dir/$module_shim_id/module.prop" | cut -d'=' -f2)
if [ "$shim_real_id" = "$module_id" ]; then
ui_print " Removing shim installation: $module_shim_id"
rm -rf "$modules_dir/$module_shim_id"
shim_removed=1
fi
else
# No valid module.prop, safe to remove
ui_print " Removing invalid shim directory"
rm -rf "$modules_dir/$module_shim_id"
shim_removed=1
fi
fi
# Check and remove shim from modules_update directory
if [ -d "$modules_update_dir/$module_shim_id" ]; then
ui_print " Found shim in modules_update directory"
if [ -f "$modules_update_dir/$module_shim_id/module.prop" ]; then
shim_real_id=$(grep "^id=" "$modules_update_dir/$module_shim_id/module.prop" | cut -d'=' -f2)
if [ "$shim_real_id" = "$module_id" ]; then
ui_print " Removing shim from updates: $module_shim_id"
rm -rf "$modules_update_dir/$module_shim_id"
shim_removed=1
fi
else
ui_print " Removing invalid shim from updates"
rm -rf "$modules_update_dir/$module_shim_id"
shim_removed=1
fi
fi
if [ $shim_removed -eq 1 ]; then
ui_print " ✓ Shim cleanup completed"
else
ui_print " ℹ No shim installation found"
fi
fi
ui_print "- Managing metamodule status"
# Check if metamodule symlink exists and points to a different module
@ -189,8 +259,9 @@ if [ -L "$metamodule_link" ]; then
if [ -n "$metamodule_path" ]; then
metamodule_id=$(basename "$metamodule_path")
if [ "$metamodule_id" != "$module_id" ]; then
ui_print " Switching from $metamodule_id to $module_id"
# Consider both real module_id and shim_id as valid for this module
if [ "$metamodule_id" != "$module_id" ] && [ "$metamodule_id" != "$module_shim_id" ]; then
ui_print " Switching from $metamodule_id to $current_modid"
# Mark old metamodule for removal
if [ -f "$metamodule_path/module.prop" ]; then
@ -200,6 +271,10 @@ if [ -L "$metamodule_link" ]; then
# Remove old symlink
rm -f "$metamodule_link"
elif [ "$metamodule_id" = "$module_shim_id" ] && [ "$current_modid" = "$module_id" ]; then
# Update link from shim to normal
ui_print " Updating metamodule link from shim to normal"
rm -f "$metamodule_link"
else
ui_print " ✓ Already active metamodule"
fi
@ -212,22 +287,115 @@ fi
# Create new metamodule symlink if needed
if [ ! -e "$metamodule_link" ]; then
if ln -sf "/data/adb/modules/$module_id" "$metamodule_link"; then
if ln -sf "$modules_dir/$current_modid" "$metamodule_link"; then
ui_print " ✓ Activated as metamodule"
else
ui_print " ! Warning: Failed to create metamodule link"
fi
fi
ui_print "- Finalizing installation"
# Shim-specific post-install setup
if [ "$INSTALL_TYPE" = "shim" ]; then
ui_print "- Setting up shim migration"
ui_print " Scheduling module ID migration to $module_id"
# Create a post-install script to handle the rename
cat > "$MODPATH/post-fs-data.sh" << 'EOF'
#!/system/bin/sh
module_id="org.zrlab.magic_mount"
module_shim_id="meta-mm"
metamodule_link="/data/adb/metamodule"
modules_dir="/data/adb/modules"
# Function to safely rename module directory
rename_module() {
local source_dir="$1"
local source_id="$2"
local target_id="$3"
if [ -d "$source_dir/$source_id" ]; then
# Check if target already exists
if [ -e "$source_dir/$target_id" ]; then
# Target exists, check if it's valid
if [ -f "$source_dir/$target_id/module.prop" ]; then
target_real_id=$(grep "^id=" "$source_dir/$target_id/module.prop" | cut -d'=' -f2)
if [ "$target_real_id" = "$module_id" ]; then
# Valid target module exists, remove shim
rm -rf "$source_dir/$source_id"
return 0
fi
fi
# Invalid target, remove it
rm -rf "$source_dir/$target_id"
fi
# Perform rename
if mv "$source_dir/$source_id" "$source_dir/$target_id"; then
return 0
else
return 1
fi
fi
return 2 # Source doesn't exist
}
# Only run once
if [ -f "$modules_dir/$module_id/.shim_migrated" ]; then
exit 0
fi
# Also check if we're still in shim directory
if [ ! -d "$modules_dir/$module_shim_id" ]; then
exit 0
fi
# Rename in modules directory
if rename_module "$modules_dir" "$module_shim_id" "$module_id"; then
# Update metamodule link if it points to shim
if [ -L "$metamodule_link" ]; then
link_target=$(readlink "$metamodule_link")
if [ "$link_target" = "$modules_dir/$module_shim_id" ] || \
[ "$(basename "$(realpath "$metamodule_link" 2>/dev/null)")" = "$module_shim_id" ]; then
rm -f "$metamodule_link"
ln -sf "$modules_dir/$module_id" "$metamodule_link"
fi
fi
# Mark migration as complete
touch "$modules_dir/$module_id/.shim_migrated" 2>/dev/null
fi
# Remove this script after execution
rm -f "$modules_dir/$module_id/post-fs-data.sh"
exit 0
EOF
chmod 755 "$MODPATH/post-fs-data.sh"
ui_print " ✓ Post-install migration script created"
ui_print " ℹ Module will be renamed on next boot"
fi
ui_print ""
ui_print "========================================="
ui_print " Magic Mount Installation Information"
ui_print "========================================="
ui_print " Module ID: $module_id"
ui_print " Install Dir: $current_modid"
if [ "$INSTALL_TYPE" = "shim" ]; then
ui_print " Install Type: Shim (will migrate on reboot)"
else
ui_print " Install Type: Normal"
fi
ui_print " Architecture: $ABI"
ui_print " Binary: $ARCH_BINARY"
ui_print " Data directory: $module_data_dir"
ui_print "========================================="
ui_print ""
ui_print "- Finalizing installation"