├── .gitignore ├── rootfs ├── usr │ ├── share │ │ └── pint │ │ │ ├── handoff.conf │ │ │ └── pint.d │ │ │ ├── 10-udevd.sh │ │ │ ├── 30-dbus.sh │ │ │ └── 00-populate-dev.sh │ └── sbin │ │ ├── shmenu │ │ └── growpart ├── etc │ └── os-release ├── changelog.txt └── sbin │ └── init ├── lib ├── i386 │ ├── cgpt │ └── sfdisk ├── x86_64 │ ├── cgpt │ └── sfdisk └── aarch64 │ ├── cgpt │ └── sfdisk ├── payloads ├── badapple.gz ├── badapple.sh └── sh1mmer.sh ├── autobuild-conf.sh ├── BUILDING.md ├── autobuild.sh ├── README.md ├── update_device.sh ├── priism_builder.sh ├── priism_init.sh ├── wax_common.sh ├── priism.sh └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | *.bin 2 | *.img 3 | *.save 4 | -------------------------------------------------------------------------------- /rootfs/usr/share/pint/handoff.conf: -------------------------------------------------------------------------------- 1 | /usr/sbin/sh1mmer_main.sh 2 | -------------------------------------------------------------------------------- /lib/i386/cgpt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmb9/Priism/HEAD/lib/i386/cgpt -------------------------------------------------------------------------------- /lib/i386/sfdisk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmb9/Priism/HEAD/lib/i386/sfdisk -------------------------------------------------------------------------------- /lib/x86_64/cgpt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmb9/Priism/HEAD/lib/x86_64/cgpt -------------------------------------------------------------------------------- /lib/aarch64/cgpt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmb9/Priism/HEAD/lib/aarch64/cgpt -------------------------------------------------------------------------------- /lib/aarch64/sfdisk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmb9/Priism/HEAD/lib/aarch64/sfdisk -------------------------------------------------------------------------------- /lib/x86_64/sfdisk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmb9/Priism/HEAD/lib/x86_64/sfdisk -------------------------------------------------------------------------------- /payloads/badapple.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmb9/Priism/HEAD/payloads/badapple.gz -------------------------------------------------------------------------------- /rootfs/etc/os-release: -------------------------------------------------------------------------------- 1 | NAME="Priism" 2 | PRETTY_NAME"Priism" 3 | ID=priism 4 | BUILD_ID="v2.0 stable" 5 | -------------------------------------------------------------------------------- /payloads/badapple.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Decompressing BadApple..." 3 | gunzip /mnt/priism/payloads/badapple.gz -c 2&> /tmp/badapple.sh 4 | clear 5 | . /tmp/badapple.sh 6 | clear 7 | -------------------------------------------------------------------------------- /autobuild-conf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ $- == *i* ]]; then 4 | echo "This file is meant to be sourced." 5 | return 1 6 | fi 7 | 8 | shim_directory="SHIMS~-NOT~-SET" 9 | 10 | -------------------------------------------------------------------------------- /rootfs/usr/share/pint/pint.d/10-udevd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source /etc/profile 4 | echo "Starting udevd..." 5 | /sbin/udevd --daemon || : 6 | udevadm trigger || : 7 | udevadm settle || : 8 | echo "Done." 9 | -------------------------------------------------------------------------------- /rootfs/usr/share/pint/pint.d/30-dbus.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source /etc/profile 4 | 5 | echo "Starting dbus..." 6 | mkdir -p /run/dbus 7 | mkdir -p /var/lib/dbus 8 | chown messagebus:messagebus /run/dbus 9 | 10 | if [ ! -e /var/run ]; then 11 | ln -s /run /var/run # Lazy. 12 | fi 13 | 14 | rm -f /var/lib/dbus/machine-id 15 | dbus-uuidgen --ensure 16 | 17 | # dbus-daemon --system --fork 18 | 19 | -------------------------------------------------------------------------------- /payloads/sh1mmer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo -e "${COLOR_YELLOW_B}You will not be able to return to Priism again in this session once you do this!" 3 | read -p "Press 'y' to continue." -n 1 -r 4 | echo 5 | if [[ $REPLY =~ ^[Yy]$ ]] 6 | then 7 | cp /usr/sbin/sh1mmer_main_old.sh /usr/sbin/sh1mmer_main.sh 8 | exec /sbin/init 9 | fail "Failed to execute /sbin/init! Somehow..." 10 | else 11 | echo "Cancelled." 12 | fi 13 | -------------------------------------------------------------------------------- /rootfs/usr/share/pint/pint.d/00-populate-dev.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source /etc/environment 4 | 5 | echo "Populating /dev, /proc, /sys..." 6 | 7 | mount -n -t proc -o nodev,noexec,nosuid proc /proc 8 | mount -n -t sysfs -o nodev,noexec,nosuid sysfs /sys 9 | mount -t tmpfs tmp /tmp 10 | 11 | mount -t devtmpfs -o mode=0755,nosuid devtmpfs /dev 12 | ln -sf /proc/self/fd /dev/fd || : 13 | ln -sf fd/0 /dev/stdin || : 14 | ln -sf fd/1 /dev/stdout || : 15 | ln -sf fd/2 /dev/stderr || : 16 | 17 | mkdir -p /dev/pts 18 | mount -n -t devpts -o noexec,nosuid devpts /dev/pts || : 19 | 20 | mount -n -t debugfs debugfs /sys/kernel/debug 21 | 22 | echo "Done." 23 | -------------------------------------------------------------------------------- /BUILDING.md: -------------------------------------------------------------------------------- 1 | # Building Priism 2 | ``sudo bash priism_builder.sh image.bin`` 3 | 4 | ``image.bin`` MUST be a SH1MMER Legacy image on a version newer than February 2024. 5 | 6 | # Using Priism 7 | 8 | After flashing your USB, boot it so that Priism can resize the images partition. For instructions on how to add recovery images, press ``i``.
9 | If the drive is empty, it will show you where to get recovery images, and how to mount the images partition on your computer. 10 | 11 | # Bug reporting 12 | Briefly describe any errors you recieve, then rerun the builder with ``sudo bash -x priism_builder.sh image.bin``. This will help me narrow down the issue. 13 | 14 | Further instructions will be added later. 15 | -------------------------------------------------------------------------------- /autobuild.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source autobuild-conf.sh 4 | 5 | if [[ $shim_directory == "SHIMS~-NOT~-SET" ]]; then 6 | while true; do 7 | echo "Where are your shims located? (Must be an ABSOLUTE path and not have quotes!)" 8 | read -p "> " choice 9 | if [[ -d $choice ]]; then 10 | sed -i 's/SHIMS~-NOT~-SET/"${choice}"/g' autobuild-conf.sh 11 | echo "Re-run this script to start building." 12 | exit 13 | else 14 | echo "Invalid directory." 15 | fi 16 | done 17 | else 18 | if [ "$EUID" -ne 0 ]; then echo "Please run as root."; exit 1; fi 19 | echo "Beginning autobuild..." 20 | for f in ${shim_directory}/* 21 | do 22 | echo "Building ${f}" 23 | bash priism_builder.sh "$f" 24 | done 25 | fi 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Priism 2 | Portable recovery image installer/shim manager based on [SH1MMER Legacy](https://github.com/MercuryWorkshop/Sh1mmer) 3 | 4 | # What works? What doesn't? 5 | Recovery :white_check_mark:
6 | Payloads menu :white_check_mark:
7 | Booting other shims :white_check_mark:
8 | 9 | # Downloads 10 | ~~[Official Prebuilts](https://dl.archima.xyz/Priism)~~
11 | [Fanqyxl's File Host*](https://dl.fanqyxl.net/Priism)
12 | 13 | Mirrors that are crossed out don't have Priism uploaded yet. 14 | Mirrors with a star next to them may not have all boards uploaded yet. 15 | 16 | # FAQ (Frequently Asked Questions) 17 |
18 | How do I update without reflashing? 19 | 20 | This requires a device to build on. 21 | 22 | 1: Copy a SH1MMER legacy (Feb 2024+) image to where you downloaded the repo 23 | 24 | 2: Run this command: ``sudo bash update_device.sh path/to/sh1mmer.bin /dev/XXX``, where ``/dev/XXX`` is your USB/sd card. You can find this with ``lsblk``. 25 |
26 | 27 |
28 | I wanna use Shimboot. How can I? 29 | 30 | Use the [respective Shimboot fork for Priism](https://github.com/xmb9/shimboot-priism). 31 |
32 |
33 | Does Priism work on Chomp? 34 | 35 | Priism 2.0 was developed entirely on Chomp! 36 |
37 | 38 | # Credits 39 | - [xmb9](https://discord.com/users/988950574387068968) - Pioneering the creation of this tool 40 | - [Mercury Workshop](https://mercurywork.shop) - Developing SH1MMER 41 | - [OlyB](https://discord.com/users/476169716998733834) - Help with adapting wax to Priism and PID1 42 | - [kxtzownsu](https://discord.com/users/952792525637312552) - Help with `sed` syntax 43 | - [simpansoftware](https://discord.com/users/1001820177731686500) - Testing Priism and building the very first shims 44 | -------------------------------------------------------------------------------- /rootfs/changelog.txt: -------------------------------------------------------------------------------- 1 | === Priism changelog === 2 | Last updated: May 24, 2025 12:50 PM EST 3 | 4 | == 2.0 stable [2025-05-24] == 5 | Priism 2.0 init is now Pint. https://github.com/xmb9/Pint. 6 | Includes services. Yay. 7 | 8 | == 2.0 release candidate [2025-05-24] == 9 | New TUI menu for Priism! No longer uses the old style options select. Very similar to SH1MMER's payload menu, but actually good. 10 | Easter eggs :) 11 | Shimboot detection (will prevent you from booting non-Priishimboot images). 12 | Failsafe if user has not ran Priishimbooter when booting Priishimboot. 13 | New splash text! 14 | Fixed an oversight in shmenu that allowed users to "Quit" the main menu. 15 | Updated changelog (duh). 16 | 17 | == 2.0 dev [2025-05-21] == 18 | Priism now runs as PID 1! Horray. 19 | New "priisminit" init system for some interesting behind the scenes stuff. 20 | Shim booting implementation finished (after an entire year...) 21 | Removed Ethereal Workshop branding (2/2) 22 | Added script date on splash screen. 23 | Changelog added. 24 | README updated to match shim booting and payload operation status. 25 | 26 | == 1.2 dev [2025-05-20] == 27 | Fixed some major flaws with Priism. Images and disk detection have been reworked entirely. 28 | Fixed PRIISM_IMAGES resizing (growpart issues). 29 | Removed stateful detection logic from installcros(). chromeos-recovery finds internal storage automatically. 30 | Fixed some name typos lmfaoooo. 31 | Updated the name "Archimax" in credits to "xmb9". 32 | Removed Ethereal Workshop branding (1/2) 33 | 34 | == 1.1 stable [2025-02-05] == 35 | Updated installcros() to fix installing recovery images on ChromeOS versions above ~113. 36 | Added "payloads" menu. Quick and dirty replacement for those who needed some things that shims provide but not all. 37 | 38 | == 1.0 stable [2025-01-15] == 39 | Priism is now MUCH more (skid)user-friendly. 40 | Added update_device.sh script. 41 | 42 | == 0.9a [2025-01-12] == 43 | Rebranded from "CROSMIDI" to "Priism". 44 | Fixed recovery (kernel priority is now set). 45 | Added auto-resizer inside of Priism. 46 | 47 | == 0.8 [2024-05-20] == 48 | Implemented installing recovery media. 49 | Added builder. Uses a SH1MMER legacy (Oct 2024+) image as a base. 50 | 51 | == 0.1 [2024-01-20] == 52 | Basic shim booting implementation added. Uses chroot. Kind of lame. 53 | -------------------------------------------------------------------------------- /update_device.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | COLOR_RESET="\033[0m" 4 | COLOR_BLACK_B="\033[1;30m" 5 | COLOR_RED_B="\033[1;31m" 6 | COLOR_GREEN="\033[0;32m" 7 | COLOR_GREEN_B="\033[1;32m" 8 | COLOR_YELLOW="\033[0;33m" 9 | COLOR_YELLOW_B="\033[1;33m" 10 | COLOR_BLUE_B="\033[1;34m" 11 | COLOR_MAGENTA_B="\033[1;35m" 12 | COLOR_CYAN_B="\033[1;36m" 13 | 14 | fail() { 15 | printf "${COLOR_RED_B}%b${COLOR_RESET}\n" "$*" >&2 || : 16 | exit 1 17 | } 18 | 19 | [ "$EUID" -ne 0 ] && fail "Please run as root" 20 | IMAGE=$1 21 | DEVICE=$2 22 | 23 | ARCHITECTURE="$(uname -m)" 24 | case "$ARCHITECTURE" in 25 | *x86_64* | *x86-64*) ARCHITECTURE=x86_64 ;; 26 | *aarch64* | *armv8*) ARCHITECTURE=aarch64 ;; 27 | *i[3-6]86*) ARCHITECTURE=i386 ;; 28 | *) fail "Unsupported architecture $ARCHITECTURE" ;; 29 | esac 30 | 31 | [ -z "$1" ] && fail "Specify a sh1mmer legacy image (Feb 2024+) to modify!" 32 | [ -z "$2" ] && fail "Specify a block device (e.g /dev/sda) to update!" 33 | 34 | bash priism_builder.sh $IMAGE || fail "Failed to build Priism image!" 35 | 36 | losetup -Pf $IMAGE 37 | 38 | CGPT="lib/$ARCHITECTURE/cgpt" 39 | chmod +x "$CGPT" 40 | 41 | LOOP_PART=$("$CGPT" find -l SH1MMER /dev/loop* 2> /dev/null | grep "/dev/loop" --color=never | head -n 1) || fail "Failed to get SH1MMER partition on loop device" 42 | DEVICE_PART=$("$CGPT" find -l SH1MMER "$DEVICE" 2> /dev/null | grep "$DEVICE" --color=never | head -n 1) || fail "Failed to get SH1MMER partition on ${DEVICE}" 43 | IMAGES_PART_LOOP=$("$CGPT" find -l PRIISM_IMAGES /dev/loop* 2> /dev/null | grep "/dev/loop" --color=never | head -n 1) || fail "Failed to get PRIISM_IMAGES partition on ${DEVICE}" 44 | IMAGES_PART=$("$CGPT" find -l PRIISM_IMAGES "$DEVICE"* 2> /dev/null | grep "$DEVICE" --color=never | head -n 1) || fail "Failed to get PRIISM_IMAGES partition on ${DEVICE}" 45 | 46 | echo "SH1MMER partition on loop device is: ${LOOP_PART}" 47 | echo "SH1MMER partition on ${DEVICE} is: ${DEVICE_PART}" 48 | echo "PRIISM_IMAGES partition on loop device is: ${IMAGES_PART_LOOP}" 49 | echo "PRIISM_IMAGES partition on ${DEVICE} is: ${IMAGES_PART}" 50 | 51 | echo -e "${COLOR_YELLOW_B}About to flash SH1MMER partition on ${DEVICE}! Data loss could possibly occur!${COLOR_RESET}" 52 | echo -e "Please make sure the above partition values look correct!" 53 | read -p "Press enter to continue, or CTRL+C to exit." 54 | echo -e "${COLOR_YELLOW_B}Flashing partition in 5 seconds... press CTRL+C NOW to cancel!" 55 | sleep 5 56 | echo -e "${COLOR_GREEN}Info: Beginning flash...${COLOR_RESET}" 57 | dd if="$LOOP_PART" of="$DEVICE_PART" status=progress || fail "An error occurred during flashing. Please report this, it could be bad!" 58 | sync 59 | echo -e "${COLOR_GREEN}Info: Copying payloads to PRIISM_IMAGES...${COLOR_RESET}" 60 | MNT_IMAGES=$(mktemp -d) 61 | MNT_IMAGES_LOOP=$(mktemp -d) 62 | mount "$IMAGES_PART" "$MNT_IMAGES" 63 | mount "$IMAGES_PART_LOOP" "$MNT_IMAGES_LOOP" 64 | mkdir "$MNT_IMAGES/payloads/" 65 | cp -vR "$MNT_IMAGES_LOOP"/payloads/* "$MNT_IMAGES"/payloads/ 66 | sync 67 | sync 68 | sync 69 | sleep 0.2 70 | umount "$MNT_IMAGES" 71 | umount "$MNT_IMAGES_LOOP" 72 | umount /tmp/tmp.* 2&> /dev/null # Failsafe umount. I fucking hate loopback devices. 73 | losetup --detach-all 74 | echo -e "${COLOR_GREEN}Done. Have fun!${COLOR_RESET}" 75 | -------------------------------------------------------------------------------- /rootfs/sbin/init: -------------------------------------------------------------------------------- 1 | #!/bin/bash -l 2 | 3 | declare -A VERSION 4 | 5 | VERSION["NAME"]="Pint" 6 | VERSION["NUMBER"]="1.0" 7 | VERSION["STRING"]="${VERSION[NAME]} v${VERSION[NUMBER]}" 8 | 9 | COLOR_RESET="\033[0m" 10 | COLOR_BLACK_B="\033[1;30m" 11 | COLOR_RED_B="\033[1;31m" 12 | COLOR_GREEN="\033[0;32m" 13 | COLOR_GREEN_B="\033[1;32m" 14 | COLOR_YELLOW="\033[0;33m" 15 | COLOR_YELLOW_B="\033[1;33m" 16 | COLOR_BLUE_B="\033[1;34m" 17 | COLOR_MAGENTA_B="\033[1;35m" 18 | COLOR_CYAN_B="\033[1;36m" 19 | 20 | echo -e "Starting up ${COLOR_GREEN_B}${VERSION["STRING"]}${COLOR_RESET} on ${COLOR_BLUE_B}$(/bin/busybox uname -o) $(/bin/busybox uname -r)${COLOR_RESET}" 21 | 22 | services="/usr/share/pint/pint.d/" 23 | handoffConfig="/usr/share/pint/handoff.conf" 24 | defaultHandoff="/usr/sbin/sh1mmer_main.sh" 25 | 26 | log() { 27 | local level="$1" 28 | local message="$2" 29 | echo -e "[$level] $message" 30 | echo -e "[$level] $message" > /dev/kmsg 31 | } 32 | 33 | nextHandoff= 34 | sourceHandoff=false 35 | 36 | hang() { 37 | echo "Halting." 38 | while :; do sleep 1d; done 39 | } 40 | 41 | detectHandoff() { 42 | if [[ -f "$handoffConfig" && -s "$handoffConfig" ]]; then 43 | nextHandoff=$(cat "$handoffConfig" | /bin/busybox xargs) 44 | log "${COLOR_GREEN_B}OK${COLOR_RESET}" "Found handoff as $nextHandoff" 45 | else 46 | log "${COLOR_YELLOW_B}WARN${COLOR_RESET}" "Handoff Config does not exist! Fallback to default." 47 | nextHandoff="$defaultHandoff" 48 | fi 49 | 50 | if /bin/busybox head -n 1 "$nextHandoff" | /bin/busybox grep -q '^#!'; then 51 | log "${COLOR_GREEN_B}OK${COLOR_RESET}" "Handoff is a shell script. Will be sourced." 52 | sourceHandoff=true 53 | fi 54 | 55 | if [ ! -x "$nextHandoff" ] && [ "$sourceHandoff" == false ]; then 56 | log "${COLOR_RED_B}ERROR${COLOR_RESET}" "Handoff does not exist or is not executable." 57 | hang 58 | fi 59 | } 60 | 61 | runServices() { 62 | local path="$1" 63 | 64 | if [[ ! -d "$path" ]]; then 65 | log "${COLOR_RED_B}ERROR${COLOR_RESET}" "Services path $path does not exist or is not a directory" 66 | return 67 | fi 68 | 69 | services=($(ls -v "$path"/* 2>/dev/null)) 70 | 71 | if [[ ${#services[@]} -eq 0 ]]; then 72 | log "${COLOR_YELLOW_B}WARN${COLOR_RESET}" "No services found in $path" 73 | return 74 | fi 75 | 76 | for i in "${!services[@]}"; do 77 | s="${services[$i]}" 78 | if [[ -x "$s" ]]; then 79 | log "..." "($((i+1))/${#services[@]}) Starting service $s" 80 | "$s" 81 | if [[ $? -ne 0 ]]; then 82 | log "${COLOR_RED_B}ERROR${COLOR_RESET}" "Failure running service $s" 83 | hang 84 | else 85 | log "${COLOR_GREEN_B}OK${COLOR_RESET}" "Started service $s" 86 | fi 87 | else 88 | log "${COLOR_RED_B}ERROR${COLOR_RESET}" "Service $s is not an executable!" 89 | hang 90 | fi 91 | done 92 | } 93 | 94 | launchHandoff() { 95 | local init_path="$1" 96 | 97 | if [ "$sourceHandoff" = true ]; then 98 | log "${COLOR_GREEN_B}OK${COLOR_RESET}" "Sourcing handoff $init_path" 99 | source "$init_path" 100 | else 101 | log "${COLOR_GREEN_B}OK${COLOR_RESET}" "Starting handoff $init_path" 102 | exec "$init_path" 103 | fi 104 | 105 | log "${COLOR_RED_B}ERROR${COLOR_RESET}" "Something went wrong during handoff" 106 | hang 107 | } 108 | 109 | /usr/bin/setsid -c test # Prevent CTRL + C on init 110 | detectHandoff 111 | runServices "$services" 112 | launchHandoff "$nextHandoff" 113 | -------------------------------------------------------------------------------- /priism_builder.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | IMAGE=$1 4 | SCRIPT_DIR=$(dirname "$0") 5 | SCRIPT_DIR=${SCRIPT_DIR:-"."} 6 | . "$SCRIPT_DIR/wax_common.sh" 7 | 8 | [ "$EUID" -ne 0 ] && fail "Please run as root" 9 | [ -z "$1" ] && fail "Specify a SH1MMER Legacy image (Feb 2024+) to modify with 'priism_builder.sh image.bin'" 10 | 11 | cleanup() { 12 | [ -d "$MNT_SH1MMER" ] && umount "$MNT_SH1MMER" && rmdir "$MNT_SH1MMER" 13 | [ -z "$LOOPDEV" ] || losetup -d "$LOOPDEV" || : 14 | trap - EXIT INT 15 | } 16 | 17 | check_raw_shim() { 18 | log_info "Checking if this is a raw shim..." 19 | CGPT="${SCRIPT_DIR}/lib/$ARCHITECTURE/cgpt" 20 | chmod +x "$CGPT" 21 | sh1mmer_exists=$("$CGPT" find -l SH1MMER "$LOOPDEV" 2&> /dev/null) 22 | if [ $? != 0 ]; then 23 | fail "Use a SH1MMER Legacy image, not a raw shim!" 24 | fi 25 | log_info "SH1MMER Legacy image detected, continuing..." 26 | } 27 | 28 | check_pre_frecon() { 29 | log_info "Checking if shim is pre-frecon..." 30 | MNT_ROOTA=$(mktemp -d) 31 | mount -o ro,norecovery "${LOOPDEV}p4" "$MNT_ROOTA" 32 | if [ ! -f $MNT_ROOTA/sbin/frecon ]; then 33 | fail "Pre-frecon shims are not supported." 34 | fi 35 | log_info "Shim has frecon present. Continuing..." 36 | umount "$MNT_ROOTA" 37 | } 38 | 39 | patch_sh1mmer() { 40 | log_info "Creating Priism images partition ($(format_bytes $SH1MMER_PART_SIZE))" 41 | local sector_size=$(get_sector_size "$LOOPDEV") 42 | cgpt_add_auto "$IMAGE" "$LOOPDEV" 5 $((SH1MMER_PART_SIZE / sector_size)) -t data -l PRIISM_IMAGES 43 | mkfs.ext2 -F -b 4096 -L PRIISM_IMAGES "${LOOPDEV}p5" 44 | 45 | safesync 46 | suppress sgdisk -e "$IMAGE" 2>&1 | sed 's/\a//g' 47 | safesync 48 | 49 | MNT_SH1MMER=$(mktemp -d) 50 | MNT_priism=$(mktemp -d) 51 | mount "${LOOPDEV}p1" "$MNT_SH1MMER" 52 | 53 | log_info "Copying payload" 54 | mv "$MNT_SH1MMER/root/noarch/usr/sbin/sh1mmer_main.sh" "$MNT_SH1MMER/root/noarch/usr/sbin/sh1mmer_main_old.sh" 55 | cp priism.sh "$MNT_SH1MMER/root/noarch/usr/sbin/sh1mmer_main.sh" 56 | cp priism_init.sh "$MNT_SH1MMER/bootstrap/noarch/init_sh1mmer.sh" 57 | mkdir -p "$MNT_SH1MMER/root/noarch/sbin/" # half the time this doesn't exist. make it. 58 | cp -r rootfs/* "$MNT_SH1MMER/root/noarch/" 59 | chmod -R +x "$MNT_SH1MMER" 60 | 61 | umount "$MNT_SH1MMER" 62 | rmdir "$MNT_SH1MMER" 63 | 64 | mount "${LOOPDEV}p5" "$MNT_priism" 65 | 66 | mkdir "$MNT_priism/shims" 67 | mkdir "$MNT_priism/recovery" 68 | mkdir "$MNT_priism/payloads/" 69 | cp "$SCRIPT_DIR/payloads/"* "$MNT_priism/payloads/" -r 70 | touch "$MNT_priism/.IMAGES_NOT_YET_RESIZED" 71 | chmod 777 "$MNT_priism"/* 72 | safesync 73 | umount $MNT_priism 74 | rmdir $MNT_priism 75 | } 76 | 77 | FLAGS_sh1mmer_part_size=64M 78 | 79 | if [ -b "$IMAGE" ]; then 80 | log_info "Image is a block device, performance may suffer..." 81 | else 82 | check_file_rw "$IMAGE" || fail "$IMAGE doesn't exist, isn't a file, or isn't RW" 83 | check_slow_fs "$IMAGE" 84 | fi 85 | 86 | check_gpt_image "$IMAGE" || fail "$IMAGE is not GPT, or is corrupted" 87 | 88 | SH1MMER_PART_SIZE=$(parse_bytes "$FLAGS_sh1mmer_part_size") || fail "Could not parse size '$FLAGS_sh1mmer_part_size'" 89 | 90 | sudo dd if=/dev/zero bs=1MiB of="$IMAGE" conv=notrunc oflag=append count=100 91 | # sane backup table 92 | suppress sgdisk -e "$IMAGE" 2>&1 | sed 's/\a//g' 93 | 94 | log_info "Correcting GPT errors" 95 | suppress fdisk "$IMAGE" <&1 | sed 's/\a//g' 123 | 124 | log_info "Done. Have fun!" 125 | trap - EXIT 126 | -------------------------------------------------------------------------------- /priism_init.sh: -------------------------------------------------------------------------------- 1 | #!/bin/busybox sh 2 | 3 | set -eE 4 | 5 | TMPFS_SIZE=1024M 6 | NEWROOT_MNT=/newroot 7 | ROOTFS_MNT=/usb 8 | 9 | STATEFUL_MNT="$1" 10 | STATEFUL_DEV="$2" 11 | BOOTSTRAP_DEV="$3" 12 | ARCHITECTURE="${4:-x86_64}" 13 | 14 | ROOTFS_DEV= 15 | 16 | SCRIPT_DATE="[2025-5-24]" 17 | 18 | COLOR_RESET="\033[0m" 19 | COLOR_BLACK_B="\033[1;30m" 20 | COLOR_RED_B="\033[1;31m" 21 | COLOR_GREEN="\033[0;32m" 22 | COLOR_GREEN_B="\033[1;32m" 23 | COLOR_YELLOW="\033[0;33m" 24 | COLOR_YELLOW_B="\033[1;33m" 25 | COLOR_BLUE_B="\033[1;34m" 26 | COLOR_MAGENTA_B="\033[1;35m" 27 | COLOR_CYAN_B="\033[1;36m" 28 | 29 | fail() { 30 | printf "%b\nAborting.\n" "$*" >&2 31 | cleanup || : 32 | 33 | sleep 1 34 | self_shell || : 35 | 36 | tail -f /dev/null 37 | exit 1 38 | } 39 | 40 | cleanup() { 41 | umount "$STATEFUL_MNT" || : 42 | umount "$ROOTFS_MNT" || : 43 | } 44 | 45 | trap 'fail "An unhandled error occured."' ERR 46 | 47 | enable_input() { 48 | stty echo || : 49 | } 50 | 51 | disable_input() { 52 | stty -echo || : 53 | } 54 | 55 | clear_line() { 56 | local cols 57 | cols=$(stty size | cut -d" " -f 2) 58 | printf "%-${cols}s\r" 59 | } 60 | 61 | pv_dircopy() { 62 | [ -d "$1" ] || return 1 63 | local apparent_bytes 64 | apparent_bytes=$(du -sb "$1" | cut -f 1) 65 | mkdir -p "$2" 66 | tar -cf - -C "$1" . | pv -f -s "${apparent_bytes:-0}" | tar -xf - -C "$2" 67 | } 68 | 69 | determine_rootfs() { 70 | local bootstrap_num 71 | bootstrap_num="$(echo "$BOOTSTRAP_DEV" | grep -o '[0-9]*$')" 72 | ROOTFS_DEV="$(echo "$BOOTSTRAP_DEV" | sed 's/[0-9]*$//')$((bootstrap_num + 1))" 73 | [ -b "$ROOTFS_DEV" ] || return 1 74 | } 75 | 76 | patch_new_root_sh1mmer() { 77 | [ -f "$NEWROOT_MNT/sbin/chromeos_startup" ] && sed -i "s/BLOCK_DEVMODE=1/BLOCK_DEVMODE=/g" "$NEWROOT_MNT/sbin/chromeos_startup" 78 | [ -f "$NEWROOT_MNT/usr/share/cros/dev_utils.sh" ] && sed -i "/^dev_check_block_dev_mode\(\)/a return" "$NEWROOT_MNT/usr/share/cros/dev_utils.sh" 79 | [ -f "$NEWROOT_MNT/sbin/chromeos-boot-alert" ] && sed -i "/^mode_block_devmode\(\)/a return" "$NEWROOT_MNT/sbin/chromeos-boot-alert" 80 | # disable factory-related jobs 81 | local file 82 | local disable_jobs="factory_shim factory_install factory_ui" 83 | for job in $disable_jobs; do 84 | file="$NEWROOT_MNT/etc/init/${job}.conf" 85 | if [ -f "$file" ]; then 86 | sed -i '/^start /!d' "$file" 87 | echo "exec true" >>"$file" 88 | fi 89 | done 90 | } 91 | 92 | # todo: dev console on tty4, better logging 93 | 94 | disable_input 95 | 96 | mkdir -p "$NEWROOT_MNT" "$ROOTFS_MNT" 97 | mount -t tmpfs tmpfs "$NEWROOT_MNT" -o "size=$TMPFS_SIZE" || fail "Failed to mount tmpfs" 98 | 99 | determine_rootfs || fail "Could not determine rootfs" 100 | mount -o ro "$ROOTFS_DEV" "$ROOTFS_MNT" || fail "Failed to mount rootfs $ROOTFS_DEV" 101 | 102 | printf "\033[?25l\033[2J\033[H" 103 | 104 | printf "${COLOR_MAGENTA_B}" 105 | echo " ...." 106 | echo " .. ......" 107 | echo " .::. ........." 108 | echo " .:..:. ......:::..." 109 | echo " .::..::. ..::::---:::..." 110 | echo " ........ :::::::::: ..::-====--::.... " 111 | echo " ...:::::...::::::::..:::-=++=--:..... " 112 | echo " ....----:::::::::-:..... " 113 | echo " .:-:.........::::. " 114 | echo " .............::::-:. " 115 | echo " ............::::::-:. " 116 | echo " .....::::::::::::::--: " 117 | printf "${COLOR_RESET}" 118 | echo "Priism is loading..." 119 | echo "Bootloader version: ${SCRIPT_DATE}" 120 | echo "https://github.com/xmb9/Priism" 121 | echo "" 122 | 123 | echo "Copying rootfs..." 124 | pv_dircopy "$ROOTFS_MNT" "$NEWROOT_MNT" 125 | umount "$ROOTFS_MNT" 126 | echo "" 127 | 128 | SKIP_SH1MMER_PATCH=0 129 | 130 | echo "Patching new root..." 131 | printf "${COLOR_BLACK_B}" 132 | /bin/patch_new_root.sh "$NEWROOT_MNT" "$STATEFUL_DEV" 133 | [ "$SKIP_SH1MMER_PATCH" -eq 0 ] && patch_new_root_sh1mmer 134 | printf "${COLOR_RESET}" 135 | echo "" 136 | 137 | if [ "$SKIP_SH1MMER_PATCH" -eq 0 ]; then 138 | echo "Copying Priism files..." 139 | pv_dircopy "$STATEFUL_MNT/root/noarch" "$NEWROOT_MNT" || : 140 | pv_dircopy "$STATEFUL_MNT/root/$ARCHITECTURE" "$NEWROOT_MNT" || : 141 | cp /bin/busybox "$NEWROOT_MNT/bin/busybox" 142 | echo "" 143 | fi 144 | 145 | umount "$STATEFUL_MNT" 146 | 147 | # write this to a file so the user can easily run this from the debug shell 148 | cat </bin/sh1mmer_switch_root 149 | #!/bin/busybox sh 150 | 151 | if [ \$\$ -ne 1 ]; then 152 | echo "No PID 1. Abort." 153 | exit 1 154 | fi 155 | 156 | BASE_MOUNTS="/sys /proc /dev" 157 | move_mounts() { 158 | # copied from https://chromium.googlesource.com/chromiumos/platform/initramfs/+/54ea247a6283e7472a094215b4929f664e337f4f/factory_shim/bootstrap.sh#302 159 | echo "Moving \$BASE_MOUNTS to $NEWROOT_MNT" 160 | for mnt in \$BASE_MOUNTS; do 161 | # \$mnt is a full path (leading '/'), so no '/' joiner 162 | mkdir -p "$NEWROOT_MNT\$mnt" 163 | mount -n -o move "\$mnt" "$NEWROOT_MNT\$mnt" 164 | done 165 | echo "Done." 166 | } 167 | 168 | move_mounts 169 | echo "exec switch_root" 170 | echo "this shouldn't take more than a few seconds" 171 | exec switch_root "$NEWROOT_MNT" /sbin/init -v --default-console output || : 172 | EOF 173 | chmod +x /bin/sh1mmer_switch_root 174 | 175 | enable_input 176 | exec sh1mmer_switch_root || : 177 | 178 | # should never reach here 179 | fail "Failed to exec switch_root." 180 | -------------------------------------------------------------------------------- /wax_common.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # wax common file, this should probably be sourced 3 | 4 | # internal variables 5 | COLOR_RESET="\033[0m" 6 | COLOR_BLACK_B="\033[1;30m" 7 | COLOR_RED_B="\033[1;31m" 8 | COLOR_GREEN="\033[0;32m" 9 | COLOR_GREEN_B="\033[1;32m" 10 | COLOR_YELLOW="\033[0;33m" 11 | COLOR_YELLOW_B="\033[1;33m" 12 | COLOR_BLUE_B="\033[1;34m" 13 | COLOR_MAGENTA_B="\033[1;35m" 14 | COLOR_CYAN_B="\033[1;36m" 15 | 16 | fail() { 17 | printf "${COLOR_RED_B}%b${COLOR_RESET}\n" "$*" >&2 || : 18 | exit 1 19 | } 20 | 21 | readlink /proc/$$/exe | grep -q bash || fail "Please run with bash" 22 | 23 | check_deps() { 24 | for dep in "$@"; do 25 | command -v "$dep" &>/dev/null || echo "$dep" 26 | done 27 | } 28 | 29 | log_debug() { 30 | [ "${FLAGS_debug:-0}" = "${FLAGS_TRUE:-1}" ] && printf "${COLOR_YELLOW}Debug: %b${COLOR_RESET}\n" "$*" >&2 || : 31 | } 32 | 33 | log_info() { 34 | printf "${COLOR_GREEN}Info: %b${COLOR_RESET}\n" "$*" || : 35 | } 36 | 37 | log_error() { 38 | printf "${COLOR_RED_B}Error: %b${COLOR_RESET}\n" "$*" || : 39 | } 40 | 41 | suppress() { 42 | "$@" &>/dev/null 43 | } 44 | 45 | suppress_out() { 46 | if [ "${FLAGS_debug:-0}" = "${FLAGS_TRUE:-1}" ]; then 47 | "$@" 48 | else 49 | "$@" >/dev/null 50 | fi 51 | } 52 | 53 | SCRIPT_DIR=$(dirname "$0") 54 | SCRIPT_DIR=${SCRIPT_DIR:-"."} 55 | 56 | is_ext2() { 57 | local rootfs="$1" 58 | local offset="${2-0}" 59 | 60 | local sb_magic_offset=$((0x438)) 61 | local sb_value=$(dd if="$rootfs" skip=$((offset + sb_magic_offset)) \ 62 | count=2 bs=1 2>/dev/null) 63 | local expected_sb_value=$(printf '\123\357') 64 | if [ "$sb_value" = "$expected_sb_value" ]; then 65 | return 0 66 | fi 67 | return 1 68 | } 69 | 70 | enable_rw_mount() { 71 | local rootfs="$1" 72 | local offset="${2-0}" 73 | 74 | if ! is_ext2 "$rootfs" $offset; then 75 | echo "enable_rw_mount called on non-ext2 filesystem: $rootfs $offset" 1>&2 76 | return 1 77 | fi 78 | 79 | local ro_compat_offset=$((0x464 + 3)) 80 | printf '\000' | 81 | dd of="$rootfs" seek=$((offset + ro_compat_offset)) \ 82 | conv=notrunc count=1 bs=1 2>/dev/null 83 | } 84 | 85 | disable_rw_mount() { 86 | local rootfs="$1" 87 | local offset="${2-0}" 88 | 89 | if ! is_ext2 "$rootfs" $offset; then 90 | echo "disable_rw_mount called on non-ext2 filesystem: $rootfs $offset" 1>&2 91 | return 1 92 | fi 93 | 94 | local ro_compat_offset=$((0x464 + 3)) 95 | printf '\377' | 96 | dd of="$rootfs" seek=$((offset + ro_compat_offset)) \ 97 | conv=notrunc count=1 bs=1 2>/dev/null 98 | } 99 | 100 | rw_mount_disabled() { 101 | local rootfs="$1" 102 | local offset="${2-0}" 103 | 104 | if ! is_ext2 "$rootfs" $offset; then 105 | return 2 106 | fi 107 | 108 | local ro_compat_offset=$((0x464 + 3)) 109 | local ro_value=$(dd if="$rootfs" skip=$((offset + ro_compat_offset)) \ 110 | count=1 bs=1 2>/dev/null) 111 | local expected_ro_value=$(printf '\377') 112 | if [ "$ro_value" = "$expected_ro_value" ]; then 113 | return 0 114 | fi 115 | return 1 116 | } 117 | 118 | check_semver_ge() { 119 | local major="$(echo "$1" | cut -d. -f1)" 120 | local minor="$(echo "$1" | cut -d. -f2)" 121 | local patch="$(echo "$1" | cut -d. -f3)" 122 | [ "$major" -lt "$2" ] && return 1 123 | [ "$major" -gt "$2" ] && return 0 124 | [ "$minor" -lt "$3" ] && return 1 125 | [ "$minor" -gt "$3" ] && return 0 126 | [ "${patch:-0}" -lt "$4" ] && return 1 127 | return 0 128 | } 129 | 130 | ARCHITECTURE="$(uname -m)" 131 | case "$ARCHITECTURE" in 132 | *x86_64* | *x86-64*) ARCHITECTURE=x86_64 ;; 133 | *aarch64* | *armv8*) ARCHITECTURE=aarch64 ;; 134 | *i[3-6]86*) ARCHITECTURE=i386 ;; 135 | *) fail "Unsupported architecture $ARCHITECTURE" ;; 136 | esac 137 | 138 | if command -v sfdisk &>/dev/null && check_semver_ge "$(sfdisk --version | awk '{print $NF}')" 2 38 0; then 139 | log_debug "using machine's sfdisk" 140 | SFDISK=sfdisk 141 | else 142 | log_debug "using bundled sfdisk" 143 | SFDISK="${SCRIPT_DIR}/lib/$ARCHITECTURE/sfdisk" 144 | chmod +x "$SFDISK" 145 | fi 146 | 147 | # no way to check cgpt version, so we always use the bundled build 148 | CGPT="${SCRIPT_DIR}/lib/$ARCHITECTURE/cgpt" 149 | chmod +x "$CGPT" 150 | 151 | format_bytes() { 152 | numfmt --to=iec-i --suffix=B "$@" 153 | } 154 | 155 | parse_bytes() { 156 | numfmt --from=iec "$@" 2>/dev/null 157 | } 158 | 159 | check_file_rw() { 160 | [ -f "$1" -a -r "$1" -a -w "$1" ] 161 | } 162 | 163 | check_gpt_image() { 164 | "$SFDISK" -l "$1" 2>/dev/null | grep -q "Disklabel type: gpt" 165 | } 166 | 167 | check_slow_fs() { 168 | if uname -r | grep -qi microsoft && realpath "$1" | grep -q "^/mnt"; then 169 | echo "You are attempting to run wax on a file in your windows filesystem." 170 | echo "Performance would suffer, so please move your file into your linux filesystem (e.g. ~/file.bin)" 171 | exit 1 172 | fi 173 | } 174 | 175 | safesync() { 176 | sync 177 | sleep 0.2 178 | } 179 | 180 | get_sectors() { 181 | "$SFDISK" -l "$1" 2>/dev/null | grep "sectors$" | awk '{print $(NF-1)}' 182 | } 183 | 184 | get_sector_size() { 185 | "$SFDISK" -l "$1" 2>/dev/null | grep "^Sector size" | awk '{print $4}' 186 | } 187 | 188 | get_final_sector() { 189 | "$SFDISK" -l -o end "$1" 2>/dev/null | grep "^\s*[0-9]" | awk '{print $1}' | sort -nr | head -n 1 190 | } 191 | 192 | get_gpt_backup_table_sector() { 193 | "$CGPT" show "$1" | grep "Sec GPT table$" | awk '{print $1}' 194 | } 195 | 196 | get_parts() { 197 | "$CGPT" show -q "$1" | awk '{print $3}' 198 | } 199 | 200 | get_parts_physical_order() { 201 | local part_table=$("$CGPT" show -q "$1") 202 | local physical_parts=$(awk '{print $1}' <<<"$part_table" | sort -n) 203 | for part in $physical_parts; do 204 | grep "^\s*${part}\s" <<<"$part_table" | awk '{print $3}' 205 | done 206 | } 207 | 208 | delete_partitions_except() { 209 | local img="$1" 210 | local to_delete=() 211 | shift 212 | 213 | for part in $(get_parts "$img"); do 214 | grep -qw "$part" <<<"$@" || to_delete+=("$part") 215 | done 216 | 217 | log_info "Deleting partitions: ${to_delete[@]}" 218 | suppress "$SFDISK" --delete "$img" "${to_delete[@]}" 219 | } 220 | 221 | squash_partitions() { 222 | log_info "Squashing partitions" 223 | 224 | for part in $(get_parts_physical_order "$1"); do 225 | log_info "Squashing ${1}p${part}" 226 | suppress "$SFDISK" -N "$part" --move-data "$1" <<<"+,-" || : 227 | done 228 | } 229 | 230 | truncate_image() { 231 | local buffer=35 # magic number to ward off evil gpt corruption spirits 232 | local sector_size=$(get_sector_size "$1") 233 | local final_sector=$(get_final_sector "$1") 234 | local end_bytes=$(((final_sector + buffer) * sector_size)) 235 | log_info "Truncating image to $(format_bytes "$end_bytes")" 236 | 237 | if [ -b "$1" ]; then 238 | local loopdev=$(losetup -f) 239 | losetup -P "$loopdev" "$1" --sizelimit "$end_bytes" 240 | suppress sgdisk -e "$loopdev" 2>&1 | sed 's/\a//g' 241 | losetup -d "$loopdev" 242 | else 243 | truncate -s "$end_bytes" "$1" 244 | suppress sgdisk -e "$1" 2>&1 | sed 's/\a//g' 245 | fi 246 | 247 | [ -z "$2" ] || echo "$end_bytes" >"$2" 248 | } 249 | 250 | resize_image() { 251 | # 1: size, 2: image, 3: loop (optional) 252 | if [ -b "$2" ]; then 253 | echo "$2 is a block device, cannot resize" >&2 254 | return 1 255 | fi 256 | log_info "Resizing image to $(format_bytes "$1")" 257 | truncate -s "$1" "$2" 258 | suppress sgdisk -e "$2" 2>&1 | sed 's/\a//g' 259 | [ -z "$3" ] || losetup -c "$3" 260 | } 261 | 262 | cgpt_add_auto() { 263 | local final_sector gpt_sector difference img_sectors sector_size new_size 264 | local image="$1" 265 | local device="$2" 266 | local part="$3" 267 | local sectors="$4" 268 | shift 4 269 | final_sector=$(get_final_sector "$device") 270 | gpt_sector=$(get_gpt_backup_table_sector "$device") 271 | difference=$((gpt_sector - final_sector - sectors - 1)) 272 | if [ "$difference" -lt 0 ]; then 273 | img_sectors=$(get_sectors "$device") 274 | sector_size=$(get_sector_size "$device") 275 | # remember difference is negative 276 | new_size=$((sector_size * (img_sectors - difference))) 277 | echo $new_size 278 | resize_image "$new_size" "$image" "$device" 279 | fi 280 | "$CGPT" repair "$device" 281 | "$CGPT" add "$device" -i "$part" -b $((final_sector + 1)) -s "$sectors" "$@" 282 | partx -u -n "$part" "$device" 283 | } 284 | -------------------------------------------------------------------------------- /rootfs/usr/sbin/shmenu: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Priism 2.0 - shmenu.sh 4 | # Based on https://github.com/duclos-cavalcanti/shmenu 5 | 6 | ######### 7 | ### globals 8 | ######### 9 | _DEBUG=0 10 | 11 | declare -a _OPTIONS 12 | _CUR=1 13 | _TOTAL=0 14 | _CHOSEN= 15 | 16 | _PROMPT="MENU" 17 | 18 | _INPUT= 19 | 20 | ######### 21 | ### utils 22 | ######### 23 | usage() { 24 | man shmenu 25 | } 26 | 27 | parse() { 28 | if [[ $# -ne 0 ]]; then 29 | while [[ $# -gt 0 ]]; do 30 | case $1 in 31 | -o|--options) 32 | shift 33 | # append options as long as the current arg isnt 34 | # either empty or a possible flag/switch to other 35 | # features 36 | IFS=$'\n' read -r -d '' -a _OPTIONS < <(printf "%s\0" "$1") 37 | shift 38 | ;; 39 | 40 | -p|--prompt) 41 | shift 42 | # either take the next argument as prompt, if it is 43 | # somehow empty then take the default value of MENU 44 | _PROMPT="${1:-${_PROMPT}}" 45 | shift 46 | ;; 47 | 48 | -d|--debug) 49 | _DEBUG=1 50 | shift 51 | ;; 52 | 53 | -h|--help) 54 | usage 55 | exit 0 56 | ;; 57 | 58 | *) 59 | printf "UNKNOWN ARGUMENT: %s\n" "${${1}}" 60 | exit 1 61 | ;; 62 | esac 63 | done 64 | else 65 | printf "NO ARGUMENTS PROVIDED!\n" 66 | exit 1 67 | fi 68 | _TOTAL="${#_OPTIONS[@]}" 69 | [[ $_TOTAL -eq 0 ]] && echo "No options given!" && exit 1 70 | } 71 | 72 | ######### 73 | ### TUI 74 | ######### 75 | setup() { 76 | # https://vt100.net/docs/vt100-ug/contents.html 77 | # Modes: Wraparound 78 | printf '\e[?7l' 79 | 80 | # https://vt100.net/docs/vt510-rm/DECCRA.html 81 | # stores initial terminal state 82 | # uses DECCRA - copy rectangular area command 83 | printf '\e[?1049h' 84 | 85 | # stty changes and prints terminal line settings 86 | # -echo, removes the echoing/visual typing of user input 87 | stty -echo 88 | 89 | # trap allows us to capture and react to specific signals sent 90 | # to the running program. 91 | # 92 | # https://github.com/dylanaraps/writing-a-tui-in-bash#using-stty 93 | # In this case we're trapping the SIGWINCH signal which is 94 | # sent to the terminal and the running shell on window resize. 95 | # Callbacks the screen_size function when SIGWINCH is 96 | # received, thus updating the lines and columns variables 97 | trap 'screen_size' WINCH 98 | 99 | # clear screen to use a clean slate 100 | clear_screen 101 | 102 | # reset cursor to 2,2 so it fits into the [ ] boxes 103 | # and stays after the prompt 104 | set_cursor 2 2 105 | 106 | # draw the TUI 107 | draw 108 | 109 | } 110 | 111 | restore() { 112 | # https://vt100.net/docs/vt100-ug/contents.html 113 | # Modes: Wraparound 114 | printf '\e[?7h' 115 | 116 | # https://vt100.net/docs/vt510-rm/DECCRA.html 117 | # restore previous terminal state 118 | # uses DECCRA - copy rectangular area command 119 | printf '\e[?1049l' 120 | 121 | # stty changes and prints terminal line settings 122 | # -echo, enables the echoing/visual typing of user input 123 | stty echo 124 | 125 | show_cursor 126 | } 127 | 128 | clear_screen() { 129 | # https://vt100.net/docs/vt510-rm/ED.html 130 | # ED - Erase in Display 131 | # Arg 2: complete display 132 | printf '\e[2J' 133 | } 134 | 135 | screen_size() { 136 | # https://github.com/dylanaraps/writing-a-tui-in-bash#getting-the-window-size 137 | # Get terminal size ('stty' is POSIX and always available). 138 | # This can't be done reliably across all bash versions in pure bash. 139 | read -r LINES COLUMNS < <(stty size) 140 | } 141 | 142 | hide_cursor() { 143 | # https://vt100.net/docs/vt510-rm/DECTCEM.html 144 | # '\e[?25l': makes cursor invisible 145 | printf '\e[?25l' 146 | } 147 | 148 | show_cursor() { 149 | # https://vt100.net/docs/vt510-rm/DECTCEM.html 150 | # '\e[?25l': makes cursor visible 151 | printf '\e[?25h' 152 | } 153 | 154 | push_cursor_pos() { 155 | printf '\e7' 156 | } 157 | 158 | pop_cursor_pos() { 159 | printf '\e8' 160 | } 161 | 162 | set_cursor() { 163 | local row="$1" 164 | local col="$2" 165 | 166 | # https://vt100.net/docs/vt510-rm/CUP.html 167 | # CUP - Cursor Position 168 | if [[ -z "$row" || -z "$col" ]]; then 169 | printf '\e[H' 170 | else 171 | printf "\e[${row};${col}H" 172 | fi 173 | } 174 | 175 | cursor_up() { 176 | # https://vt100.net/docs/vt510-rm/CUU.html 177 | printf '\e[A' 178 | } 179 | 180 | cursor_down() { 181 | # https://vt100.net/docs/vt510-rm/CUD.html 182 | printf '\e[B' 183 | } 184 | 185 | cursor_left() { 186 | # https://vt100.net/docs/vt510-rm/CUB.html 187 | printf '\e[D' 188 | } 189 | 190 | cursor_right() { 191 | # https://vt100.net/docs/vt510-rm/CUF.html 192 | printf '\e[C' 193 | } 194 | 195 | underline_text() { 196 | # https://github.com/dylanaraps/pure-bash-bible#text-colors 197 | printf '\e[4m' 198 | } 199 | 200 | highlight_text() { 201 | # https://github.com/dylanaraps/pure-bash-bible#text-colors 202 | printf '\e[7m' 203 | } 204 | 205 | italic_text() { 206 | # https://github.com/dylanaraps/pure-bash-bible#text-colors 207 | printf '\e[3m' 208 | } 209 | 210 | reset_text() { 211 | # https://github.com/dylanaraps/pure-bash-bible#text-colors 212 | printf '\e[m' 213 | } 214 | 215 | ######### 216 | ### control flow 217 | ######### 218 | draw_debug() { 219 | local row= 220 | local col= 221 | 222 | # PRE_DRAW 223 | push_cursor_pos 224 | 225 | # 1 for the prompt, 1 for the help menu and ${TOTAL} for all options 226 | row=$((1 + $_TOTAL + 1 + 1)) 227 | col=1 228 | set_cursor $row $col 229 | 230 | # DRAW 231 | italic_text 232 | printf "last key: $_INPUT | LINES: ${LINES} | COLS: ${COLUMNS}" 233 | reset_text 234 | 235 | # POST_DRAW 236 | pop_cursor_pos 237 | } 238 | 239 | draw() { 240 | # PRE_DRAW 241 | push_cursor_pos 242 | set_cursor 1 1 243 | 244 | # PROMPT 245 | underline_text 246 | printf "${_PROMPT}\n\r" 247 | reset_text 248 | 249 | # OPTIONS 250 | for o in "${_OPTIONS[@]}"; do 251 | printf "[ ] ${o}\n\r" 252 | done 253 | 254 | # KEYBINDINGS 255 | highlight_text 256 | printf "Use arrow keys to navigate. Press enter to confirm.\n\r" 257 | reset_text 258 | 259 | 260 | # POST_DRAW 261 | pop_cursor_pos 262 | } 263 | 264 | refresh() { 265 | # was supposed to do much more, but we simplified 266 | # the program, will however leave a refresh function 267 | # even if unnecssary here for future modifications 268 | hide_cursor 269 | [[ $_DEBUG -eq 1 ]] && draw_debug 270 | show_cursor 271 | } 272 | 273 | main() { 274 | parse "$@" 275 | setup 276 | while [[ true ]]; do 277 | refresh 278 | # The read utility shall read a single logical line from standard input 279 | # into one or more shell variables. 280 | # '-r':, do not allow backslashes to escape any characters 281 | # '-n NCHARS': return after reading NCHARS 282 | # '-s': do not echo input from incoming terminal 283 | local key 284 | escape_char=$(printf "\u1b") 285 | read -rsn1 _INPUT # get 1 character 286 | if [[ $_INPUT == $escape_char ]]; then 287 | read -rsn2 _INPUT # read 2 more chars 288 | fi 289 | case ${_INPUT} in 290 | '[B') # down 291 | if [[ ${_CUR} -lt ${_TOTAL} ]]; then 292 | cursor_down 293 | ((_CUR++)) 294 | fi 295 | ;; 296 | 297 | '[A') # up 298 | if [[ ${_CUR} -gt 1 ]]; then 299 | cursor_up 300 | ((_CUR--)) 301 | fi 302 | ;; 303 | 304 | "") # user chose/selected option 305 | _CHOSEN=${_OPTIONS[((_CUR - 1))]} 306 | restore 307 | break 308 | ;; 309 | 310 | *) 311 | ;; 312 | esac 313 | 314 | # thanks, taken from: https://github.com/dylanaraps/fff 315 | # Exit if there is no longer a terminal attached. 316 | if [[ ! -t 1 ]]; then 317 | restore 318 | exit 1 319 | fi 320 | done 321 | } 322 | 323 | main "$@" 324 | [ -n "${_CHOSEN}" ] && printf "${_CHOSEN}" > /tmp/shmenu_choice || exit 0 325 | -------------------------------------------------------------------------------- /priism.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | clear 4 | 5 | releaseBuild=1 6 | recoroot="/mnt/recoroot" 7 | shimroot="/mnt/shimroot" 8 | 9 | COLOR_RESET="\033[0m" 10 | COLOR_BLACK_B="\033[1;30m" 11 | COLOR_RED_B="\033[1;31m" 12 | COLOR_GREEN="\033[0;32m" 13 | COLOR_GREEN_B="\033[1;32m" 14 | COLOR_YELLOW="\033[0;33m" 15 | COLOR_YELLOW_B="\033[1;33m" 16 | COLOR_BLUE_B="\033[1;34m" 17 | COLOR_MAGENTA_B="\033[1;35m" 18 | COLOR_CYAN_B="\033[1;36m" 19 | 20 | if [[ $releaseBuild -eq 1 ]]; then 21 | trap '' INT 22 | fi 23 | 24 | fail() { 25 | printf "Priism panic: ${COLOR_RED_B}%b${COLOR_RESET}\n" "$*" >&2 || : 26 | printf "panic: We are hanging here..." 27 | sync 28 | umount /mnt/priism/ &> /dev/null 29 | umount /mnt/shimroot &> /dev/null 30 | umount /newroot &> /dev/null 31 | umount /mnt/recoroot &> /dev/null 32 | losetup -D 33 | hang 34 | } 35 | 36 | hang() { 37 | tput civis 38 | stty -echo 39 | sleep 1h 40 | echo "You really still haven't turned off your device?" 41 | sleep 1d 42 | echo "I give up. Bye." 43 | sleep 5 44 | reboot -f 45 | } 46 | 47 | get_largest_cros_blockdev() { 48 | local largest size dev_name tmp_size remo 49 | size=0 50 | for blockdev in /sys/block/*; do 51 | dev_name="${blockdev##*/}" 52 | echo -e "$dev_name" | grep -q '^\(loop\|ram\)' && continue 53 | tmp_size=$(cat "$blockdev"/size) 54 | remo=$(cat "$blockdev"/removable) 55 | if [ "$tmp_size" -gt "$size" ] && [ "${remo:-0}" -eq 0 ]; then 56 | case "$(sfdisk -d "/dev/$dev_name" 2>/dev/null)" in 57 | *'name="STATE"'*'name="KERN-A"'*'name="ROOT-A"'*) 58 | largest="/dev/$dev_name" 59 | size="$tmp_size" 60 | ;; 61 | esac 62 | fi 63 | done 64 | echo -e "$largest" 65 | } 66 | 67 | funText() { 68 | splashText=(" Triangle is love, triangle is life." " Placeholder splash text" " The lower tape fade meme is still massive" " Now in TUI format!" " The average reaction after talking with fanqyxl" "Discord speech impediment... oh wait that's 2468") 69 | selectedSplashText=${splashText[$RANDOM % ${#splashText[@]}]} 70 | echo -e " " 71 | echo -e "$selectedSplashText" 72 | } 73 | 74 | funTextbutGay() { 75 | splashText=("Triangle is love, triangle is life." "Placeholder splash text" "The lower tape fade meme is still massive" "Now in TUI format!" "The average reaction after talking with fanqyxl" "Discord speech impediment... oh wait that's 2468") 76 | selectedSplashText=${splashText[$RANDOM % ${#splashText[@]}]} 77 | echo -e "$selectedSplashText" 78 | } 79 | 80 | 81 | detect_priism_in_shimboot_function() { 82 | echo "dD0oIkhlYXJzYXkhIiAiSSByZWZ1c2UuIiAiSSBzaGFsbCBkbyBubyBzdWNoIHRoaW5nISIgIkxpa2UuLi4gd2h5Pz8/IiAiSSBjZXJ0YWlubHkgd2lsbCBub3QhIiAiQXJlIHlvdSBqdXN0IGhlcmUgdG8gZGlsbHlkYWRkbGU/IiAiWW91IHJlYWxseSBoYXZlIG5vdGhpbmcgYmV0dGVyIHRvIGRvLCBkb24ndCB5b3U/IikKcz0ke3RbJFJBTkRPTSAlICR7I3RbQF19XX0KZWNobyAtZSAiICIKZWNobyAtZSAiJHMi" | base64 -d | bash 83 | } 84 | 85 | splash() { 86 | local width=48 87 | local verstring=${VERSION["STRING"]} 88 | local build=${VERSION["BUILDDATE"]} 89 | local version_pad=$(( (width - ${#verstring}) / 2 )) 90 | local build_pad=$(( (width - ${#build}) / 2 )) 91 | echo -e "$COLOR_MAGENTA_B ...." 92 | echo -e " .. ......" 93 | echo -e " .::. ........." 94 | echo -e " .:..:. ......:::..." 95 | echo -e " .::..::. ..::::---:::..." 96 | echo -e " ........ :::::::::: ..::-====--::.... " 97 | echo -e " ...:::::...::::::::..:::-=++=--:..... " 98 | echo -e " ....----:::::::::-:..... " 99 | echo -e " .:-:.........::::. " 100 | echo -e " .............::::-:. " 101 | echo -e " ............::::::-:. " 102 | echo -e " .....::::::::::::::--: $COLOR_RESET" 103 | echo -e " Priism " 104 | echo -e " or " 105 | echo -e " Portable recovery image installer/shim manager " 106 | echo -e "$(printf "%*s%s" $version_pad "" "$verstring")" 107 | echo -e "$(printf "%*s%s" $build_pad "" "$build")" 108 | funText 109 | echo -e " " 110 | } 111 | 112 | # version strings: use dev, stable, or release candidate 113 | declare -A VERSION 114 | 115 | VERSION["BRANCH"]="stable" 116 | VERSION["NUMBER"]="2.0" 117 | VERSION["BUILDDATE"]="[2025-05-24]" 118 | VERSION["STRING"]="v${VERSION["NUMBER"]} ${VERSION["BRANCH"]}" 119 | 120 | credits() { 121 | echo -e "${COLOR_MAGENTA_B}Priism credits" 122 | echo -e "${COLOR_BLUE_B}xmb9${COLOR_RESET}: Pioneering the creation of this tool" 123 | echo -e "${COLOR_MAGENTA_B}Mercury Workshop${COLOR_RESET}: Finding the SH1MMER exploit" 124 | echo -e "${COLOR_MAGENTA_B}OlyB${COLOR_RESET}: Help with adapting wax to Priism and PID1" 125 | echo -e "${COLOR_MAGENTA_B}kxtzownsu${COLOR_RESET}: Help with sed syntax" 126 | echo -e "${COLOR_RED_B}Simon${COLOR_RESET}: Testing Priism and building the very first shims" 127 | echo -e "${COLOR_YELLOW_B}Darkn${COLOR_RESET}: Hosting shims" 128 | echo -e " " 129 | read -p "Press enter to continue." 130 | clear 131 | splash 132 | } 133 | 134 | splash 135 | echo -e "${COLOR_YELLOW_B}Priism is currently in active development. Please report any issues you find.${COLOR_RESET}\n" 136 | 137 | read -p "Press enter to continue." 138 | 139 | mkdir /mnt/priism 140 | mkdir /mnt/new_root 141 | mkdir /mnt/shimroot 142 | mkdir /mnt/recoroot 143 | 144 | 145 | # Wow. Just wow. 146 | # Why didn't I think of any of this before. 147 | priism_images="/dev/disk/by-label/PRIISM_IMAGES" 148 | 149 | board_name="$(cat /sys/devices/virtual/dmi/id/board_name | head -n 1)" 150 | if ! [ $? -eq 0 ]; then 151 | echo -e "${COLOR_YELLOW_B}Board name detection failed. This isn't that big of an issue.${COLOR_RESET}" 152 | board_name="" 153 | fi 154 | 155 | source /etc/lsb-release 2&> /dev/null 156 | 157 | mount $priism_images /mnt/priism || fail "Failed to mount PRIISM_IMAGES partition!" 158 | 159 | if [ ! -z "$(ls -A /mnt/priism/.IMAGES_NOT_YET_RESIZED 2> /dev/null)" ]; then # this janky shit is the only way it works. idk why. 160 | echo -e "${COLOR_YELLOW}Priism needs to resize your images partition!${COLOR_RESET}" 161 | 162 | read -p "Press enter to continue." 163 | 164 | echo -e "${COLOR_GREEN}Info: Growing PRIISM_IMAGES partition${COLOR_RESET}" 165 | 166 | umount $priism_images 167 | 168 | growpart $priism_images # growpart. why. why didn't you have to be different. 169 | e2fsck -f $priism_images 170 | 171 | echo -e "${COLOR_GREEN}Info: Resizing filesystem (This operation may take a while, do not panic if it looks stuck!)${COLOR_RESET}" 172 | 173 | resize2fs -p $priism_images || fail "Failed to resize filesystem on ${priism_images}!" 174 | 175 | echo -e "${COLOR_GREEN}Done. Remounting partition...${COLOR_RESET}" 176 | 177 | mount $priism_images /mnt/priism 178 | rm -rf /mnt/priism/.IMAGES_NOT_YET_RESIZED 179 | sync 180 | fi 181 | 182 | chmod 777 /mnt/priism/* 183 | 184 | recochoose=(/mnt/priism/recovery/*) 185 | shimchoose=(/mnt/priism/shims/*) 186 | selpayload=(/mnt/priism/payloads/*.sh) 187 | 188 | NEWROOT_MNT=/mnt/shimroot 189 | STATEFUL_MNT=/stateful 190 | 191 | export_args() { 192 | # We trust our kernel command line explicitly. 193 | local arg= 194 | local key= 195 | local val= 196 | local acceptable_set='[A-Za-z0-9]_' 197 | echo "Exporting kernel arguments..." 198 | for arg in "$@"; do 199 | key=$(echo "${arg%%=*}" | busybox tr 'a-z' 'A-Z' | \ 200 | busybox tr -dc "$acceptable_set" '_') 201 | val="${arg#*=}" 202 | export "KERN_ARG_$key"="$val" 203 | echo -n " KERN_ARG_$key=$val," 204 | done 205 | echo "" 206 | } 207 | 208 | export_args $(cat /proc/cmdline | sed -e 's/"[^"]*"/DROPPED/g') 1> /dev/null 209 | 210 | copy_lsb() { 211 | echo "Copying lsb..." 212 | 213 | local lsb_file="dev_image/etc/lsb-factory" 214 | local dest_path="${NEWROOT_MNT}/mnt/stateful_partition/${lsb_file}" 215 | local src_path="${STATEFUL_MNT}/${lsb_file}" 216 | 217 | mkdir -p "$(dirname "${dest_path}")" 218 | 219 | local ret=0 220 | if [ -f "${src_path}" ]; then 221 | # Convert kern_guid to uppercase and store extra info 222 | local kern_guid=$(echo "${KERN_ARG_KERN_GUID}" | tr '[:lower:]' '[:upper:]') 223 | echo "Found ${src_path}" 224 | cp -a "${src_path}" "${dest_path}" 225 | echo "REAL_USB_DEV=${loop}p3" >>"${dest_path}" 226 | echo "KERN_ARG_KERN_GUID=${kern_guid}" >>"${dest_path}" 227 | else 228 | echo "Failed to find ${src_path}!!" 229 | ret=1 230 | fi 231 | return "${ret}" 232 | } 233 | 234 | pv_dircopy() { 235 | [ -d "$1" ] || return 1 236 | local apparent_bytes 237 | apparent_bytes=$(du -sb "$1" | cut -f 1) 238 | mkdir -p "$2" 239 | tar -cf - -C "$1" . | pv -f -s "${apparent_bytes:-0}" | tar -xf - -C "$2" 240 | } 241 | 242 | shimboot() { 243 | if [[ -z "$(ls -A /mnt/priism/shims)" ]]; then 244 | echo -e "${COLOR_YELLOW_B}You have no shims downloaded!\nPlease download a few images for your board ${board_name} (${CHROMEOS_RELEASE_BOARD}) into the shims folder on PRIISM_IMAGES!" 245 | echo -e "If you have a computer running Windows, use Ext4Fsd or this chrome device. If you have a Mac, use this chrome device to download images instead.${COLOR_RESET}\n" 246 | shim="Exit" 247 | else 248 | echo -e "Choose the shim you want to boot:" 249 | select FILE in "${shimchoose[@]}" "Exit"; do 250 | if [[ -n "$FILE" ]]; then 251 | shim=$FILE 252 | break 253 | elif [[ $FILE == "Exit" ]]; then 254 | shim=$FILE 255 | break 256 | fi 257 | done 258 | fi 259 | 260 | if [[ $shim == "Exit" ]]; then 261 | read -p "Press enter to continue." 262 | clear 263 | else 264 | mkdir -p $shimroot 265 | echo -e "Searching for ROOT-A on shim..." 266 | loop=$(losetup -fP --show $shim) 267 | export loop 268 | 269 | loop_root="$(cgpt find -l ROOT-A $loop || cgpt find -t rootfs $loop)" 270 | loop_root="$(echo $loop_root | head -n 1)" # there's probably way better ways to do this but i'm lazy 271 | loop_root="$(echo $loop_root | awk '{print $1}')" 272 | 273 | if mount "${loop_root}" $shimroot; then 274 | echo -e "ROOT-A found successfully and mounted." 275 | else 276 | result=$? 277 | err1="Mount process failed! Exit code was ${result}.\n" 278 | err2=" This may be a bug! Please check your shim,\n" 279 | err3=" and if it looks fine, report it to the GitHub repo!\n" 280 | fail "${err1}${err2}${err3}" 281 | fi 282 | unpatched_shimboot=0 283 | if cat /mnt/shimroot/sbin/bootstrap.sh | grep "│ Shimboot OS Selector" --quiet; then 284 | echo -e "${COLOR_YELLOW_B}Shimboot (unpatched) detected. Please use shimboot-priism.${COLOR_RESET}" 285 | umount /mnt/shimroot 286 | losetup -D 287 | unpatched_shimboot=1 288 | read -p "Press enter to continue." 289 | clear 290 | return 291 | elif cat /mnt/shimroot/sbin/bootstrap.sh | grep "│ Priishimboot OS Selector" --quiet; then 292 | echo -e "${COLOR_GREEN}Priishimboot detected.${COLOR_RESET}" 293 | if ! cgpt find -l "shimboot_rootfs:priism" > /dev/null; then 294 | echo -e "${COLOR_YELLOW_B}Please use Priishimbooter before booting!${COLOR_RESET}" 295 | umount /mnt/shimroot 296 | losetup -D 297 | unpatched_shimboot=1 298 | read -p "Press enter to continue." 299 | clear 300 | return 301 | fi 302 | fi 303 | if cat /mnt/shimroot/usr/sbin/sh1mmer_main.sh | grep "Portable recovery image installer/shim manager" --quiet; then 304 | echo -e "${COLOR_YELLOW_B}$(detect_priism_in_shimboot_function)${COLOR_RESET}" 305 | losetup -D 306 | read -p "Press enter to continue." 307 | clear 308 | return 309 | fi 310 | if ! stateful="$(cgpt find -l STATE ${loop} | head -n 1 | grep --color=never /dev/)"; then 311 | echo -e "${COLOR_YELLOW_B}Finding stateful via partition label \"STATE\" failed (try 1...)${COLOR_RESET}" 312 | if ! stateful="$(cgpt find -l SH1MMER ${loop} | head -n 1 | grep --color=never /dev/)"; then 313 | echo -e "${COLOR_YELLOW_B}Finding stateful via partition label \"SH1MMER\" failed (try 2...)${COLOR_RESET}" 314 | 315 | for dev in "$loop"*; do 316 | [[ -b "$dev" ]] || continue 317 | parttype=$(udevadm info --query=property --name="$dev" 2>/dev/null | grep '^ID_PART_ENTRY_TYPE=' | cut -d= -f2) 318 | if [ "$parttype" = "0fc63daf-8483-4772-8e79-3d69d8477de4" ]; then 319 | stateful="$dev" 320 | break 321 | fi 322 | done 323 | fi 324 | fi 325 | if [[ -z "${stateful// }" ]]; then 326 | echo -e "${COLOR_RED_B}Finding stateful via partition type \"Linux data\" failed! (try 3...)${COLOR_RESET}" 327 | echo -e "Last resort (try 4...)" 328 | stateful="${loop}p1" 329 | fi 330 | 331 | if (( $unpatched_shimboot == 0 )); then 332 | mkdir -p /stateful 333 | mkdir -p /newroot 334 | 335 | mount -t tmpfs tmpfs /newroot -o "size=1024M" || fail "Could not allocate 1GB of TMPFS to the newroot mountpoint." 336 | mount $stateful /stateful || fail "Failed to mount stateful partition!" 337 | 338 | copy_lsb 339 | 340 | echo "Copying rootfs to ram." 341 | pv_dircopy "$shimroot" /newroot 342 | 343 | echo "Moving mounts..." 344 | mkdir -p "/newroot/dev" "/newroot/proc" "/newroot/sys" "/newroot/tmp" "/newroot/run" 345 | mount -t tmpfs -o mode=1777 none /newroot/tmp 346 | mount -t tmpfs -o mode=0555 run /newroot/run 347 | mkdir -p -m 0755 /newroot/run/lock 348 | 349 | umount -l /dev/pts 350 | umount -f /dev/pts 351 | 352 | mounts=("/dev" "/proc" "/sys") 353 | for mnt in "${mounts[@]}"; do 354 | mount --move "$mnt" "/newroot$mnt" 355 | umount -l "$mnt" 356 | done 357 | 358 | echo "Done." 359 | echo "About to switch root. If your screen goes black and the device reboots, it may be a bug. Please make a GitHub issue if you're sure your shim isn't corrupted." 360 | sleep 1 361 | echo "Switching root!" 362 | clear 363 | 364 | mkdir -p /newroot/tmp/priism 365 | pivot_root /newroot /newroot/tmp/priism 366 | 367 | echo "Starting init" 368 | if [ -f "/bin/kvs" ]; then 369 | exec /bin/kvs 370 | fi 371 | 372 | exec /sbin/init || { 373 | echo "Failed to start init!!!" 374 | echo "Bailing out, you are on your own. Good luck." 375 | echo "This shell has PID 1. Exit = panic." 376 | /tmp/priism/bin/uname -a 377 | exec /tmp/priism/bin/sh 378 | } 379 | fi 380 | fi 381 | } 382 | 383 | 384 | installcros() { 385 | if [[ -z "$(ls -A /mnt/priism/recovery)" ]]; then 386 | echo -e "${COLOR_YELLOW_B}You have no recovery images downloaded!\nPlease download a few images for your board ${board_name} (${CHROMEOS_RELEASE_BOARD}) into the recovery folder on PRIISM_IMAGES!" 387 | echo -e "These are available on websites such as chrome100.dev, or cros.tech." 388 | echo -e "Chrome100 hosts old and new recovery images, whereas cros.tech only hosts the latest images." 389 | echo -e "If you have a computer running Windows, use Ext4Fsd or this chrome device. If you have a Mac, use this chrome device to download images instead.${COLOR_RESET}\n" 390 | reco="Exit" 391 | else 392 | echo -e "Choose the image you want to flash:" 393 | select FILE in "${recochoose[@]}" "Exit"; do 394 | if [[ -n "$FILE" ]]; then 395 | reco=$FILE 396 | break 397 | elif [[ $FILE == "Exit" ]]; then 398 | reco=$FILE 399 | break 400 | fi 401 | done 402 | fi 403 | 404 | if [[ $reco == "Exit" ]]; then 405 | read -p "Press enter to continue." 406 | clear 407 | else 408 | mkdir -p $recoroot 409 | echo -e "Searching for ROOT-A on reco image..." 410 | loop=$(losetup -fP --show $reco) 411 | loop_root="$(cgpt find -l ROOT-A $loop | head -n 1)" # Usually the 3rd partition is always the "real" ROOT-A 412 | if mount -r "${loop_root}" $recoroot ; then 413 | echo -e "ROOT-A found successfully and mounted." 414 | else 415 | result=$? 416 | err1="Mount process failed! Exit code was ${result}.\n" 417 | err2=" This may be a bug! Please check your recovery image,\n" 418 | err3=" and if it looks fine, report it to the GitHub repo!\n" 419 | fail "${err1}${err2}${err3}" 420 | fi 421 | stateful="$(cgpt find -l STATE ${loop} | head -n 1 | grep --color=never /dev/)" || fail "Failed to find stateful partition on ${loop}!" 422 | mount $stateful /mnt/stateful_partition || fail "Failed to mount stateful partition!" 423 | MOUNTS="/proc /dev /sys /tmp /run /var /mnt/stateful_partition" 424 | cd /mnt/recoroot/ 425 | d= 426 | for d in ${MOUNTS}; do 427 | mount -n --bind "${d}" "./${d}" 428 | mount --make-slave "./${d}" 429 | done 430 | local cros_dev="$(get_largest_cros_blockdev)" 431 | if [ -z "$cros_dev" ]; then 432 | echo -e "${COLOR_YELLOW_B}No ChromeOS drive was found on the device! Please make sure ChromeOS is installed before using Priism. Continuing anyway...${COLOR_RESET}" 433 | fi 434 | export IS_RECOVERY_INSTALL=1 435 | chroot ./ /usr/sbin/chromeos-install --payload_image="${loop}" --yes || fail "Failed during chroot!" 436 | # Juusst in case. 437 | cgpt add -i 2 $cros_dev -P 15 -T 15 -S 1 -R 1 || echo -e "${COLOR_YELLOW_B}Failed to set kernel priority! Continuing anyway.${COLOR_RESET}" 438 | echo -e "${COLOR_GREEN}\n" 439 | read -p "Recovery finished. Press any key to reboot." 440 | reboot 441 | sleep 1 442 | echo -e "\n${COLOR_RED_B}Reboot failed. Hanging..." 443 | hang 444 | fi 445 | } 446 | 447 | rebootdevice() { 448 | if [[ releaseBuild -eq 1 ]]; then 449 | echo -e "Rebooting..." 450 | sync 451 | reboot -f 452 | sleep 1 453 | echo -e "${COLOR_RED_B}Reboot failed. Hanging..." 454 | hang 455 | else 456 | echo -e "Use the bash shell to reboot." 457 | fi 458 | read -p "Press enter to continue." 459 | clear 460 | } 461 | 462 | shutdowndevice() { 463 | if [[ releaseBuild -eq 1 ]]; then 464 | echo -e "Shutting down..." 465 | sync 466 | poweroff -f 467 | sleep 1 468 | echo -e "${COLOR_RED_B}Shutdown failed. Hanging..." 469 | hang 470 | else 471 | echo -e "Use the bash shell to shutdown." 472 | fi 473 | read -p "Press enter to continue." 474 | clear 475 | } 476 | 477 | exitdebug() { 478 | if [[ releaseBuild -eq 0 ]]; then 479 | echo -e "${COLOR_YELLOW_B}Exit is only meant to be used when" 480 | echo -e "testing Priism outside of shims!" 481 | echo -e "Are you sure you want to do this?${COLOR_RESET}" 482 | read -p "(y/n) >" exitask 483 | if [[ $exitask == "y" ]]; then 484 | umount /mnt/recoroot > /dev/null 485 | umount /mnt/shimroot > /dev/null 486 | umount /mnt/new_root > /dev/null 487 | umount /mnt/priism > /dev/null 488 | losetup -D > /dev/null 489 | rm -rf /mnt/recoroot 490 | rm -rf /mnt/priism 491 | rm -rf /mnt/shimroot 492 | rm -rf /mnt/new_root 493 | exit 494 | else 495 | echo -e "Cancelled." 496 | fi 497 | else 498 | echo -e "This option is only available on debug builds." 499 | fi 500 | read -p "Press enter to continue." 501 | clear 502 | } 503 | 504 | payloads() { 505 | echo -e "Choose payload to run:" 506 | select FILE in "${selpayload[@]}" "Exit"; do 507 | if [[ -n "$FILE" ]]; then 508 | payload=$FILE 509 | break 510 | elif [[ "$FILE" == "Exit" ]]; then 511 | payload=$FILE 512 | break 513 | fi 514 | done 515 | if [[ $payload == "Exit" ]]; then 516 | read -p "Press enter to continue." 517 | clear 518 | else 519 | source $payload 520 | read -p "Press enter to continue." 521 | clear 522 | fi 523 | } 524 | 525 | changelog() { 526 | cat /changelog.txt | busybox less 527 | read -p "Press enter to continue." 528 | clear 529 | } 530 | 531 | if [[ releaseBuild -eq 1 ]]; then 532 | OPTIONS=$'Bash shell\nBoot an RMA shim\nInstall a ChromeOS recovery image\nPayloads\nCredits\nChangelog\nReboot\nPower off' 533 | else 534 | OPTIONS=$'Bash shell\nBoot an RMA shim\nInstall a ChromeOS recovery image\nPayloads\nCredits\nChangelog\nReboot\nPower off\nExit [Debug]' 535 | fi 536 | 537 | while true; do 538 | shmenu -o "$OPTIONS" -p "Main menu - Priism [${VERSION[STRING]}] - $(funTextbutGay)" 539 | option=$(cat /tmp/shmenu_choice) 540 | clear 541 | case "$option" in 542 | "Bash shell") bash ;; 543 | "Boot an RMA shim") shimboot ;; 544 | "Install a ChromeOS recovery image") installcros ;; 545 | "Payloads") payloads ;; 546 | "Credits") credits ;; 547 | "Changelog") changelog ;; 548 | "Reboot") rebootdevice ;; 549 | "Power off") shutdowndevice ;; 550 | "Exit [Debug]") exitdebug ;; 551 | *) echo -e "You entered an invalid option (${option})... Somehow."; sleep 1 ;; 552 | esac 553 | echo -e "" 554 | done 555 | -------------------------------------------------------------------------------- /rootfs/usr/sbin/growpart: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright (C) 2011 Canonical Ltd. 3 | # Copyright (C) 2013 Hewlett-Packard Development Company, L.P. 4 | # 5 | # Authors: Scott Moser 6 | # Juerg Haefliger 7 | # 8 | # This program is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, version 3 of the License. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | # Modified 2025 by soap phia 20 | 21 | # the fudge factor. if within this many bytes dont bother 22 | FUDGE=${GROWPART_FUDGE:-$((1024*1024))} 23 | TEMP_D="" 24 | RESTORE_FUNC="" 25 | RESTORE_HUMAN="" 26 | VERBOSITY=0 27 | DISK="" 28 | PART="" 29 | PT_UPDATE=false 30 | DRY_RUN=0 31 | FLOCK_DISK_FD="" 32 | RESIZE_RESULT="" 33 | 34 | SFDISK_VERSION="" 35 | SFDISK_2_26="22600" 36 | SFDISK_V_WORKING_GPT="22603" 37 | MBR_BACKUP="" 38 | GPT_BACKUP="" 39 | _capture="" 40 | 41 | error() { 42 | echo "$@" 1>&2 43 | } 44 | 45 | fail() { 46 | [ $# -eq 0 ] || echo "FAILED:" "$@" 47 | exit 2 48 | } 49 | 50 | nochange() { 51 | RESIZE_RESULT="NOCHANGE" 52 | echo "NOCHANGE:" "$@" 53 | return 1 54 | } 55 | 56 | changed() { 57 | RESIZE_RESULT="CHANGED" 58 | echo "CHANGED:" "$@" 59 | return 0 60 | } 61 | 62 | change() { 63 | RESIZE_RESULT="CHANGE" 64 | echo "CHANGE:" "$@" 65 | return 0 66 | } 67 | 68 | cleanup() { 69 | if [ -n "${RESTORE_FUNC}" ]; then 70 | error "***** WARNING: Resize failed, attempting to revert ******" 71 | if ${RESTORE_FUNC} ; then 72 | error "***** Restore appears to have gone OK ****" 73 | else 74 | error "***** Restore FAILED! ******" 75 | if [ -n "${RESTORE_HUMAN}" -a -f "${RESTORE_HUMAN}" ]; then 76 | error "**** original table looked like: ****" 77 | cat "${RESTORE_HUMAN}" 1>&2 78 | else 79 | error "We seem to have not saved the partition table!" 80 | fi 81 | fi 82 | unlock_disk_and_settle $DISK 83 | fi 84 | [ -z "${TEMP_D}" -o ! -d "${TEMP_D}" ] || rm -Rf "${TEMP_D}" 85 | } 86 | 87 | debug() { 88 | local level=${1} 89 | shift 90 | [ "${level}" -gt "${VERBOSITY}" ] && return 91 | if [ "${DEBUG_LOG}" ]; then 92 | echo "$@" >>"${DEBUG_LOG}" 93 | else 94 | error "$@" 95 | fi 96 | } 97 | 98 | debugcat() { 99 | local level="$1" 100 | shift; 101 | [ "${level}" -gt "$VERBOSITY" ] && return 102 | if [ "${DEBUG_LOG}" ]; then 103 | cat "$@" >>"${DEBUG_LOG}" 104 | else 105 | cat "$@" 1>&2 106 | fi 107 | } 108 | 109 | mktemp_d() { 110 | # just a mktemp -d that doens't need mktemp if its not there. 111 | _RET=$(mktemp -d "${TMPDIR:-/tmp}/${0##*/}.XXXXXX" 2>/dev/null) && 112 | return 113 | _RET=$(umask 077 && t="${TMPDIR:-/tmp}/${0##*/}.$$" && 114 | mkdir "${t}" && echo "${t}") 115 | return 116 | } 117 | 118 | Usage() { 119 | cat <&2 156 | error "$@" 157 | exit 2 158 | } 159 | 160 | lock_disk() { 161 | local disk="$1" 162 | # flock the target disk to protect against udev actions while modifying. 163 | # https://systemd.io/BLOCK_DEVICE_LOCKING/ 164 | [ "${DRY_RUN}" = 0 ] || return 165 | 166 | # only lock block devices, files do not need a lock 167 | [ -b "${disk}" ] || return 168 | 169 | # The FD values are hard-coded per /bin/sh requirement for using exec 170 | # to open paths with specific fd values; man (1) sh on "Redirections" 171 | FLOCK_DISK_FD=9 172 | debug 1 "FLOCK: try exec open fd 9, on failure exec exits this program" 173 | exec 9<>$disk 174 | 175 | # Do not use --nonblock or --timeout as udev may be already processing 176 | # the disk and we must wait until it has released the disk to 177 | # proceed. Failure to obtain exclusive lock is fatal to growpart. 178 | rq flock flock -x $FLOCK_DISK_FD || 179 | fail "Error while obtaining exclusive lock on $DISK" 180 | debug 1 "FLOCK: $disk: obtained exclusive lock" 181 | } 182 | 183 | unlock_disk_and_settle() { 184 | # unlock_disk(disk, settle) 185 | local disk="$1" 186 | local settle=${2-"1"} 187 | # release the lock on a disk if locked. When a disk is locked, 188 | # FLOCK_DISK_FD is set to the hard-coded value of 9. 189 | # After unlocking run udevadm settle (if installed) as the disk has 190 | # likely been changed. 191 | [ "${DRY_RUN}" = 0 ] || return 192 | [ -n "${FLOCK_DISK_FD}" ] || return 193 | 194 | debug 1 "FLOCK: ${disk}: releasing exclusive lock" 195 | exec 9>&- 196 | [ "${settle}" = 1 ] && has_cmd udevadm && udevadm settle 197 | FLOCK_DISK_FD="" 198 | } 199 | 200 | sfdisk_restore_legacy() { 201 | sfdisk --no-reread "${DISK}" -I "${MBR_BACKUP}" 202 | } 203 | 204 | sfdisk_restore() { 205 | # files are named: sfdisk--.bak 206 | local f="" offset="" fails=0 207 | for f in "${MBR_BACKUP}"*.bak; do 208 | [ -f "$f" ] || continue 209 | offset=${f##*-} 210 | offset=${offset%.bak} 211 | [ "$offset" = "$f" ] && { 212 | error "WARN: confused by file $f"; 213 | continue; 214 | } 215 | dd "if=$f" "of=${DISK}" seek=$(($offset)) bs=1 conv=notrunc || 216 | { error "WARN: failed restore from $f"; fails=$(($fails+1)); } 217 | done 218 | return $fails 219 | } 220 | 221 | sfdisk_worked_but_blkrrpart_failed() { 222 | local ret="$1" output="$2" 223 | # exit code found was just 1, but dont insist on that 224 | #[ $ret -eq 1 ] || return 1 225 | # Successfully wrote the new partition table 226 | if grep -qi "Success.* wrote.* new.* partition" "$output"; then 227 | grep -qi "BLKRRPART: Device or resource busy" "$output" 228 | return 229 | # The partition table has been altered. 230 | elif grep -qi "The.* part.* table.* has.* been.* altered" "$output"; then 231 | # Re-reading the partition table failed 232 | grep -qi "Re-reading.* partition.* table.* failed" "$output" 233 | return 234 | fi 235 | return $ret 236 | } 237 | 238 | get_sfdisk_version() { 239 | # set SFDISK_VERSION to MAJOR*10000+MINOR*100+MICRO 240 | local out oifs="$IFS" ver="" 241 | [ -n "$SFDISK_VERSION" ] && return 0 242 | [ -n "$SFDISK" ] || { 243 | SFDISK_VERSION=0 244 | return 0 245 | } 246 | # expected output: sfdisk from util-linux 2.25.2 247 | out=$(LANG=C sfdisk --version) || 248 | { error "failed to get sfdisk version"; return 1; } 249 | set -- $out 250 | ver=$4 251 | case "$ver" in 252 | [0-9]*.[0-9]*.[0-9]|[0-9].[0-9]*) 253 | IFS="."; set -- $ver; IFS="$oifs" 254 | SFDISK_VERSION=$(($1*10000+$2*100+${3:-0})) 255 | return 0;; 256 | *) error "unexpected output in sfdisk --version [$out]" 257 | return 1;; 258 | esac 259 | } 260 | 261 | get_diskpart_path() { 262 | # get_diskpart_path(disk, part_number) 263 | # return the path to the partition device on disk 264 | # 265 | # Convert inputs disk and part into a path to a partition device path 266 | # handle both block devices or files. 267 | # e.g. get_diskpart_path /dev/loop0 7 returns /dev/loop0p7 268 | local disk="$1" 269 | local part="$2" 270 | local dpart="" 271 | 272 | dpart="${disk}${part}" # disk and partition number 273 | if [ -b "$disk" ]; then 274 | if [ -b "${disk}p${part}" -a "${disk%[0-9]}" != "${disk}" ]; then 275 | # for block devices that end in a number (/dev/nbd0) 276 | # the partition is "p" (/dev/nbd0p1) 277 | dpart="${disk}p${part}" 278 | elif [ "${disk#/dev/loop[0-9]}" != "${disk}" ]; then 279 | # for /dev/loop devices, sfdisk output will be p 280 | # format also, even though there is not a device there. 281 | dpart="${disk}p${part}" 282 | fi 283 | else 284 | case "$disk" in 285 | # sfdisk for files ending in digit to p. 286 | *[0-9]) dpart="${disk}p${part}";; 287 | esac 288 | fi 289 | _RET="$dpart" 290 | } 291 | 292 | resize_sfdisk() { 293 | local humanpt="${TEMP_D}/recovery" 294 | local mbr_backup="${TEMP_D}/orig.save" 295 | local restore_func="" 296 | local format="$1" 297 | 298 | local change_out=${TEMP_D}/change.out 299 | local dump_out=${TEMP_D}/dump.out 300 | local new_out=${TEMP_D}/new.out 301 | local dump_mod=${TEMP_D}/dump.mod 302 | local tmp="${TEMP_D}/tmp.out" 303 | local err="${TEMP_D}/err.out" 304 | local mbr_max_512="4294967296" 305 | 306 | local pt_start pt_size pt_end max_end new_size change_info dpart 307 | local sector_num sector_size disk_size pt_size_bytes tot out 308 | local excess_sectors free_percent_sectors remaining_free_sectors 309 | 310 | LANG=C rqe sfd_list sfdisk --list --unit=S "$DISK" >"$tmp" || 311 | fail "failed: sfdisk --list $DISK" 312 | if [ "${SFDISK_VERSION}" -lt ${SFDISK_2_26} ]; then 313 | # exected output contains: Units: sectors of 512 bytes, ... 314 | out=$(awk '$1 == "Units:" && $5 ~ /bytes/ { print $4 }' "$tmp") || 315 | fail "failed to read sfdisk output" 316 | if [ -z "$out" ]; then 317 | error "WARN: sector size not found in sfdisk output, assuming 512" 318 | sector_size=512 319 | else 320 | sector_size="$out" 321 | fi 322 | local _w _cyl _w1 _heads _w2 sectors _w3 t s 323 | # show-size is in units of 1024 bytes (same as /proc/partitions) 324 | t=$(sfdisk --show-size "${DISK}") || 325 | fail "failed: sfdisk --show-size $DISK" 326 | disk_size=$((t*1024)) 327 | sector_num=$(($disk_size/$sector_size)) 328 | msg="disk size '$disk_size' not evenly div by sector size '$sector_size'" 329 | [ "$((${disk_size}%${sector_size}))" -eq 0 ] || 330 | error "WARN: $msg" 331 | restore_func=sfdisk_restore_legacy 332 | else 333 | # --list first line output: 334 | # Disk /dev/vda: 20 GiB, 21474836480 bytes, 41943040 sectors 335 | local _x 336 | read _x _x _x _x disk_size _x sector_num _x < "$tmp" 337 | sector_size=$((disk_size/$sector_num)) 338 | restore_func=sfdisk_restore 339 | fi 340 | 341 | debug 1 "$sector_num sectors of $sector_size. total size=${disk_size} bytes" 342 | 343 | rqe sfd_dump sfdisk --unit=S --dump "${DISK}" >"${dump_out}" || 344 | fail "failed to dump sfdisk info for ${DISK}" 345 | RESTORE_HUMAN="$dump_out" 346 | 347 | { 348 | echo "## sfdisk --unit=S --dump ${DISK}" 349 | cat "${dump_out}" 350 | } >"$humanpt" 351 | 352 | [ $? -eq 0 ] || fail "failed to save sfdisk -d output" 353 | RESTORE_HUMAN="$humanpt" 354 | 355 | debugcat 1 "$humanpt" 356 | 357 | sed -e 's/,//g; s/start=/start /; s/size=/size /' "${dump_out}" \ 358 | >"${dump_mod}" || 359 | fail "sed failed on dump output" 360 | 361 | get_diskpart_path $DISK $PART 362 | dpart="$_RET" 363 | 364 | pt_start=$(awk '$1 == pt { print $4 }' "pt=${dpart}" <"${dump_mod}") && 365 | pt_size=$(awk '$1 == pt { print $6 }' "pt=${dpart}" <"${dump_mod}") && 366 | [ -n "${pt_start}" -a -n "${pt_size}" ] && 367 | pt_end=$((${pt_size} + ${pt_start} - 1)) || 368 | fail "failed to get start and end for ${dpart} in ${DISK}" 369 | 370 | # find the minimal starting location that is >= pt_end 371 | max_end=$(awk '$3 == "start" { if($4 >= pt_end && $4 < min) 372 | { min = $4 } } END { printf("%s\n",min); }' \ 373 | min=${sector_num} pt_end=${pt_end} "${dump_mod}") && 374 | [ -n "${max_end}" ] || 375 | fail "failed to get max_end for partition ${PART}" 376 | # As sector numbering starts from 0 need to reduce value by 1. 377 | max_end=$((max_end - 1)) 378 | 379 | if [ "$format" = "gpt" ]; then 380 | # sfdisk respects 'last-lba' in input, and complains about 381 | # partitions that go past that. without it, it does the right thing. 382 | sed -i '/^last-lba:/d' "$dump_out" || 383 | fail "failed to remove last-lba from output" 384 | fi 385 | if [ "$format" = "dos" ]; then 386 | mbr_max_sectors=$((mbr_max_512*$((sector_size/512)))) 387 | if [ "$max_end" -gt "$mbr_max_sectors" ]; then 388 | max_end=$mbr_max_sectors 389 | fi 390 | [ $(($disk_size/512)) -gt $mbr_max_512 ] && 391 | debug 0 "WARNING: MBR/dos partitioned disk is larger than 2TB." \ 392 | "Additional space will go unused." 393 | fi 394 | 395 | local gpt_second_size="33" 396 | if [ "${max_end}" -gt "$((${sector_num}-${gpt_second_size}))" ]; then 397 | # if MBR, allow subsequent conversion to GPT without shrinking 398 | # the partition and safety net at cost of 33 sectors seems 399 | # reasonable. If GPT, we can't write there anyway. 400 | debug 1 "padding ${gpt_second_size} sectors for gpt secondary header" 401 | max_end=$((${sector_num} - ${gpt_second_size} - 1)) 402 | fi 403 | 404 | if [ -n "${free_percent}" ]; then 405 | free_percent_sectors=$((sector_num/100*free_percent)) 406 | 407 | if [ "$format" = "dos" ]; then 408 | if [ $(($disk_size/512)) -ge $((mbr_max_512+free_percent_sectors)) ]; then 409 | # If MBR partitioned disk larger than 2TB and 410 | # remaining space over 2TB boundary is greater 411 | # than the requested overprovisioning sectors 412 | # then do not change max_end. 413 | debug 1 "WARNING: Additional unused space on MBR/dos partitioned disk" \ 414 | "is larger than requested percent of overprovisioning." 415 | elif [ $sector_num -gt $mbr_max_512 ]; then 416 | # If only some of the overprovisioning sectors 417 | # are over the 2TB boundary then reduce max_end 418 | # by the remaining number of overprovisioning 419 | # sectors. 420 | excess_sectors=$((sector_num-mbr_max_512)) 421 | remaining_free_sectors=$((free_percent_sectors - excess_sectors)) 422 | debug 1 "reserving ${remaining_free_sectors} sectors from MBR maximum for overprovisioning" 423 | max_end=$((max_end - remaining_free_sectors)) 424 | else 425 | # Shrink max_end to keep X% of whole disk unused 426 | # (for overprovisioning). 427 | debug 1 "reserving ${free_percent_sectors} sectors (${free_percent}%) for overprovisioning" 428 | max_end=$((max_end-free_percent_sectors)) 429 | fi 430 | 431 | if [ ${max_end} -lt ${pt_end} ]; then 432 | nochange "partition ${PART} could not be grown while leaving" \ 433 | "${free_percent}% (${free_percent_sectors} sectors) free on device" 434 | return 435 | fi 436 | else 437 | # Shrink max_end to keep X% of whole disk unused 438 | # (for overprovisioning). 439 | debug 1 "reserving ${free_percent_sectors} sectors (${free_percent}%) for overprovisioning" 440 | max_end=$((max_end-free_percent_sectors)) 441 | 442 | if [ ${max_end} -lt ${pt_end} ]; then 443 | nochange "partition ${PART} could not be grown while leaving" \ 444 | "${free_percent}% (${free_percent_sectors} sectors) free on device" 445 | return 446 | fi 447 | fi 448 | fi 449 | 450 | pt_size_bytes=$((${pt_size}*${sector_size})) 451 | 452 | debug 1 "max_end=${max_end} tot=${sector_num} pt_end=${pt_end}" \ 453 | "pt_start=${pt_start} pt_size=${pt_size} pt_size_bytes=${pt_size_bytes}" 454 | [ $((${pt_end})) -eq ${max_end} ] && { 455 | nochange "partition ${PART} size is ${pt_size_bytes} bytes (${pt_size} sectors of ${sector_size}). it cannot be grown" 456 | return 457 | } 458 | [ $((${pt_end}+(${FUDGE}/$sector_size))) -gt ${max_end} ] && { 459 | nochange "partition ${PART} could only be grown by" \ 460 | "$((${max_end}-${pt_end})) [fudge=$((${FUDGE}/$sector_size))]" 461 | return 462 | } 463 | 464 | # Now, change the size for this partition in ${dump_out} to be the 465 | # new size. 466 | new_size=$((${max_end} - ${pt_start} + 1)) 467 | sed "\|^\s*${dpart} |s/\(.*\)${pt_size},/\1${new_size},/" "${dump_out}" \ 468 | >"${new_out}" || 469 | fail "failed to change size in output" 470 | 471 | change_info="partition=${PART} start=${pt_start}" 472 | change_info="${change_info} old: size=${pt_size} end=${pt_end}" 473 | change_info="${change_info} new: size=${new_size} end=${max_end}" 474 | if [ ${DRY_RUN} -ne 0 ]; then 475 | echo "CHANGE: ${change_info}" 476 | { 477 | echo "# === old sfdisk -d ===" 478 | cat "${dump_out}" 479 | echo "# === new sfdisk -d ===" 480 | cat "${new_out}" 481 | } 1>&2 482 | exit 0 483 | fi 484 | 485 | MBR_BACKUP="${mbr_backup}" 486 | LANG=C sfdisk --no-reread "${DISK}" --force \ 487 | -O "${mbr_backup}" <"${new_out}" >"${change_out}" 2>&1 488 | ret=$? 489 | [ $ret -eq 0 ] || RESTORE_FUNC="${restore_func}" 490 | 491 | if [ $ret -eq 0 ]; then 492 | debug 1 "resize of ${DISK} returned 0." 493 | if [ $VERBOSITY -gt 2 ]; then 494 | sed 's,^,| ,' "${change_out}" 1>&2 495 | fi 496 | elif $PT_UPDATE && 497 | sfdisk_worked_but_blkrrpart_failed "$ret" "${change_out}"; then 498 | # if the command failed, but it looks like only because 499 | # the device was busy and we have pt_update, then go on 500 | debug 1 "sfdisk failed, but likely only because of blkrrpart" 501 | else 502 | error "attempt to resize ${DISK} failed. sfdisk output below:" 503 | sed 's,^,| ,' "${change_out}" 1>&2 504 | fail "failed to resize" 505 | fi 506 | 507 | rq pt_update pt_update "$DISK" "$PART" || 508 | fail "pt_resize failed" 509 | 510 | RESTORE_FUNC="" 511 | 512 | changed "${change_info}" 513 | return 514 | 515 | # dump_out looks something like: 516 | ## partition table of /tmp/out.img 517 | #unit: sectors 518 | # 519 | #/tmp/out.img1 : start= 1, size= 48194, Id=83 520 | #/tmp/out.img2 : start= 48195, size= 963900, Id=83 521 | #/tmp/out.img3 : start= 1012095, size= 305235, Id=82 522 | #/tmp/out.img4 : start= 1317330, size= 771120, Id= 5 523 | #/tmp/out.img5 : start= 1317331, size= 642599, Id=83 524 | #/tmp/out.img6 : start= 1959931, size= 48194, Id=83 525 | #/tmp/out.img7 : start= 2008126, size= 80324, Id=83 526 | } 527 | 528 | gpt_restore() { 529 | sgdisk -l "${GPT_BACKUP}" "${DISK}" 530 | } 531 | 532 | resize_sgdisk() { 533 | GPT_BACKUP="${TEMP_D}/pt.backup" 534 | 535 | local pt_info="${TEMP_D}/pt.info" 536 | local pt_pretend="${TEMP_D}/pt.pretend" 537 | local pt_data="${TEMP_D}/pt.data" 538 | local out="${TEMP_D}/out" 539 | 540 | local dev="disk=${DISK} partition=${PART}" 541 | 542 | local pt_start pt_end pt_size last pt_max code guid name new_size 543 | local old new change_info sector_size pt_size_bytes 544 | 545 | # Dump the original partition information and details to disk. This is 546 | # used in case something goes wrong and human interaction is required 547 | # to revert any changes. 548 | rqe sgd_info sgdisk "--info=${PART}" --print "${DISK}" >"${pt_info}" || 549 | fail "${dev}: failed to dump original sgdisk info" 550 | RESTORE_HUMAN="${pt_info}" 551 | 552 | # support reading old format (<1.0.2) 553 | # Logical sector size: bytes 554 | # and newer format >= 1.0.2 555 | # Sector size (logical): bytes 556 | # Sector size (logical/physical): / bytes 557 | sector_size=$(awk ' 558 | $0 ~ /^Logical sector size:.*bytes/ { print $4; exit(0); } 559 | $0 ~ /^Sector size \(logical\):/ { print $4; exit(0); } 560 | $0 ~ /^Sector size \(logical\/physical\):/ { 561 | sub(/\/.*/, "", $4); print $4; exit(0); }' \ 562 | "$pt_info") && [ -n "$sector_size" ] || { 563 | sector_size=512 564 | error "WARN: did not find sector size, assuming 512" 565 | } 566 | 567 | debug 1 "$dev: original sgdisk info:" 568 | debugcat 1 "${pt_info}" 569 | 570 | # Pretend to move the backup GPT header to the end of the disk and dump 571 | # the resulting partition information. We use this info to determine if 572 | # we have to resize the partition. 573 | rqe sgd_pretend sgdisk --pretend --move-second-header \ 574 | --print "${DISK}" >"${pt_pretend}" || 575 | fail "${dev}: failed to dump pretend sgdisk info" 576 | 577 | debug 1 "$dev: pretend sgdisk info" 578 | debugcat 1 "${pt_pretend}" 579 | 580 | # Extract the partition data from the pretend dump 581 | awk 'found { print } ; $1 == "Number" { found = 1 }' \ 582 | "${pt_pretend}" >"${pt_data}" || 583 | fail "${dev}: failed to parse pretend sgdisk info" 584 | 585 | # Get the start and end sectors of the partition to be grown 586 | pt_start=$(awk '$1 == '"${PART}"' { print $2 }' "${pt_data}") && 587 | [ -n "${pt_start}" ] || 588 | fail "${dev}: failed to get start sector" 589 | pt_end=$(awk '$1 == '"${PART}"' { print $3 }' "${pt_data}") && 590 | [ -n "${pt_end}" ] || 591 | fail "${dev}: failed to get end sector" 592 | # Start and end are inclusive, start 2048 end 2057 is length 10. 593 | pt_size="$((${pt_end} - ${pt_start} + 1))" 594 | 595 | # Get the last usable sector 596 | last=$(awk '/last usable sector is/ { print $NF }' \ 597 | "${pt_pretend}") && [ -n "${last}" ] || 598 | fail "${dev}: failed to get last usable sector" 599 | 600 | # Find the maximal end sector that is >= pt_end 601 | pt_max=$(awk '{ if ($2 >= pt_end && $2 < min) { min = $2 } } END \ 602 | { print min-1 }' min="${last}" pt_end="${pt_end}" \ 603 | "${pt_data}") && [ -n "${pt_max}" ] || 604 | fail "${dev}: failed to find max end sector" 605 | 606 | pt_size_bytes=$((${pt_size}*${sector_size})) 607 | 608 | debug 1 "${dev}: pt_start=${pt_start} pt_end=${pt_end}" \ 609 | "pt_size=${pt_size} pt_max=${pt_max} last=${last} pt_size_bytes=${pt_size_bytes}" 610 | 611 | # Check if the partition can be grown 612 | [ "${pt_end}" -eq "${pt_max}" ] && { 613 | nochange "${dev}: size=${pt_size_bytes} bytes (${pt_size} sectors of ${sector_size}), it cannot be grown" 614 | return 615 | } 616 | [ "$((${pt_end} + ${FUDGE}/${sector_size}))" -gt "${pt_max}" ] && { 617 | nochange "${dev}: could only be grown by" \ 618 | "$((${pt_max} - ${pt_end})) [fudge=$((${FUDGE}/$sector_size))]" 619 | return 620 | } 621 | 622 | # The partition can be grown if we made it here. Get some more info 623 | # about it so we can do it properly. 624 | # FIXME: Do we care about the attribute flags? 625 | code=$(awk '/^Partition GUID code:/ { print $4 }' "${pt_info}") 626 | guid=$(awk '/^Partition unique GUID:/ { print $4 }' "${pt_info}") 627 | name=$(awk '/^Partition name:/ { gsub(/'"'"'/, "") ; \ 628 | if (NF >= 3) print substr($0, index($0, $3)) }' "${pt_info}") 629 | [ -n "${code}" -a -n "${guid}" ] || 630 | fail "${dev}: failed to parse sgdisk details" 631 | 632 | debug 1 "${dev}: code=${code} guid=${guid} name='${name}'" 633 | local wouldrun="" 634 | [ "$DRY_RUN" -ne 0 ] && wouldrun="would-run" 635 | 636 | # Calculate the new size of the partition 637 | new_size=$((${pt_max} - ${pt_start} + 1)) 638 | change_info="partition=${PART} start=${pt_start}" 639 | change_info="${change_info} old: size=${pt_size} end=${pt_end}" 640 | change_info="${change_info} new: size=${new_size} end=${pt_max}" 641 | 642 | # Backup the current partition table, we're about to modify it 643 | rq sgd_backup $wouldrun sgdisk "--backup=${GPT_BACKUP}" "${DISK}" || 644 | fail "${dev}: failed to backup the partition table" 645 | 646 | # Modify the partition table. We do it all in one go (the order is 647 | # important!): 648 | # - move the GPT backup header to the end of the disk 649 | # - delete the partition 650 | # - recreate the partition with the new size 651 | # - set the partition code 652 | # - set the partition GUID 653 | # - set the partition name 654 | rq sgdisk_mod $wouldrun sgdisk --move-second-header "--delete=${PART}" \ 655 | "--new=${PART}:${pt_start}:$((pt_max-1))" \ 656 | "--typecode=${PART}:${code}" \ 657 | "--partition-guid=${PART}:${guid}" \ 658 | "--change-name=${PART}:${name}" "${DISK}" && 659 | rq pt_update $wouldrun pt_update "$DISK" "$PART" || { 660 | RESTORE_FUNC=gpt_restore 661 | fail "${dev}: failed to repartition" 662 | } 663 | 664 | # Dry run 665 | [ "${DRY_RUN}" -ne 0 ] && { 666 | change "${change_info}" 667 | return 668 | } 669 | 670 | changed "${change_info}" 671 | return 672 | } 673 | 674 | kver_to_num() { 675 | local kver="$1" maj min mic 676 | 677 | # Canonicalize the kernel version 678 | kver=${kver%%[!0-9.]*}.0.0 679 | 680 | maj=${kver%%[!0-9]*} 681 | kver=${kver#*.} 682 | min=${kver%%[!0-9]*} 683 | kver=${kver#*.} 684 | mic=${kver%%[!0-9]*} 685 | _RET=$((maj*1000*1000+min*1000+mic)) 686 | } 687 | 688 | kver_cmp() { 689 | local op="$2" n1="" n2="" 690 | kver_to_num "$1" 691 | n1="$_RET" 692 | kver_to_num "$3" 693 | n2="$_RET" 694 | test $n1 $op $n2 695 | } 696 | 697 | rq() { 698 | # runquieterror(label, command) 699 | # gobble stderr of a command unless it errors 700 | local label="$1" ret="" efile="" 701 | efile="$TEMP_D/$label.err" 702 | shift; 703 | 704 | local rlabel="running" 705 | [ "$1" = "would-run" ] && rlabel="would-run" && shift 706 | 707 | local cmd="" x="" 708 | for x in "$@"; do 709 | [ "${x#* }" != "$x" -o "${x#* \"}" != "$x" ] && x="'$x'" 710 | cmd="$cmd $x" 711 | done 712 | cmd=${cmd# } 713 | 714 | debug 2 "${rlabel}[$label][$_capture]" "$cmd" 715 | [ "$rlabel" = "would-run" ] && return 0 716 | 717 | if [ "${_capture}" = "erronly" ]; then 718 | "$@" 2>"$TEMP_D/$label.err" 719 | ret=$? 720 | else 721 | "$@" >"$TEMP_D/$label.err" 2>&1 722 | ret=$? 723 | fi 724 | if [ $ret -ne 0 ]; then 725 | error "failed [$label:$ret]" "$@" 726 | cat "$efile" 1>&2 727 | fi 728 | return $ret 729 | } 730 | 731 | rqe() { 732 | local _capture="erronly" 733 | rq "$@" 734 | } 735 | 736 | verify_ptupdate() { 737 | local input="$1" found="" reason="" kver="" 738 | 739 | # we can always satisfy 'off' 740 | if [ "$input" = "off" ]; then 741 | _RET="false"; 742 | return 0; 743 | fi 744 | 745 | if command -v partx >/dev/null 2>&1; then 746 | local out="" ret=0 747 | out=$(partx --help 2>&1) 748 | ret=$? 749 | if [ $ret -eq 0 ]; then 750 | echo "$out" | grep -q -- --update || { 751 | reason="partx has no '--update' flag in usage." 752 | found="off" 753 | } 754 | else 755 | reason="'partx --help' returned $ret. assuming it is old." 756 | found="off" 757 | fi 758 | else 759 | reason="no 'partx' command" 760 | found="off" 761 | fi 762 | 763 | if [ -z "$found" ]; then 764 | if [ "$(uname)" != "Linux" ]; then 765 | reason="Kernel is not Linux per uname." 766 | found="off" 767 | fi 768 | fi 769 | 770 | if [ -z "$found" ]; then 771 | kver=$(uname -r) || debug 1 "uname -r failed!" 772 | 773 | if ! kver_cmp "${kver-0.0.0}" -ge 3.8.0; then 774 | reason="Kernel '$kver' < 3.8.0." 775 | found="off" 776 | fi 777 | fi 778 | 779 | if [ -z "$found" ]; then 780 | _RET="true" 781 | return 0 782 | fi 783 | 784 | case "$input" in 785 | on) error "$reason"; return 1;; 786 | auto) 787 | _RET="false"; 788 | debug 1 "partition update disabled: $reason" 789 | return 0;; 790 | force) 791 | _RET="true" 792 | error "WARNING: ptupdate forced on even though: $reason" 793 | return 0;; 794 | esac 795 | error "unknown input '$input'"; 796 | return 1; 797 | } 798 | 799 | pt_update() { 800 | local dev="$1" part="$2" update="${3:-$PT_UPDATE}" 801 | if ! $update; then 802 | return 0 803 | fi 804 | # partx only works on block devices (do not run on file) 805 | [ -b "$dev" ] || return 0 806 | partx --update --nr "$part" "$dev" 807 | } 808 | 809 | has_cmd() { 810 | command -v "${1}" >/dev/null 2>&1 811 | } 812 | 813 | resize_sgdisk_gpt() { 814 | resize_sgdisk gpt 815 | } 816 | 817 | resize_sgdisk_dos() { 818 | fail "unable to resize dos label with sgdisk" 819 | } 820 | 821 | resize_sfdisk_gpt() { 822 | resize_sfdisk gpt 823 | } 824 | 825 | resize_sfdisk_dos() { 826 | resize_sfdisk dos 827 | } 828 | 829 | get_table_format() { 830 | local out="" disk="$1" 831 | if has_cmd blkid && blkid -V | grep -q util-linux && 832 | out=$(blkid -o value -s PTTYPE "$disk") && 833 | [ "$out" = "dos" -o "$out" = "gpt" ]; then 834 | _RET="$out" 835 | return 836 | fi 837 | _RET="dos" 838 | if [ -z "$SFDISK" ]; then 839 | out=$(LANG=C sgdisk --print "$disk") || { 840 | error "Could not determine partition table format of $disk" \ 841 | "with 'sgdisk --print $disk'" 842 | return 1 843 | } 844 | # looking for a message like: 845 | # Found invalid GPT and valid MBR; converting MBR to GPT format 846 | case "$out" in 847 | *\ valid\ MBR\ *) _RET="dos";; 848 | *) _RET="gpt";; 849 | esac 850 | return 851 | elif [ ${SFDISK_VERSION} -lt ${SFDISK_2_26} ] && 852 | out=$(sfdisk --id --force "$disk" 1 2>/dev/null); then 853 | if [ "$out" = "ee" ]; then 854 | _RET="gpt" 855 | else 856 | _RET="dos" 857 | fi 858 | return 859 | elif out=$(LANG=C sfdisk --list "$disk"); then 860 | out=$(echo "$out" | sed -e '/Disklabel type/!d' -e 's/.*: //') 861 | case "$out" in 862 | gpt|dos) _RET="$out";; 863 | *) error "WARN: unknown label $out";; 864 | esac 865 | fi 866 | } 867 | 868 | get_resizer() { 869 | local format="$1" user=${2:-"auto"} 870 | 871 | case "$user" in 872 | sgdisk) _RET="resize_sgdisk_$format"; return;; 873 | sfdisk) _RET="resize_sfdisk_$format"; return;; 874 | auto) :;; 875 | *) error "unexpected value '$user' for growpart resizer"; return 1;; 876 | esac 877 | 878 | if [ "$format" = "dos" ]; then 879 | [ -n "$SFDISK" ] || { 880 | error "sfdisk is required for resizing dos/MBR partition table." 881 | return 1 882 | } 883 | _RET="resize_sfdisk_dos" 884 | return 0 885 | fi 886 | 887 | if [ "${SFDISK_VERSION}" -ge ${SFDISK_V_WORKING_GPT} ]; then 888 | # sfdisk 2.26.2 works for resize but loses type (LP: #1474090) 889 | _RET="resize_sfdisk_gpt" 890 | elif has_cmd sgdisk; then 891 | _RET="resize_sgdisk_$format" 892 | else 893 | error "no tools available to resize disk with '$format'" 894 | return 1 895 | fi 896 | return 0 897 | } 898 | 899 | maybe_lvm_resize() { 900 | local disk="$1" part="$2" partpath="" ret="" out="" wouldrun="" 901 | [ "$DRY_RUN" -ne 0 ] && wouldrun="would-run" 902 | 903 | has_cmd lvm || { 904 | debug 2 "No lvm command, cannot attempt lvm resize of disk '$disk' part '$part'" 905 | return 0 906 | } 907 | get_diskpart_path "$1" "$2" || { 908 | error "could not determine partition path for disk '$DISK' part '$part'" 909 | return 1 910 | } 911 | partpath="$_RET" 912 | 913 | # can't use rq or rqe here because of "not an lvm" exit code 5. 914 | set -- lvm pvs --nolocking --readonly -o pvname "$partpath" 915 | debug 2 "executing: $*" 916 | out=$("$@" 2>&1) 917 | ret=$? 918 | case "$ret" in 919 | 5) debug 1 "$partpath is not an lvm pv"; return 0;; 920 | 0) :;; 921 | *) error "failed to execute [$ret] '$*'" 922 | error "$out" 923 | return 1;; 924 | esac 925 | rq lvm_resize $wouldrun lvm pvresize "$partpath" || { 926 | error "Failed to resize lvm pv $partpath" 927 | return 1 928 | } 929 | return 0 930 | } 931 | 932 | pt_update="auto" 933 | resizer=${GROWPART_RESIZER:-"auto"} 934 | while [ $# -ne 0 ]; do 935 | cur=${1} 936 | next=${2} 937 | case "$cur" in 938 | -h|--help) 939 | Usage 940 | exit 0 941 | ;; 942 | --free-percent|--free-percent=*) 943 | if [ "${cur#--free-percent=}" != "$cur" ]; then 944 | next="${cur#--free-percent=}" 945 | else 946 | shift 947 | fi 948 | if [ "$next" -gt 0 ] 2>/dev/null && 949 | [ "$next" -lt 100 ] 2>/dev/null; then 950 | free_percent=$next 951 | else 952 | fail "unknown/invalid --free-percent option: $next" 953 | fi 954 | ;; 955 | --fudge) 956 | FUDGE=${next} 957 | shift 958 | ;; 959 | -N|--dry-run) 960 | DRY_RUN=1 961 | ;; 962 | -u|--update|--update=*) 963 | if [ "${cur#--update=}" != "$cur" ]; then 964 | next="${cur#--update=}" 965 | else 966 | shift 967 | fi 968 | case "$next" in 969 | off|auto|force|on) pt_update=$next;; 970 | *) fail "unknown --update option: $next";; 971 | esac 972 | ;; 973 | -v|--verbose) 974 | VERBOSITY=$(($VERBOSITY+1)) 975 | ;; 976 | --) 977 | shift 978 | break 979 | ;; 980 | -*) 981 | fail "unknown option ${cur}" 982 | ;; 983 | *) 984 | if [ -z "${DISK}" ]; then 985 | case "$cur" in 986 | *[!0-9]*[0-9]*) 987 | DISK=$(echo "$cur" | sed -E 's/p?[0-9]+$//') 988 | PART=$(echo "$cur" | sed -E 's/.*[^0-9]([0-9]+)$/\1/') 989 | ;; 990 | *) 991 | DISK="$cur" 992 | ;; 993 | esac 994 | else 995 | if [ -z "${PART}" ]; then 996 | PART="${cur}" 997 | fi 998 | fi 999 | ;; 1000 | 1001 | esac 1002 | shift 1003 | done 1004 | 1005 | case "$DISK" in 1006 | *[!0-9]*) ;; 1007 | *) bad_Usage "must supply disk and partition-number" ;; 1008 | esac 1009 | [ -n "${PART}" ] || bad_Usage "must supply partition-number" 1010 | 1011 | [ -e "${DISK}" ] || fail "${DISK}: does not exist" 1012 | 1013 | # cache the has_cmd return value. 1014 | has_cmd sfdisk && SFDISK=sfdisk || SFDISK="" 1015 | has_cmd sgdisk && SGDISK=sgdisk || SGDISK="" 1016 | 1017 | [ -n "$SGDISK" -o -n "$SFDISK" ] || 1018 | fail "Did not have sfdisk or sgdisk in PATH." 1019 | 1020 | get_sfdisk_version || fail 1021 | 1022 | # If $DISK is a symlink, resolve it. 1023 | # This avoids problems due to varying partition device name formats 1024 | # (e.g. "1" for /dev/sda vs "-part1" for /dev/disk/by-id/name) 1025 | if [ -L "${DISK}" ]; then 1026 | has_cmd readlink || 1027 | fail "${DISK} is a symlink, but 'readlink' command not available." 1028 | real_disk=$(readlink -f "${DISK}") || fail "unable to resolve ${DISK}" 1029 | debug 1 "${DISK} resolved to ${real_disk}" 1030 | DISK=${real_disk} 1031 | fi 1032 | 1033 | [ "${PART#*[!0-9]}" = "${PART}" ] || fail "partition-number must be a number" 1034 | 1035 | verify_ptupdate "$pt_update" || fail 1036 | PT_UPDATE=$_RET 1037 | 1038 | debug 1 "update-partition set to $PT_UPDATE" 1039 | 1040 | mktemp_d && TEMP_D="${_RET}" || fail "failed to make temp dir" 1041 | trap cleanup 0 # EXIT - some shells may not like 'EXIT' but are ok with 0 1042 | 1043 | # get the ID of the first partition to determine if it's MBR or GPT 1044 | get_table_format "$DISK" || fail 1045 | format=$_RET 1046 | get_resizer "$format" "$resizer" || 1047 | fail "failed to get a resizer for format '$format'" 1048 | resizer=$_RET 1049 | 1050 | lock_disk $DISK 1051 | debug 1 "resizing $PART on $DISK using $resizer" 1052 | "$resizer" 1053 | ret=$? 1054 | 1055 | unlock_disk_and_settle $DISK 1056 | 1057 | if [ "$RESIZE_RESULT" = "CHANGED" -o "$RESIZE_RESULT" = "CHANGE" ]; then 1058 | maybe_lvm_resize "$DISK" "$PART" || fail "lvm resize failed." 1059 | fi 1060 | 1061 | exit $ret 1062 | 1063 | # vi: ts=4 noexpandtab -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | --------------------------------------------------------------------------------