From aab10adc7bf8dc03bfd02ec0d66b53a48cbbe8a1 Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Sun, 30 Jun 2024 07:46:41 +0200
Subject: [PATCH 01/46] Change from using `which` to `command -v`
---
shrink-backup | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/shrink-backup b/shrink-backup
index c86a0bb..bc219dc 100644
--- a/shrink-backup
+++ b/shrink-backup
@@ -1174,7 +1174,8 @@ function make_img() {
if [ $PARTITION_TABLE == 'gpt' ]; then
echo -e "${White}## ${Green}GPT partition table detected, ${Yellow}sgdisk needed, ${IWhite}checking for application..."
$SLEEPING
- if [[ ! -f $(which sgdisk 2>&1) ]]; then
+ #if [[ ! -f $(which sgdisk 2>&1) ]]; then
+ if ! command -v sgdisk > /dev/null 2>&1; then
echo -e "${Yellow}!! sgdisk is NOT installed..."
debug 'INFO' 'sgdisk not available on system'
read -p "Do you want to try to install gdisk? [y/n] " -n 1 -r
@@ -1186,10 +1187,11 @@ function make_img() {
fi
echo ''
debug 'INFO' 'Y or y pressed to confirm'
- if [[ -f $(which apt 2>&1) ]]; then
+ #if [[ -f $(which apt 2>&1) ]]; then
+ if command -v apt > /dev/null 2>&1; then
echo -e "${White}## ${Green}apt found, ${IWhite}trying to install gdisk..."
- read -p "Do you want to use apt to install gdisk? [y/n] " -n 1 -r
- debug 'INFO' 'Do you want to use apt to install gdisk? [y/n]'
+ read -p "Do you want to use apt to install gdisk? (will upgrade system) [y/n] " -n 1 -r
+ debug 'INFO' 'Do you want to use apt to install gdisk? (will upgrade system) [y/n]'
if ! [[ "$REPLY" =~ ^[Yy]$ ]]; then
echo ''
echo -e "${Red}!! Aborting..."
@@ -1199,7 +1201,8 @@ function make_img() {
debug 'INFO' 'Y or y pressed to confirm'
debug 'DEBUG' 'Running: apt update -y && apt upgrade -y && apt install gdisk -y'
apt update -y && apt upgrade -y && apt install gdisk -y
- elif [[ -f $(which pacman 2>&1) ]]; then
+ #elif [[ -f $(which pacman 2>&1) ]]; then
+ elif command -v pacman > /dev/null 2>&1; then
echo -e "${White}## ${Green}pacman found, ${IWhite}trying to install gdisk..."
read -p "Do you want to use pacman to install gptfdisk? (will do -Syu first) [y/n] " -n 1 -r
debug 'INFO' 'Do you want to use pacman to install gptfdisk? (will do -Syu first) [y/n]'
@@ -1310,11 +1313,12 @@ function make_img() {
if [ "$F2FS" = true ]; then
echo -e "${White}## ${Green}--f2fs option selected, mkfs.f2fs is needed, ${IWhite}checking if installed..."
$SLEEPING
- if [[ ! -f $(which mkfs.f2fs 2>&1) ]]; then
+ #if [[ ! -f $(which mkfs.f2fs 2>&1) ]]; then
+ if ! command -v mkfs.f2fs > /dev/null 2>&1; then
echo -e "${Yellow}!! mkfs.f2fs is NOT installed..."
debug 'INFO' 'mkfs.f2fs (f2fs-tools) not available on system'
- read -p "Do you want to use apt to install f2fs-tools? [y/n] " -n 1 -r
- debug 'INFO' 'Do you want to try to install f2fs-tools? [y/n]'
+ read -p "Do you want to use apt to install f2fs-tools? (will upgrade system) [y/n] " -n 1 -r
+ debug 'INFO' 'Do you want to try to install f2fs-tools? (will upgrade system) [y/n]'
if ! [[ "$REPLY" =~ ^[Yy]$ ]]; then
echo ''
echo -e "${Red}!! Aborting..."
From 98de1354e9ec47e6fcaa2b74ce361197f3cc4731 Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Tue, 2 Jul 2024 19:10:23 +0200
Subject: [PATCH 02/46] Update README.md
Changed --f2fs internal link from f2fs section
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index e6df2b4..ada78b9 100644
--- a/README.md
+++ b/README.md
@@ -278,7 +278,7 @@ Only expansion is possible with this method.
## f2fs
The script will detect `f2fs` on `root` automatically and act accordingly.
-**Do NOT USE [`--f2fs`](#--fix-broken-pipe) unless you are converting from a `ext4` filesystem (on your system) into `f2fs` on the img file.**
+**Do NOT USE [`--f2fs`](#--f2fs-Convert-ext4-into-f2fs-on-img-file) unless you are converting from a `ext4` filesystem (on your system) into `f2fs` on the img file.**
Autoexpansion at boot is not possible with `f2fs`. User will have to manually expand img to cover entire storage media (f.ex sd-card) when restoring.
Resizing of img `root` partition while updating img (`-U`) is not possible with `f2fs` _as of now_. User will have to create a new backup if img runs out of space.
From 3fd73c2a9b69332464265d07f6c9e9b4c3c1d035 Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Tue, 2 Jul 2024 19:21:15 +0200
Subject: [PATCH 03/46] Update README.md
Made it more clear early in the readme that only root and boot is included as partitions.
---
README.md | 3 +++
1 file changed, 3 insertions(+)
diff --git a/README.md b/README.md
index ada78b9..1eedd71 100644
--- a/README.md
+++ b/README.md
@@ -4,6 +4,9 @@ _I made this script because I wanted a universal method of backing up my SBC:s i
shrink-backup is a very fast utility for backing up your SBC:s into minimal bootable img files for easy restore with autoexpansion at boot.
+Supports backing up `boot` & `root` partitions, data from other partitions will be written to `root` if not excluded ([`btrfs`](#btrfs) excluded, all subvolumes will be created).
+Please see [`Info`](#info) section.
+
Autoexpansion tested on **Raspberry Pi** os (bookworm and older), **Armbian**, **Manjaro-arm**, **DietPi** & **ArchLinuxARM** for rpi with `ext4` or [`f2fs`](#f2fs) root partition.
(Also **experimental** [`btrfs`](#btrfs) functionality, please read further down)
Full support for usage inside [webmin](https://webmin.com/) (including "custom command" button). Thank you to [iliajie](https://github.com/iliajie) for helping out. ❤️
From fb2370ebeea5ae4f88b1a8f83bab1aec756a756c Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Tue, 2 Jul 2024 19:27:09 +0200
Subject: [PATCH 04/46] Update README.md
Made the info section about partitions a bit more clear and added an internal link and info about btrfs
---
README.md | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 1eedd71..0c50d52 100644
--- a/README.md
+++ b/README.md
@@ -160,7 +160,9 @@ Please read information about [`f2fs`](#f2fs) further down.
### Info
**Rsync WILL cross filesystem boundries, so make sure you exclude external drives unless you want them included in the backup.**
-**Not excluding other partitions will copy the data to the img `root` partition, not create more partitions,** so make sure to **_manually add_ `[extra space]`** if you do this.
+The script will **ONLY** create `boot` (if exits) and `root` partitions on the img file.
+**Not excluding other partitions will copy the data to the img `root` partition, not create more partitions,** so make sure to **_manually add_ `[extra space]`** if you do this.
+Experimental [`btrfs`](#btrfs) is an exception to this.
The script will **ONLY** look at your `root` partition when calculating sizes.
From a348db0ec16ceac0376d6fc7e176f268547edd92 Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Thu, 4 Jul 2024 16:06:10 +0200
Subject: [PATCH 05/46] Fixed version to 1.2-beta
---
shrink-backup | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/shrink-backup b/shrink-backup
index bc219dc..9e455a0 100644
--- a/shrink-backup
+++ b/shrink-backup
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
#
# shrink-backup
-# version 1.1
+# version 1.2-beta
# backup tool for backing up and updating .img files with autoexpansion on various operating systems
#
# Copyright (c) 2024, Marcus Johansson
From 7a1302f930c55b0e81ce3cd2ef1a16ff327dbed1 Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Tue, 23 Jul 2024 01:09:19 +0200
Subject: [PATCH 06/46] Cleanup and a bit of consitency correcting
- Removed some old "memory" code
- Changed path in script referencing root from `'/ '` to `' / '`
- Removed heading / when referencing boot
- Changed method of detecting if boot is mounted
Could maybe help a bit with #39
---
shrink-backup | 47 +++++++++++++++++++++--------------------------
1 file changed, 21 insertions(+), 26 deletions(-)
diff --git a/shrink-backup b/shrink-backup
index 9e455a0..33e2664 100644
--- a/shrink-backup
+++ b/shrink-backup
@@ -40,7 +40,7 @@ function cleanup() {
while true; do
# Check if the mount point is still busy
if ! umount "${TMP_DIR}${BOOT_PATH}" && [ -n "$BOOT_PATH" ] && [ -n "$TMP_DIR" ] && grep -qs "${TMP_DIR}${BOOT_PATH} " /proc/mounts; then
- # If it is, sleep for a few seconds and try again
+ # If it is, sleep for 5 seconds and try again
echo -e "${Yellow}!! ${Green}${TMP_DIR}${BOOT_PATH} ${Yellow}is busy, retrying in 5 seconds..."
debug 'DEBUG' "${TMP_DIR}${BOOT_PATH} is busy, retrying in 5 seconds"
sleep 5
@@ -89,8 +89,6 @@ function cleanup() {
break
fi
done
- #debug 'DEBUG' "Removing loop in cleanup function: losetup -d $LOOP"
- #losetup -d "$LOOP"
fi
if [ -d "$TMP_DIR" ]; then
@@ -177,7 +175,7 @@ version() {
exit 2
}
-# Function to display help information
+# Function to display help information and exit
help() {
local help
read -r -d '' help << EOM
@@ -286,7 +284,7 @@ function debug() {
fi
fi
fi
- return 0
+return 0
}
@@ -352,18 +350,17 @@ function get_dev_variables() {
if grep -q 'boot' /etc/fstab; then
debug 'INFO' 'Separate boot partition detected'
LOCAL_DEV_BOOT_PATH=$(lsblk -lpo mountpoint,path | grep 'boot' | awk '{print $2}')
- LOCAL_DEV_ROOT_PATH=$(mount | grep '/ ' | awk '{print $1}')
+ LOCAL_DEV_ROOT_PATH=$(mount | grep ' / ' | awk '{print $1}')
debug 'DEBUG' "LOCAL_DEV_BOOT_PATH=$LOCAL_DEV_BOOT_PATH | LOCAL_DEV_ROOT_PATH=$LOCAL_DEV_ROOT_PATH"
LOCAL_BOOT_UUID=$(lsblk -o uuid "$LOCAL_DEV_BOOT_PATH" | tail -1)
LOCAL_ROOT_UUID=$(lsblk -o uuid "$LOCAL_DEV_ROOT_PATH" | tail -1)
LOCAL_ROOT_PARTUUID=$(lsblk -o partuuid "$LOCAL_DEV_ROOT_PATH" | tail -1)
debug 'DEBUG' "LOCAL_BOOT_UUID=$LOCAL_BOOT_UUID | LOCAL_ROOT_UUID=$LOCAL_ROOT_UUID | LOCAL_ROOT_PARTUUID=$LOCAL_ROOT_PARTUUID"
- BOOT_PATH=$(cat /etc/fstab | grep '/boot' | awk '{print $2}')
+ BOOT_PATH=$(cat /etc/fstab | grep 'boot' | awk '{print $2}')
debug 'DEBUG' "BOOT_PATH=$BOOT_PATH"
else
debug 'INFO' 'No boot partition detected'
- #LOCAL_DEV_ROOT_PATH=$(lsblk -lpo mountpoint,path | grep '/ ' | awk '{print $2}')
- LOCAL_DEV_ROOT_PATH=$(mount | grep '/ ' | awk '{print $1}')
+ LOCAL_DEV_ROOT_PATH=$(mount | grep ' / ' | awk '{print $1}')
debug 'DEBUG' "LOCAL_DEV_ROOT_PATH=$LOCAL_DEV_ROOT_PATH"
LOCAL_ROOT_UUID=$(lsblk -o uuid "$LOCAL_DEV_ROOT_PATH" | tail -1)
LOCAL_ROOT_PARTUUID=$(lsblk -o partuuid "$LOCAL_DEV_ROOT_PATH" | tail -1)
@@ -447,7 +444,7 @@ return 0
# Function to gather btrfs information
function get_btrfs_variables() {
- BOOT_PATH=$(cat /etc/fstab | grep '/boot' | awk '{print $2}')
+ BOOT_PATH=$(cat /etc/fstab | grep 'boot' | awk '{print $2}')
debug 'DEBUG' "BOOT_PATH=$BOOT_PATH"
if [ "$AUTORESIZE_RUN" = true ]; then
@@ -486,7 +483,6 @@ function get_img_variables() {
# Boot partition exists
if grep -q 'boot' /etc/fstab; then
- debug 'INFO' 'Separate boot partition detected'
# ext4 & f2fs
if [ "$FSTYPE" == 'ext4' ] || [ "$FSTYPE" == 'f2fs' ]; then
@@ -543,7 +539,7 @@ function get_img_variables() {
fi
$SLEEPING
partprobe "$LOOP"
- declare -a fstab=( $(cat /etc/fstab | grep '/ ') )
+ declare -a fstab=( $(cat /etc/fstab | grep ' / ') )
debug 'INFO' 'Mounting root to find subvolumes'
debug 'DEBUG' "Running: mount -o ${fstab[3]} $IMG_DEV_ROOT_PATH $TMP_DIR"
if ! output=$(mount -o "${fstab[3]}" "$IMG_DEV_ROOT_PATH" "$TMP_DIR" 2>&1); then
@@ -675,7 +671,7 @@ function do_mount() {
# btrfs
elif [ "$FSTYPE" == 'btrfs' ]; then
- declare -a fstab=( $(cat /etc/fstab | grep '/ ') )
+ declare -a fstab=( $(cat /etc/fstab | grep ' / ') )
echo -e "${White}## ${IWhite}Mounting root subvolume..."
debug 'DEBUG' "Running: mount -o ${fstab[3]} $IMG_DEV_ROOT_PATH $TMP_DIR"
if ! output=$(mount -o "${fstab[3]}" "$IMG_DEV_ROOT_PATH" "$TMP_DIR" 2>&1); then
@@ -714,10 +710,9 @@ function do_mount() {
done
fi
- # Checking if boot partition exists and if true, mount boot
- #if [ $(lsblk | grep -c 'boot') -ne 0 ]; then
+ # Mount boot partition if exists
if [ -n "$BOOT_PATH" ]; then
- if ! lsblk | grep -q 'boot'; then
+ if ! mount | grep -q 'boot'; then
echo -e "${Red}!! BOOT PARTITION NOT MOUNTED ON SYSTEM, PLEASE MOUNT BOOT PARTITION AND RE-RUN THE SCRIPT!!!"
debug 'ERROR' 'BOOT PARTITION NOT MOUNTED ON SYSTEM, PLEASE MOUNT BOOT PARTITION AND RE-RUN THE SCRIPT!!!'
exit 1
@@ -827,7 +822,7 @@ function do_resize() {
echo -e "${White}## ${IWhite}Expanding img filesystem..."
$SLEEPING
- # Removing loop for tuncate to take effect
+ # Removing loop for truncate to take effect
echo -e "${White}## ${IWhite}Removing loop..."
$SLEEPING
debug 'INFO' 'Removing loop for truncate to take effect'
@@ -1280,7 +1275,7 @@ function make_img() {
# ext4 & f2fs on root
elif [ "$FSTYPE" == 'ext4' ] || [ "$FSTYPE" == 'f2fs' ]; then
- debug 'DEBUG' "Running: parted -s -a none $LOOP unit B mkpart primary $FSTYPE $LOCAL_ROOT_START 100%"
+ debug 'DEBUG' "Running: parted -s -a none $LOOP unit B mkpart primary $LOCAL_ROOT_START 100%"
#if ! output=$(parted -s -a none "$LOOP" unit B mkpart primary "$FSTYPE" "$LOCAL_ROOT_START" 100% 2>&1); then
if ! output=$(parted -s -a none "$LOOP" unit B mkpart primary "$LOCAL_ROOT_START" 100% 2>&1); then
echo -e "${Yellow}$output\n${Red}!! PARTED FAILED!!!"
@@ -1442,7 +1437,7 @@ function make_img() {
$SLEEPING
partprobe "$LOOP"
#fstab=( $(cat /etc/fstab | grep "${LOCAL_SUBVOLUMES[0]}") )
- declare -a fstab=( $(cat /etc/fstab | grep '/ ') )
+ declare -a fstab=( $(cat /etc/fstab | grep ' / ') )
debug 'DEBUG' "Running: mount -o ${fstab[3]} $IMG_DEV_ROOT_PATH $TMP_DIR"
if ! output=$(mount -o "${fstab[3]}" "$IMG_DEV_ROOT_PATH" "$TMP_DIR" 2>&1); then
echo -e "${Yellow}$output\n${Red}!! ROOT SUBVOLUME MOUNT FAILED!!!"
@@ -1808,10 +1803,10 @@ EOF
debug 'DEBUG' "Creating expansion script ${TMP_DIR}/expand-fs.sh"
cat << EOF2 > "${TMP_DIR}/expand-fs.sh"
#!/usr/bin/bash
-LOCAL_DEV_PTUUID=\$(lsblk -lpo mountpoint,ptuuid | grep '/ ' | awk '{print \$2}')
+LOCAL_DEV_PTUUID=\$(lsblk -lpo mountpoint,ptuuid | grep ' / ' | awk '{print \$2}')
LOCAL_DEV_PATH=\$(lsblk -lpo ptuuid,type,path | grep "\$LOCAL_DEV_PTUUID" | grep 'disk' | awk '{print \$3}')
LOCAL_ROOT_PARTN=\$(parted -sm "\$LOCAL_DEV_PATH" print | tail -1 | cut -d : -f 1)
-LOCAL_DEV_ROOT_PATH=\$(lsblk -lpo mountpoint,path | grep '/ ' | awk '{print \$2}')
+LOCAL_DEV_ROOT_PATH=\$(lsblk -lpo mountpoint,path | grep ' / ' | awk '{print \$2}')
LOCAL_ROOT_START=\$(fdisk -lo start "\$LOCAL_DEV_PATH" | tail -1 | awk '{print \$1}') # blocks, 512B block size
LOCAL_ROOT_START=\$(( LOCAL_ROOT_START * 512 )) # bytes
@@ -1867,10 +1862,10 @@ EOF
debug 'DEBUG' 'Creating expansion script ${TMP_DIR}/expand-fs.sh'
cat << EOF2 > "${TMP_DIR}/expand-fs.sh"
#!/usr/bin/bash
-LOCAL_DEV_PTUUID=\$(lsblk -lpo mountpoint,ptuuid | grep '/ ' | awk '{print \$2}')
+LOCAL_DEV_PTUUID=\$(lsblk -lpo mountpoint,ptuuid | grep ' / ' | awk '{print \$2}')
LOCAL_DEV_PATH=\$(lsblk -lpo ptuuid,type,path | grep "\$LOCAL_DEV_PTUUID" | grep 'disk' | awk '{print \$3}')
LOCAL_ROOT_PARTN=\$(parted -sm "\$LOCAL_DEV_PATH" print | tail -1 | cut -d : -f 1)
-LOCAL_DEV_ROOT_PATH=\$(lsblk -lpo mountpoint,path | grep '/ ' | awk '{print \$2}')
+LOCAL_DEV_ROOT_PATH=\$(lsblk -lpo mountpoint,path | grep ' / ' | awk '{print \$2}')
LOCAL_ROOT_START=\$(fdisk -lo start "\$LOCAL_DEV_PATH" | tail -1 | awk '{print \$1}') # blocks, 512B block size
LOCAL_ROOT_START=\$(( LOCAL_ROOT_START * 512 )) # bytes
@@ -2030,14 +2025,14 @@ fi
echo -e "${White}## ${IWhite}Scanning filesystem and calculating..."
# Check what filesystem root is using and set LOCAL_DEV_PATH & PARTITION_TABLE
-#FSTYPE=$(lsblk -lo mountpoint,fstype | grep '/ ' | awk '{print $2}')
+#FSTYPE=$(lsblk -lo mountpoint,fstype | grep ' / ' | awk '{print $2}')
FSTYPE="$(mount | grep ' / ' | awk '{print $5}')"
debug 'INFO' "$FSTYPE root filesystem detected"
debug 'DEBUG' "FSTYPE=$FSTYPE"
if [ "$FSTYPE" == 'ext4' ] || [ "$FSTYPE" == 'f2fs' ]; then
- LOCAL_DEV_PTUUID=$(lsblk -lpo mountpoint,ptuuid | grep '/ ' | awk '{print $2}')
+ LOCAL_DEV_PTUUID=$(lsblk -lpo mountpoint,ptuuid | grep ' / ' | awk '{print $2}')
else
- LOCAL_DEV_PTUUID=$(lsblk -lpo fsroots,ptuuid | grep '/ ' | awk '{print $2}')
+ LOCAL_DEV_PTUUID=$(lsblk -lpo fsroots,ptuuid | grep ' / ' | awk '{print $2}')
fi
LOCAL_DEV_PATH=$(lsblk -lpo ptuuid,type,path | grep "$LOCAL_DEV_PTUUID" | grep 'disk' | awk '{print $3}')
debug 'DEBUG' "LOCAL_DEV_PTUUID=$LOCAL_DEV_PTUUID | LOCAL_DEV_PATH=$LOCAL_DEV_PATH"
From 18e6749da603a9693384c619468554b52a7c3d6f Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Tue, 23 Jul 2024 19:15:29 +0200
Subject: [PATCH 07/46] Bugfix from previous commit
And changed from `lsblk` to `mount` where possible.
Should probably change `mount` to `cat /proc/mounts` instead.
---
shrink-backup | 60 ++++++++++++++++++++++++++-------------------------
1 file changed, 31 insertions(+), 29 deletions(-)
diff --git a/shrink-backup b/shrink-backup
index 33e2664..2846876 100644
--- a/shrink-backup
+++ b/shrink-backup
@@ -349,12 +349,13 @@ function get_dev_variables() {
# Check if separate boot and root partition exists and set variables accordingly
if grep -q 'boot' /etc/fstab; then
debug 'INFO' 'Separate boot partition detected'
- LOCAL_DEV_BOOT_PATH=$(lsblk -lpo mountpoint,path | grep 'boot' | awk '{print $2}')
+ #LOCAL_DEV_BOOT_PATH=$(lsblk -lpo mountpoint,path | grep 'boot' | awk '{print $2}')
+ LOCAL_DEV_BOOT_PATH=$(mount | grep 'boot' | awk '{print $1}')
LOCAL_DEV_ROOT_PATH=$(mount | grep ' / ' | awk '{print $1}')
debug 'DEBUG' "LOCAL_DEV_BOOT_PATH=$LOCAL_DEV_BOOT_PATH | LOCAL_DEV_ROOT_PATH=$LOCAL_DEV_ROOT_PATH"
- LOCAL_BOOT_UUID=$(lsblk -o uuid "$LOCAL_DEV_BOOT_PATH" | tail -1)
- LOCAL_ROOT_UUID=$(lsblk -o uuid "$LOCAL_DEV_ROOT_PATH" | tail -1)
- LOCAL_ROOT_PARTUUID=$(lsblk -o partuuid "$LOCAL_DEV_ROOT_PATH" | tail -1)
+ LOCAL_BOOT_UUID=$(lsblk -no uuid "$LOCAL_DEV_BOOT_PATH")
+ LOCAL_ROOT_UUID=$(lsblk -no uuid "$LOCAL_DEV_ROOT_PATH")
+ LOCAL_ROOT_PARTUUID=$(lsblk -no partuuid "$LOCAL_DEV_ROOT_PATH")
debug 'DEBUG' "LOCAL_BOOT_UUID=$LOCAL_BOOT_UUID | LOCAL_ROOT_UUID=$LOCAL_ROOT_UUID | LOCAL_ROOT_PARTUUID=$LOCAL_ROOT_PARTUUID"
BOOT_PATH=$(cat /etc/fstab | grep 'boot' | awk '{print $2}')
debug 'DEBUG' "BOOT_PATH=$BOOT_PATH"
@@ -362,8 +363,8 @@ function get_dev_variables() {
debug 'INFO' 'No boot partition detected'
LOCAL_DEV_ROOT_PATH=$(mount | grep ' / ' | awk '{print $1}')
debug 'DEBUG' "LOCAL_DEV_ROOT_PATH=$LOCAL_DEV_ROOT_PATH"
- LOCAL_ROOT_UUID=$(lsblk -o uuid "$LOCAL_DEV_ROOT_PATH" | tail -1)
- LOCAL_ROOT_PARTUUID=$(lsblk -o partuuid "$LOCAL_DEV_ROOT_PATH" | tail -1)
+ LOCAL_ROOT_UUID=$(lsblk -no uuid "$LOCAL_DEV_ROOT_PATH")
+ LOCAL_ROOT_PARTUUID=$(lsblk -no partuuid "$LOCAL_DEV_ROOT_PATH")
debug 'DEBUG' "LOCAL_ROOT_UUID=$LOCAL_ROOT_UUID | LOCAL_ROOT_PARTUUID=$LOCAL_ROOT_PARTUUID"
fi
LOCAL_ROOT_PARTN=$(parted -sm "$LOCAL_DEV_PATH" print | tail -1 | cut -d : -f 1)
@@ -372,7 +373,7 @@ function get_dev_variables() {
# Collect information about partition sizes
#if [ "$UPDATE" = false ] || [ "$ADDED_SPACE" -ne 0 ] || [ "$AUTORESIZE_RUN" = true ]; then
debug 'INFO' 'Calculating size for dd to cover bootsector and adding 5MiB (5242880 bytes) to overlap into root (only used in img creation)'
- #LOCAL_BOOTSECTOR=$(lsblk --bytes -o size "$LOCAL_DEV_BOOT_PATH" | tail -1) # bytes, can not be used, will be 0 if no boot partition exists
+ #LOCAL_BOOTSECTOR=$(lsblk --bytes -no size "$LOCAL_DEV_BOOT_PATH") # bytes, can not be used, will be 0 if no boot partition exists
LOCAL_ROOT_START=$(fdisk -lo device,start "$LOCAL_DEV_PATH" | grep "$LOCAL_DEV_ROOT_PATH" | awk '{print $2}') # 512B blocks
LOCAL_BOOTSECTOR=$(( LOCAL_ROOT_START - 1 )) # blocks, to set the actual bootsector, needed in case no boot partition exists
LOCAL_ROOT_START=$(( LOCAL_ROOT_START * 512 )) # bytes
@@ -488,8 +489,8 @@ function get_img_variables() {
if [ "$FSTYPE" == 'ext4' ] || [ "$FSTYPE" == 'f2fs' ]; then
# I have no idea why, but if I do not put this sleep here, IMG_DEV_BOOT_PATH does not get set
sleep 2
- IMG_DEV_BOOT_PATH=$(lsblk -o path,uuid "$LOOP" | grep "$LOCAL_BOOT_UUID" | awk '{print $1}')
- IMG_DEV_ROOT_PATH=$(lsblk -o path,uuid "$LOOP" | grep "$LOCAL_ROOT_UUID" | awk '{print $1}')
+ IMG_DEV_BOOT_PATH=$(lsblk -no path,uuid "$LOOP" | grep "$LOCAL_BOOT_UUID" | awk '{print $1}')
+ IMG_DEV_ROOT_PATH=$(lsblk -no path,uuid "$LOOP" | grep "$LOCAL_ROOT_UUID" | awk '{print $1}')
debug 'DEBUG' "IMG_DEV_BOOT_PATH=$IMG_DEV_BOOT_PATH | IMG_DEV_ROOT_PATH=$IMG_DEV_ROOT_PATH"
# 2s sleep is sometimes not enough, might have to do with slow network if img file is on a network share
if ! [ -e "$IMG_DEV_BOOT_PATH" ] || ! [ -e "$IMG_DEV_ROOT_PATH" ]; then
@@ -498,8 +499,8 @@ function get_img_variables() {
debug 'WARNING' 'LOOP paths can not be set, retrying in 5 seconds'
debug 'WARNING' "IMG_DEV_BOOT_PATH=$IMG_DEV_BOOT_PATH | IMG_DEV_ROOT_PATH=$IMG_DEV_ROOT_PATH"
sleep 5
- IMG_DEV_BOOT_PATH=$(lsblk -o path,uuid "$LOOP" | grep "$LOCAL_BOOT_UUID" | awk '{print $1}')
- IMG_DEV_ROOT_PATH=$(lsblk -o path,uuid "$LOOP" | grep "$LOCAL_ROOT_UUID" | awk '{print $1}')
+ IMG_DEV_BOOT_PATH=$(lsblk -no path,uuid "$LOOP" | grep "$LOCAL_BOOT_UUID" | awk '{print $1}')
+ IMG_DEV_ROOT_PATH=$(lsblk -no path,uuid "$LOOP" | grep "$LOCAL_ROOT_UUID" | awk '{print $1}')
if [ -e "$IMG_DEV_BOOT_PATH" ] && [ -e "$IMG_DEV_ROOT_PATH" ]; then
echo -e "${White}## ${Green}LOOP paths found, resuming backup..."
debug 'INFO' "LOOP paths found, resuming backup"
@@ -522,7 +523,7 @@ function get_img_variables() {
# I have no idea why, but if I do not put this sleep here, IMG_DEV_ROOT_PATH does not get set
sleep 2
#pause 'Press [Enter] key to continue...'
- IMG_DEV_ROOT_PATH=$(lsblk -o path,uuid "$LOOP" | grep "$LOCAL_ROOT_UUID" | awk '{print $1}')
+ IMG_DEV_ROOT_PATH=$(lsblk -no path,uuid "$LOOP" | grep "$LOCAL_ROOT_UUID" | awk '{print $1}')
debug 'DEBUG' "IMG_DEV_ROOT_PATH=$IMG_DEV_ROOT_PATH"
fi
@@ -571,8 +572,8 @@ function set_img_variables() {
if [ "$FSTYPE" == 'ext4' ] || [ "$FSTYPE" == 'f2fs' ]; then
# I have no idea why, but if I do not put this sleep here, IMG_DEV_BOOT_PATH does not get set
sleep 2
- IMG_DEV_BOOT_PATH=$(lsblk -o path,uuid "$LOOP" | grep "$LOCAL_BOOT_UUID" | awk '{print $1}')
- IMG_DEV_ROOT_PATH=$(lsblk -o path,uuid "$LOOP" | grep "$LOCAL_ROOT_UUID" | awk '{print $1}')
+ IMG_DEV_BOOT_PATH=$(lsblk -no path,uuid "$LOOP" | grep "$LOCAL_BOOT_UUID" | awk '{print $1}')
+ IMG_DEV_ROOT_PATH=$(lsblk -no path,uuid "$LOOP" | grep "$LOCAL_ROOT_UUID" | awk '{print $1}')
debug 'DEBUG' "IMG_DEV_BOOT_PATH=$IMG_DEV_BOOT_PATH | IMG_DEV_ROOT_PATH=$IMG_DEV_ROOT_PATH"
# 2s sleep is sometimes not enough, might have to do with slow network if img file is on a network share
if ! [ -e "$IMG_DEV_BOOT_PATH" ] || ! [ -e "$IMG_DEV_ROOT_PATH" ]; then
@@ -581,8 +582,8 @@ function set_img_variables() {
debug 'WARNING' 'LOOP paths can not be set, retrying in 5 seconds'
debug 'WARNING' "IMG_DEV_BOOT_PATH=$IMG_DEV_BOOT_PATH | IMG_DEV_ROOT_PATH=$IMG_DEV_ROOT_PATH"
sleep 5
- IMG_DEV_BOOT_PATH=$(lsblk -o path,uuid "$LOOP" | grep "$LOCAL_BOOT_UUID" | awk '{print $1}')
- IMG_DEV_ROOT_PATH=$(lsblk -o path,uuid "$LOOP" | grep "$LOCAL_ROOT_UUID" | awk '{print $1}')
+ IMG_DEV_BOOT_PATH=$(lsblk -no path,uuid "$LOOP" | grep "$LOCAL_BOOT_UUID" | awk '{print $1}')
+ IMG_DEV_ROOT_PATH=$(lsblk -no path,uuid "$LOOP" | grep "$LOCAL_ROOT_UUID" | awk '{print $1}')
if [ -e "$IMG_DEV_BOOT_PATH" ] && [ -e "$IMG_DEV_ROOT_PATH" ]; then
echo -e "${White}## ${Green}LOOP paths found, resuming backup..."
debug 'INFO' "LOOP paths found, resuming backup"
@@ -611,7 +612,7 @@ function set_img_variables() {
# I have no idea why, but if I do not put this sleep here, IMG_DEV_ROOT_PATH does not get set
sleep 2
#pause 'Press [Enter] key to continue...'
- IMG_DEV_ROOT_PATH=$(lsblk -o path,uuid "$LOOP" | grep "$LOCAL_ROOT_UUID" | awk '{print $1}')
+ IMG_DEV_ROOT_PATH=$(lsblk -no path,uuid "$LOOP" | grep "$LOCAL_ROOT_UUID" | awk '{print $1}')
debug 'DEBUG' "IMG_DEV_ROOT_PATH=$IMG_DEV_ROOT_PATH"
fi
return 0
@@ -1300,8 +1301,8 @@ function make_img() {
echo -e "${White}## ${IWhite}Formatting filesystem..."
debug 'INFO' 'Formatting filesystem'
$SLEEPING
- LABEL=$(lsblk -o label "$LOCAL_DEV_ROOT_PATH" | tail -1)
- UUID=$(lsblk -o uuid "$LOCAL_DEV_ROOT_PATH" | tail -1)
+ LABEL=$(lsblk -no label "$LOCAL_DEV_ROOT_PATH")
+ UUID=$(lsblk -no uuid "$LOCAL_DEV_ROOT_PATH")
debug 'DEBUG' "LABEL=$LABEL | UUID=$UUID"
# Convert to f2fs
@@ -1803,10 +1804,11 @@ EOF
debug 'DEBUG' "Creating expansion script ${TMP_DIR}/expand-fs.sh"
cat << EOF2 > "${TMP_DIR}/expand-fs.sh"
#!/usr/bin/bash
-LOCAL_DEV_PTUUID=\$(lsblk -lpo mountpoint,ptuuid | grep ' / ' | awk '{print \$2}')
-LOCAL_DEV_PATH=\$(lsblk -lpo ptuuid,type,path | grep "\$LOCAL_DEV_PTUUID" | grep 'disk' | awk '{print \$3}')
+LOCAL_DEV_PTUUID=\$(lsblk -no mountpoint,ptuuid | grep '/ ' | awk '{print \$2}')
+LOCAL_DEV_PATH=\$(lsblk -no ptuuid,type,path | grep "\$LOCAL_DEV_PTUUID" | grep 'disk' | awk '{print \$3}')
LOCAL_ROOT_PARTN=\$(parted -sm "\$LOCAL_DEV_PATH" print | tail -1 | cut -d : -f 1)
-LOCAL_DEV_ROOT_PATH=\$(lsblk -lpo mountpoint,path | grep ' / ' | awk '{print \$2}')
+#LOCAL_DEV_ROOT_PATH=\$(lsblk -no mountpoint,path | grep '/ ' | awk '{print \$2}')
+LOCAL_DEV_ROOT_PATH=\$(mount | grep ' / ' | awk '{print \$1}')
LOCAL_ROOT_START=\$(fdisk -lo start "\$LOCAL_DEV_PATH" | tail -1 | awk '{print \$1}') # blocks, 512B block size
LOCAL_ROOT_START=\$(( LOCAL_ROOT_START * 512 )) # bytes
@@ -1862,10 +1864,11 @@ EOF
debug 'DEBUG' 'Creating expansion script ${TMP_DIR}/expand-fs.sh'
cat << EOF2 > "${TMP_DIR}/expand-fs.sh"
#!/usr/bin/bash
-LOCAL_DEV_PTUUID=\$(lsblk -lpo mountpoint,ptuuid | grep ' / ' | awk '{print \$2}')
-LOCAL_DEV_PATH=\$(lsblk -lpo ptuuid,type,path | grep "\$LOCAL_DEV_PTUUID" | grep 'disk' | awk '{print \$3}')
+LOCAL_DEV_PTUUID=\$(lsblk -no mountpoint,ptuuid | grep '/ ' | awk '{print \$2}')
+LOCAL_DEV_PATH=\$(lsblk -no ptuuid,type,path | grep "\$LOCAL_DEV_PTUUID" | grep 'disk' | awk '{print \$3}')
LOCAL_ROOT_PARTN=\$(parted -sm "\$LOCAL_DEV_PATH" print | tail -1 | cut -d : -f 1)
-LOCAL_DEV_ROOT_PATH=\$(lsblk -lpo mountpoint,path | grep ' / ' | awk '{print \$2}')
+#LOCAL_DEV_ROOT_PATH=\$(lsblk -no mountpoint,path | grep '/ ' | awk '{print \$2}')
+LOCAL_DEV_ROOT_PATH=\$(mount | grep ' / ' | awk '{print \$1}')
LOCAL_ROOT_START=\$(fdisk -lo start "\$LOCAL_DEV_PATH" | tail -1 | awk '{print \$1}') # blocks, 512B block size
LOCAL_ROOT_START=\$(( LOCAL_ROOT_START * 512 )) # bytes
@@ -2025,16 +2028,15 @@ fi
echo -e "${White}## ${IWhite}Scanning filesystem and calculating..."
# Check what filesystem root is using and set LOCAL_DEV_PATH & PARTITION_TABLE
-#FSTYPE=$(lsblk -lo mountpoint,fstype | grep ' / ' | awk '{print $2}')
FSTYPE="$(mount | grep ' / ' | awk '{print $5}')"
debug 'INFO' "$FSTYPE root filesystem detected"
debug 'DEBUG' "FSTYPE=$FSTYPE"
if [ "$FSTYPE" == 'ext4' ] || [ "$FSTYPE" == 'f2fs' ]; then
- LOCAL_DEV_PTUUID=$(lsblk -lpo mountpoint,ptuuid | grep ' / ' | awk '{print $2}')
+ LOCAL_DEV_PTUUID=$(lsblk -no mountpoint,ptuuid | grep '/ ' | awk '{print $2}')
else
- LOCAL_DEV_PTUUID=$(lsblk -lpo fsroots,ptuuid | grep ' / ' | awk '{print $2}')
+ LOCAL_DEV_PTUUID=$(lsblk -no fsroots,ptuuid | grep '/ ' | awk '{print $2}')
fi
-LOCAL_DEV_PATH=$(lsblk -lpo ptuuid,type,path | grep "$LOCAL_DEV_PTUUID" | grep 'disk' | awk '{print $3}')
+LOCAL_DEV_PATH=$(lsblk -no ptuuid,type,path | grep "$LOCAL_DEV_PTUUID" | grep 'disk' | awk '{print $3}')
debug 'DEBUG' "LOCAL_DEV_PTUUID=$LOCAL_DEV_PTUUID | LOCAL_DEV_PATH=$LOCAL_DEV_PATH"
PARTITION_TABLE=$(parted "$LOCAL_DEV_PATH" print | grep -i 'Partition Table' | awk '{print $3}')
#PARTITION_TABLE=$(blkid "$LOCAL_DEV_PATH" | sed -n 's|^.*PTTYPE="\(\S\+\)".*|\1|p')
From a33d170a61685f890e5460454249f7b9d37f05e0 Mon Sep 17 00:00:00 2001
From: framps
Date: Wed, 24 Jul 2024 21:44:45 +0200
Subject: [PATCH 08/46] Added installer
---
install | 43 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
create mode 100755 install
diff --git a/install b/install
new file mode 100755
index 0000000..c0bf1f7
--- /dev/null
+++ b/install
@@ -0,0 +1,43 @@
+#!/bin/bash
+
+# Simple installer for shrink-backup
+#
+# Downloads and installs shrink-backup into /usr/local/sbin
+#
+# Command to use to install shrink-backup:
+# curl https://raw.githubusercontent.com/UnconnectedBedna/shrink-backup/master/install | sudo bash
+#
+
+set -uo pipefail
+
+readonly PACKAGE="shrink-backup"
+readonly DOWNLOAD_REPOSITORY="https://raw.githubusercontent.com/UnconnectedBedna/shrink-backup/master"
+readonly FILES_2_DOWNLOAD"=shrink-backup"
+readonly TMP_DIR=$(mktemp -d)
+readonly INSTALLATION_DIR="/usr/local/sbin"
+
+trap "{ rmdir $TMP_DIR &>/dev/null; }" SIGINT SIGTERM EXIT
+
+pwd=$PWD
+cd $TMP_DIR
+
+echo "Installing $PACKAGE ..."
+
+for file in $FILES_2_DOWNLOAD; do
+
+ echo -n "Downloading $file from $DOWNLOAD_REPOSITORY/$file ... "
+ http_code=$(curl -w "%{http_code}" -L -s $DOWNLOAD_REPOSITORY/$file -o $file)
+ (( $? )) && { echo "Curl failed"; exit 1; }
+ [[ $http_code != 200 ]] && { echo "http request failed with $http_code"; exit 1; }
+ echo "done"
+ echo -n "Installing $file into $INSTALLATION_DIR ... "
+ sudo chmod +x $file
+ (( $? )) && { echo "chmod failed"; exit 1; }
+ sudo mv $file $INSTALLATION_DIR
+ (( $? )) && { echo "mv failed"; exit 1; }
+ echo "done"
+
+done
+
+echo "$PACKAGE installed"
+cd $pwd
From 40ce3ff842011b3bd55824f87acc7a7db65f32cf Mon Sep 17 00:00:00 2001
From: framps
Date: Wed, 24 Jul 2024 22:53:21 +0200
Subject: [PATCH 09/46] fixed a minor issue in cleanup
---
install | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/install b/install
index c0bf1f7..0da67d5 100755
--- a/install
+++ b/install
@@ -16,9 +16,8 @@ readonly FILES_2_DOWNLOAD"=shrink-backup"
readonly TMP_DIR=$(mktemp -d)
readonly INSTALLATION_DIR="/usr/local/sbin"
-trap "{ rmdir $TMP_DIR &>/dev/null; }" SIGINT SIGTERM EXIT
-
pwd=$PWD
+trap "{ cd $PWD; rmdir $TMP_DIR &>/dev/null; }" SIGINT SIGTERM EXIT
cd $TMP_DIR
echo "Installing $PACKAGE ..."
From ca62dbdfb7a4e36afb672b5d3a37284277440ea7 Mon Sep 17 00:00:00 2001
From: framps
Date: Wed, 24 Jul 2024 23:25:49 +0200
Subject: [PATCH 10/46] Fixed a typo in prevous fix
---
install | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/install b/install
index 0da67d5..6799290 100755
--- a/install
+++ b/install
@@ -17,7 +17,7 @@ readonly TMP_DIR=$(mktemp -d)
readonly INSTALLATION_DIR="/usr/local/sbin"
pwd=$PWD
-trap "{ cd $PWD; rmdir $TMP_DIR &>/dev/null; }" SIGINT SIGTERM EXIT
+trap "{ cd $pwd; rmdir $TMP_DIR &>/dev/null; }" SIGINT SIGTERM EXIT
cd $TMP_DIR
echo "Installing $PACKAGE ..."
From b09ed663e5c97cab5eb658125f11ee13ad929f10 Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Thu, 25 Jul 2024 14:33:40 +0200
Subject: [PATCH 11/46] Bug fix and boot partition check implemented
- Fixed bug where script looped 3 times if loop paths could not be set, but did not exit on 3 failed attempts
- Added a check against fstab if boot exists, if true, check boot is mounted, if not, exit
---
shrink-backup | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/shrink-backup b/shrink-backup
index 2846876..e885b7a 100644
--- a/shrink-backup
+++ b/shrink-backup
@@ -510,6 +510,12 @@ function get_img_variables() {
done
fi
+ if ! [ -e "$IMG_DEV_BOOT_PATH" ] || ! [ -e "$IMG_DEV_ROOT_PATH" ]; then
+ echo -e "${Red}!! LOOP PATHS CAN NOT BE SET!!!"
+ debug 'ERROR' 'LOOP PATHS CAN NOT BE SET'
+ exit 1
+ fi
+
# btrfs (old method)
else
IMG_DEV_BOOT_PATH="${LOOP}p1"
@@ -2027,6 +2033,13 @@ fi
echo -e "${White}## ${IWhite}Scanning filesystem and calculating..."
+# Make sure boot is mounted if it exists in fstab
+if grep -q 'boot' /etc/fstab && ! mount | grep -q 'boot'; then
+ echo '!! Boot found in fstab but partition not mounted, please mount and retry script...'
+ debug 'ERROR' 'Boot found in fstab but partition not mounted, exit 3'
+ exit 3
+fi
+
# Check what filesystem root is using and set LOCAL_DEV_PATH & PARTITION_TABLE
FSTYPE="$(mount | grep ' / ' | awk '{print $5}')"
debug 'INFO' "$FSTYPE root filesystem detected"
From 87af3f6cae2bbf9971ce612f7ce21908c189b38b Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Fri, 26 Jul 2024 05:52:03 +0200
Subject: [PATCH 12/46] No reason to SCREAM when encountering errors
- Made capital letters small.
- Color coded the error message
---
shrink-backup | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/shrink-backup b/shrink-backup
index e885b7a..b13b024 100644
--- a/shrink-backup
+++ b/shrink-backup
@@ -720,8 +720,8 @@ function do_mount() {
# Mount boot partition if exists
if [ -n "$BOOT_PATH" ]; then
if ! mount | grep -q 'boot'; then
- echo -e "${Red}!! BOOT PARTITION NOT MOUNTED ON SYSTEM, PLEASE MOUNT BOOT PARTITION AND RE-RUN THE SCRIPT!!!"
- debug 'ERROR' 'BOOT PARTITION NOT MOUNTED ON SYSTEM, PLEASE MOUNT BOOT PARTITION AND RE-RUN THE SCRIPT!!!'
+ echo -e "${Red}!! Boot found in fstab but partition not mounted, please mount and retry script!!!"
+ debug 'ERROR' 'Boot found in fstab but partition not mounted, exit 1'
exit 1
fi
echo -e "${White}## ${IWhite}Mounting img boot partition..."
@@ -2035,7 +2035,7 @@ echo -e "${White}## ${IWhite}Scanning filesystem and calculating..."
# Make sure boot is mounted if it exists in fstab
if grep -q 'boot' /etc/fstab && ! mount | grep -q 'boot'; then
- echo '!! Boot found in fstab but partition not mounted, please mount and retry script...'
+ echo -e "${Red}'!! Boot found in fstab but partition not mounted, please mount and retry script!!!'
debug 'ERROR' 'Boot found in fstab but partition not mounted, exit 3'
exit 3
fi
From aa8f026c1eeafc29b670ed4f1bb97b6d11a4e18f Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Fri, 26 Jul 2024 05:55:03 +0200
Subject: [PATCH 13/46] But in last commit
Forgot to change ' to " for `echo -e` to work.
Could be good if #39 updated and tested the functionality from testing branch.
---
shrink-backup | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/shrink-backup b/shrink-backup
index b13b024..0d08a78 100644
--- a/shrink-backup
+++ b/shrink-backup
@@ -2035,7 +2035,7 @@ echo -e "${White}## ${IWhite}Scanning filesystem and calculating..."
# Make sure boot is mounted if it exists in fstab
if grep -q 'boot' /etc/fstab && ! mount | grep -q 'boot'; then
- echo -e "${Red}'!! Boot found in fstab but partition not mounted, please mount and retry script!!!'
+ echo -e "${Red}!! Boot found in fstab but partition not mounted, please mount and retry script!!!"
debug 'ERROR' 'Boot found in fstab but partition not mounted, exit 3'
exit 3
fi
From 95c1558292131c45d3a31a647869c18fe2c7658c Mon Sep 17 00:00:00 2001
From: framp
Date: Sun, 28 Jul 2024 11:32:44 +0200
Subject: [PATCH 14/46] Initial install version
---
install | 24 +++++++++++++-----------
shrink-backup.conf | 9 +++++++++
2 files changed, 22 insertions(+), 11 deletions(-)
create mode 100644 shrink-backup.conf
diff --git a/install b/install
index 6799290..58ebbc0 100755
--- a/install
+++ b/install
@@ -11,10 +11,12 @@
set -uo pipefail
readonly PACKAGE="shrink-backup"
-readonly DOWNLOAD_REPOSITORY="https://raw.githubusercontent.com/UnconnectedBedna/shrink-backup/master"
-readonly FILES_2_DOWNLOAD"=shrink-backup"
+readonly DIR_EXE="/usr/local/sbin"
+readonly DIR_ETC="/usr/local/etc"
+readonly DOWNLOAD_REPOSITORY="https://raw.githubusercontent.com/framps/$PACKAGE/install"
+readonly FILES_2_DOWNLOAD"$PACKAGE ${PACKAGE}.conf"
+readonly FILES_2_STORE="$DIR_EXE $DIR_ETC"
readonly TMP_DIR=$(mktemp -d)
-readonly INSTALLATION_DIR="/usr/local/sbin"
pwd=$PWD
trap "{ cd $pwd; rmdir $TMP_DIR &>/dev/null; }" SIGINT SIGTERM EXIT
@@ -22,21 +24,21 @@ cd $TMP_DIR
echo "Installing $PACKAGE ..."
-for file in $FILES_2_DOWNLOAD; do
+for (( i=0; i<${#FILES_2_DOWNLOAD[@]}; i++) ); do
- echo -n "Downloading $file from $DOWNLOAD_REPOSITORY/$file ... "
- http_code=$(curl -w "%{http_code}" -L -s $DOWNLOAD_REPOSITORY/$file -o $file)
+ sourceFile=${FILES_2_DOWNLOAD[$i]}
+ targetDir=${FILES_2_STORE[$i]}
+
+ echo -n "Downloading $file from $DOWNLOAD_REPOSITORY/$sourceFile ... "
+ http_code=$(curl -w "%{http_code}" -L -s $DOWNLOAD_REPOSITORY/$sourceFile -o $sourceFile)
(( $? )) && { echo "Curl failed"; exit 1; }
[[ $http_code != 200 ]] && { echo "http request failed with $http_code"; exit 1; }
echo "done"
- echo -n "Installing $file into $INSTALLATION_DIR ... "
- sudo chmod +x $file
- (( $? )) && { echo "chmod failed"; exit 1; }
- sudo mv $file $INSTALLATION_DIR
+ echo -n "Installing $sourceFile into $targetDir ... "
+ sudo mv $sourceFile $targetDir
(( $? )) && { echo "mv failed"; exit 1; }
echo "done"
done
echo "$PACKAGE installed"
-cd $pwd
diff --git a/shrink-backup.conf b/shrink-backup.conf
new file mode 100644
index 0000000..cd351dc
--- /dev/null
+++ b/shrink-backup.conf
@@ -0,0 +1,9 @@
+/lost+found
+/proc/*
+/sys/*
+/dev/*
+/tmp/*
+/run/*
+/mnt/*
+/media/*
+/var/swap
From cb69e194879db594501d7d04ab6c436e0247286b Mon Sep 17 00:00:00 2001
From: framp
Date: Sun, 28 Jul 2024 11:54:04 +0200
Subject: [PATCH 15/46] Fixed typos
---
install | 10 ++++++----
shrink-backup | 0
2 files changed, 6 insertions(+), 4 deletions(-)
mode change 100644 => 100755 shrink-backup
diff --git a/install b/install
index 58ebbc0..ee4a18b 100755
--- a/install
+++ b/install
@@ -14,8 +14,8 @@ readonly PACKAGE="shrink-backup"
readonly DIR_EXE="/usr/local/sbin"
readonly DIR_ETC="/usr/local/etc"
readonly DOWNLOAD_REPOSITORY="https://raw.githubusercontent.com/framps/$PACKAGE/install"
-readonly FILES_2_DOWNLOAD"$PACKAGE ${PACKAGE}.conf"
-readonly FILES_2_STORE="$DIR_EXE $DIR_ETC"
+readonly FILES_2_DOWNLOAD=("$PACKAGE" "${PACKAGE}.conf")
+readonly FILES_2_STORE=("$DIR_EXE" "$DIR_ETC")
readonly TMP_DIR=$(mktemp -d)
pwd=$PWD
@@ -24,17 +24,19 @@ cd $TMP_DIR
echo "Installing $PACKAGE ..."
-for (( i=0; i<${#FILES_2_DOWNLOAD[@]}; i++) ); do
+for (( i=0; i<${#FILES_2_DOWNLOAD[@]}; i++ )); do
sourceFile=${FILES_2_DOWNLOAD[$i]}
targetDir=${FILES_2_STORE[$i]}
- echo -n "Downloading $file from $DOWNLOAD_REPOSITORY/$sourceFile ... "
+ echo -n "Downloading $sourceFile from $DOWNLOAD_REPOSITORY/$sourceFile ... "
http_code=$(curl -w "%{http_code}" -L -s $DOWNLOAD_REPOSITORY/$sourceFile -o $sourceFile)
(( $? )) && { echo "Curl failed"; exit 1; }
[[ $http_code != 200 ]] && { echo "http request failed with $http_code"; exit 1; }
echo "done"
echo -n "Installing $sourceFile into $targetDir ... "
+ sudo chmod +x $file
+ (( $? )) && { echo "chmod failed"; exit 1; }
sudo mv $sourceFile $targetDir
(( $? )) && { echo "mv failed"; exit 1; }
echo "done"
diff --git a/shrink-backup b/shrink-backup
old mode 100644
new mode 100755
From ca6ea24f9c7fc52d098824ae70af0ace37d2774a Mon Sep 17 00:00:00 2001
From: framp
Date: Sun, 28 Jul 2024 12:19:18 +0200
Subject: [PATCH 16/46] Handle LICENSE file
---
install | 35 +++++++++++++++++++++++++----------
1 file changed, 25 insertions(+), 10 deletions(-)
diff --git a/install b/install
index ee4a18b..ea80222 100755
--- a/install
+++ b/install
@@ -10,19 +10,28 @@
set -uo pipefail
-readonly PACKAGE="shrink-backup"
+readonly PACKAGE_FILE="shrink-backup"
+readonly LICENSE_FILE="LICENSE"
+readonly DIR_LICENSE="/usr/share/doc/$PACKAGE_FILE"
readonly DIR_EXE="/usr/local/sbin"
readonly DIR_ETC="/usr/local/etc"
-readonly DOWNLOAD_REPOSITORY="https://raw.githubusercontent.com/framps/$PACKAGE/install"
-readonly FILES_2_DOWNLOAD=("$PACKAGE" "${PACKAGE}.conf")
-readonly FILES_2_STORE=("$DIR_EXE" "$DIR_ETC")
+readonly DOWNLOAD_REPOSITORY="https://raw.githubusercontent.com/framps/$PACKAGE_FILE/install"
+readonly FILES_2_DOWNLOAD=("$PACKAGE_FILE" "${PACKAGE_FILE}.conf" "$LICENSE_FILE")
+readonly FILES_2_STORE=("$DIR_EXE" "$DIR_ETC" "$DIR_LICENSE")
readonly TMP_DIR=$(mktemp -d)
+function cleanup() {
+ local exitStatus=$?
+ cd $pwd
+ rmdir $TMP_DIR &>/dev/null
+ exit $exitStatus
+}
+
pwd=$PWD
-trap "{ cd $pwd; rmdir $TMP_DIR &>/dev/null; }" SIGINT SIGTERM EXIT
+trap "cleanup" SIGINT SIGTERM EXIT
cd $TMP_DIR
-echo "Installing $PACKAGE ..."
+echo "Installing $PACKAGE_FILE ..."
for (( i=0; i<${#FILES_2_DOWNLOAD[@]}; i++ )); do
@@ -35,12 +44,18 @@ for (( i=0; i<${#FILES_2_DOWNLOAD[@]}; i++ )); do
[[ $http_code != 200 ]] && { echo "http request failed with $http_code"; exit 1; }
echo "done"
echo -n "Installing $sourceFile into $targetDir ... "
- sudo chmod +x $file
- (( $? )) && { echo "chmod failed"; exit 1; }
- sudo mv $sourceFile $targetDir
+ if [[ $sourceFile == $PACKAGE_FILE ]]; then # chmod only executable
+ sudo chmod +x $sourceFile
+ (( $? )) && { echo "chmod failed"; exit 1; }
+ elif [[ $sourceFile == $LICENSE_FILE ]]; then # create LICENSE directory
+ sudo mkdir -p $DIR_LICENSE
+ (( $? )) && { echo "mkdir failed"; exit 1; }
+ fi
+ sudo mv $sourceFile ${targetDir}x
(( $? )) && { echo "mv failed"; exit 1; }
echo "done"
done
-echo "$PACKAGE installed"
+echo "$PACKAGE_FILE installed"
+exit 0
From 056bcee08ab76ac8a6a9f6a3b4677e7573ef3a1e Mon Sep 17 00:00:00 2001
From: framp
Date: Sun, 28 Jul 2024 13:06:26 +0200
Subject: [PATCH 17/46] Added INSTALL_METHOD
---
install | 43 ++++++++++++++++++++++++++++---------------
shrink-backup | 2 ++
2 files changed, 30 insertions(+), 15 deletions(-)
diff --git a/install b/install
index ea80222..4026d95 100755
--- a/install
+++ b/install
@@ -1,8 +1,6 @@
#!/bin/bash
-
-# Simple installer for shrink-backup
#
-# Downloads and installs shrink-backup into /usr/local/sbin
+# Simple installer for shrink-backup
#
# Command to use to install shrink-backup:
# curl https://raw.githubusercontent.com/UnconnectedBedna/shrink-backup/master/install | sudo bash
@@ -10,12 +8,13 @@
set -uo pipefail
+readonly REPOSITORY="framps"
readonly PACKAGE_FILE="shrink-backup"
readonly LICENSE_FILE="LICENSE"
readonly DIR_LICENSE="/usr/share/doc/$PACKAGE_FILE"
readonly DIR_EXE="/usr/local/sbin"
readonly DIR_ETC="/usr/local/etc"
-readonly DOWNLOAD_REPOSITORY="https://raw.githubusercontent.com/framps/$PACKAGE_FILE/install"
+readonly DOWNLOAD_REPOSITORY="https://raw.githubusercontent.com/$REPOSITORY/$PACKAGE_FILE/install"
readonly FILES_2_DOWNLOAD=("$PACKAGE_FILE" "${PACKAGE_FILE}.conf" "$LICENSE_FILE")
readonly FILES_2_STORE=("$DIR_EXE" "$DIR_ETC" "$DIR_LICENSE")
readonly TMP_DIR=$(mktemp -d)
@@ -24,6 +23,11 @@ function cleanup() {
local exitStatus=$?
cd $pwd
rmdir $TMP_DIR &>/dev/null
+ if (( $exitStatus > 0 )); then
+ echo "Installation of $PACKAGE_FILE failed with rc $exitStatus"
+ else
+ echo "$PACKAGE_FILE usccessfully installed"
+ fi
exit $exitStatus
}
@@ -35,27 +39,36 @@ echo "Installing $PACKAGE_FILE ..."
for (( i=0; i<${#FILES_2_DOWNLOAD[@]}; i++ )); do
- sourceFile=${FILES_2_DOWNLOAD[$i]}
- targetDir=${FILES_2_STORE[$i]}
+ sourceFile="${FILES_2_DOWNLOAD[$i]}"
+ targetDir="${FILES_2_STORE[$i]}"
echo -n "Downloading $sourceFile from $DOWNLOAD_REPOSITORY/$sourceFile ... "
http_code=$(curl -w "%{http_code}" -L -s $DOWNLOAD_REPOSITORY/$sourceFile -o $sourceFile)
+
(( $? )) && { echo "Curl failed"; exit 1; }
[[ $http_code != 200 ]] && { echo "http request failed with $http_code"; exit 1; }
echo "done"
+
echo -n "Installing $sourceFile into $targetDir ... "
- if [[ $sourceFile == $PACKAGE_FILE ]]; then # chmod only executable
- sudo chmod +x $sourceFile
- (( $? )) && { echo "chmod failed"; exit 1; }
- elif [[ $sourceFile == $LICENSE_FILE ]]; then # create LICENSE directory
- sudo mkdir -p $DIR_LICENSE
- (( $? )) && { echo "mkdir failed"; exit 1; }
+ sudo chown root:root "${sourceFile}"
+ (( $? )) && { echo "chown of $sourceFile failed"; exit 1; }
+
+ sudo chmod 755 "${sourceFile}"
+ (( $? )) && { echo "chmod of $sourceFile failed"; exit 1; }
+
+ if [[ "$sourceFile" == "$PACKAGE_FILE" ]]; then # existing executable bit in github is not reflected by curl
+ sudo chmod +x "$sourceFile"
+ (( $? )) && { echo "chmod of $sourceFile failed"; exit 1; }
+ sed --follow-symlinks -i "s/INSTALL_METHOD=/INSTALL_METHOD=\"curl\"/" "$sourceFile"
+ (( $? )) && { echo "sed of $sourceFile failed"; exit 1; }
+ elif [[ "$sourceFile" == "$LICENSE_FILE" ]]; then # create LICENSE directory
+ sudo mkdir -p "$DIR_LICENSE"
+ (( $? )) && { echo "mkdir of $DIR_LICENSE failed"; exit 1; }
fi
- sudo mv $sourceFile ${targetDir}x
- (( $? )) && { echo "mv failed"; exit 1; }
+ sudo mv "${sourceFile}" "${targetDir}"
+ (( $? )) && { echo "mv of $sourceFile failed"; exit 1; }
echo "done"
done
-echo "$PACKAGE_FILE installed"
exit 0
diff --git a/shrink-backup b/shrink-backup
index c86a0bb..dfd9365 100755
--- a/shrink-backup
+++ b/shrink-backup
@@ -12,6 +12,8 @@
# LICENSE file in the root directory of this source tree.
##############################################################################
+INSTALL_METHOD=
+
# Function to clean up resources on script exit or termination
function cleanup() {
# exit 0 = cleanup after script
From cf54e5b67c9d26d0151a610b1e469ddf41187773 Mon Sep 17 00:00:00 2001
From: framp
Date: Sun, 28 Jul 2024 14:05:46 +0200
Subject: [PATCH 18/46] PR review comments ahdnled
---
install => installer.sh | 4 ++--
shrink-backup | 3 +--
2 files changed, 3 insertions(+), 4 deletions(-)
rename install => installer.sh (94%)
diff --git a/install b/installer.sh
similarity index 94%
rename from install
rename to installer.sh
index 4026d95..84afffb 100755
--- a/install
+++ b/installer.sh
@@ -26,7 +26,7 @@ function cleanup() {
if (( $exitStatus > 0 )); then
echo "Installation of $PACKAGE_FILE failed with rc $exitStatus"
else
- echo "$PACKAGE_FILE usccessfully installed"
+ echo "$PACKAGE_FILE successfully installed"
fi
exit $exitStatus
}
@@ -59,7 +59,7 @@ for (( i=0; i<${#FILES_2_DOWNLOAD[@]}; i++ )); do
if [[ "$sourceFile" == "$PACKAGE_FILE" ]]; then # existing executable bit in github is not reflected by curl
sudo chmod +x "$sourceFile"
(( $? )) && { echo "chmod of $sourceFile failed"; exit 1; }
- sed --follow-symlinks -i "s/INSTALL_METHOD=/INSTALL_METHOD=\"curl\"/" "$sourceFile"
+ sed --follow-symlinks -i -E "s/^(INSTALL_METHOD=).+$/\1=\'curl\'/" "$sourceFile"
(( $? )) && { echo "sed of $sourceFile failed"; exit 1; }
elif [[ "$sourceFile" == "$LICENSE_FILE" ]]; then # create LICENSE directory
sudo mkdir -p "$DIR_LICENSE"
diff --git a/shrink-backup b/shrink-backup
index dfd9365..87fc638 100755
--- a/shrink-backup
+++ b/shrink-backup
@@ -12,8 +12,6 @@
# LICENSE file in the root directory of this source tree.
##############################################################################
-INSTALL_METHOD=
-
# Function to clean up resources on script exit or termination
function cleanup() {
# exit 0 = cleanup after script
@@ -126,6 +124,7 @@ function pause() {
#pause 'Press [Enter] key to continue...'
# Set default values for script options
+INSTALL_METHOD='default'
PROMPTS=true
DEBUG=false
EXCLUDE_FILE=false
From 371299085b2212f3f9223b077f994f1dbf6b197d Mon Sep 17 00:00:00 2001
From: framp
Date: Sun, 28 Jul 2024 14:08:16 +0200
Subject: [PATCH 19/46] Fixed typo
---
installer.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/installer.sh b/installer.sh
index 84afffb..1438689 100755
--- a/installer.sh
+++ b/installer.sh
@@ -59,7 +59,7 @@ for (( i=0; i<${#FILES_2_DOWNLOAD[@]}; i++ )); do
if [[ "$sourceFile" == "$PACKAGE_FILE" ]]; then # existing executable bit in github is not reflected by curl
sudo chmod +x "$sourceFile"
(( $? )) && { echo "chmod of $sourceFile failed"; exit 1; }
- sed --follow-symlinks -i -E "s/^(INSTALL_METHOD=).+$/\1=\'curl\'/" "$sourceFile"
+ sed --follow-symlinks -i -E "s/^(INSTALL_METHOD)=)+$/\1=\'curl\'/" "$sourceFile"
(( $? )) && { echo "sed of $sourceFile failed"; exit 1; }
elif [[ "$sourceFile" == "$LICENSE_FILE" ]]; then # create LICENSE directory
sudo mkdir -p "$DIR_LICENSE"
From ed3076fd57f8e3dd56f1939ecbd94c7417dedbb7 Mon Sep 17 00:00:00 2001
From: framp
Date: Sun, 28 Jul 2024 14:08:16 +0200
Subject: [PATCH 20/46] Fixed typo
---
installer.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/installer.sh b/installer.sh
index 84afffb..af71e95 100755
--- a/installer.sh
+++ b/installer.sh
@@ -59,7 +59,7 @@ for (( i=0; i<${#FILES_2_DOWNLOAD[@]}; i++ )); do
if [[ "$sourceFile" == "$PACKAGE_FILE" ]]; then # existing executable bit in github is not reflected by curl
sudo chmod +x "$sourceFile"
(( $? )) && { echo "chmod of $sourceFile failed"; exit 1; }
- sed --follow-symlinks -i -E "s/^(INSTALL_METHOD=).+$/\1=\'curl\'/" "$sourceFile"
+ sed --follow-symlinks -i -E "s/^(INSTALL_METHOD)=.+$/\1=\'curl\'/" "$sourceFile"
(( $? )) && { echo "sed of $sourceFile failed"; exit 1; }
elif [[ "$sourceFile" == "$LICENSE_FILE" ]]; then # create LICENSE directory
sudo mkdir -p "$DIR_LICENSE"
From f90588c2d3f61f8709f8b402133fbfafc32b553a Mon Sep 17 00:00:00 2001
From: framp
Date: Sun, 28 Jul 2024 14:53:58 +0200
Subject: [PATCH 21/46] Added README.md
---
installer.sh | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/installer.sh b/installer.sh
index af71e95..4f4cfd5 100755
--- a/installer.sh
+++ b/installer.sh
@@ -11,12 +11,13 @@ set -uo pipefail
readonly REPOSITORY="framps"
readonly PACKAGE_FILE="shrink-backup"
readonly LICENSE_FILE="LICENSE"
+readonly README_FILE="README.md"
readonly DIR_LICENSE="/usr/share/doc/$PACKAGE_FILE"
readonly DIR_EXE="/usr/local/sbin"
readonly DIR_ETC="/usr/local/etc"
readonly DOWNLOAD_REPOSITORY="https://raw.githubusercontent.com/$REPOSITORY/$PACKAGE_FILE/install"
-readonly FILES_2_DOWNLOAD=("$PACKAGE_FILE" "${PACKAGE_FILE}.conf" "$LICENSE_FILE")
-readonly FILES_2_STORE=("$DIR_EXE" "$DIR_ETC" "$DIR_LICENSE")
+readonly FILES_2_DOWNLOAD=("$PACKAGE_FILE" "${PACKAGE_FILE}.conf" "$LICENSE_FILE" "$README_FILE")
+readonly FILES_2_STORE=("$DIR_EXE" "$DIR_ETC" "$DIR_LICENSE" "$DIR_LICENSE")
readonly TMP_DIR=$(mktemp -d)
function cleanup() {
@@ -61,9 +62,11 @@ for (( i=0; i<${#FILES_2_DOWNLOAD[@]}; i++ )); do
(( $? )) && { echo "chmod of $sourceFile failed"; exit 1; }
sed --follow-symlinks -i -E "s/^(INSTALL_METHOD)=.+$/\1=\'curl\'/" "$sourceFile"
(( $? )) && { echo "sed of $sourceFile failed"; exit 1; }
- elif [[ "$sourceFile" == "$LICENSE_FILE" ]]; then # create LICENSE directory
+ elif [[ ! -d "$DIR_LICENSE" ]] && [[ "$sourceFile" == "$LICENSE_FILE" || "$sourceFile" == "$README_FILE" ]] ; then # create LICENSE directory
sudo mkdir -p "$DIR_LICENSE"
(( $? )) && { echo "mkdir of $DIR_LICENSE failed"; exit 1; }
+ sudo chown root:root "${DIR_LICENSE}/.."
+ (( $? )) && { echo "chown of ${DIR_LICENSE}/.. failed"; exit 1; }
fi
sudo mv "${sourceFile}" "${targetDir}"
(( $? )) && { echo "mv of $sourceFile failed"; exit 1; }
From 010f4b65d7ea6316e06736ba081762b5589edfa3 Mon Sep 17 00:00:00 2001
From: framp
Date: Sun, 28 Jul 2024 15:05:44 +0200
Subject: [PATCH 22/46] Use better var name for doc dir
---
installer.sh | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/installer.sh b/installer.sh
index 4f4cfd5..93930e7 100755
--- a/installer.sh
+++ b/installer.sh
@@ -8,16 +8,19 @@
set -uo pipefail
-readonly REPOSITORY="framps"
+# Has to be updatedwhen PR is accepted
+readonly REPOSITORY="framps" # UnconnectedBedna
+readonly BRANCH="install" # testing
+
readonly PACKAGE_FILE="shrink-backup"
readonly LICENSE_FILE="LICENSE"
readonly README_FILE="README.md"
-readonly DIR_LICENSE="/usr/share/doc/$PACKAGE_FILE"
+readonly DIR_DOC="/usr/share/doc/$PACKAGE_FILE"
readonly DIR_EXE="/usr/local/sbin"
readonly DIR_ETC="/usr/local/etc"
-readonly DOWNLOAD_REPOSITORY="https://raw.githubusercontent.com/$REPOSITORY/$PACKAGE_FILE/install"
+readonly DOWNLOAD_REPOSITORY="https://raw.githubusercontent.com/$REPOSITORY/$PACKAGE_FILE/$BRANCH"
readonly FILES_2_DOWNLOAD=("$PACKAGE_FILE" "${PACKAGE_FILE}.conf" "$LICENSE_FILE" "$README_FILE")
-readonly FILES_2_STORE=("$DIR_EXE" "$DIR_ETC" "$DIR_LICENSE" "$DIR_LICENSE")
+readonly FILES_2_STORE=("$DIR_EXE" "$DIR_ETC" "$DIR_DOC" "$DIR_DOC")
readonly TMP_DIR=$(mktemp -d)
function cleanup() {
@@ -62,11 +65,11 @@ for (( i=0; i<${#FILES_2_DOWNLOAD[@]}; i++ )); do
(( $? )) && { echo "chmod of $sourceFile failed"; exit 1; }
sed --follow-symlinks -i -E "s/^(INSTALL_METHOD)=.+$/\1=\'curl\'/" "$sourceFile"
(( $? )) && { echo "sed of $sourceFile failed"; exit 1; }
- elif [[ ! -d "$DIR_LICENSE" ]] && [[ "$sourceFile" == "$LICENSE_FILE" || "$sourceFile" == "$README_FILE" ]] ; then # create LICENSE directory
- sudo mkdir -p "$DIR_LICENSE"
- (( $? )) && { echo "mkdir of $DIR_LICENSE failed"; exit 1; }
- sudo chown root:root "${DIR_LICENSE}/.."
- (( $? )) && { echo "chown of ${DIR_LICENSE}/.. failed"; exit 1; }
+ elif [[ ! -d "$DIR_DOC" ]] && [[ "$sourceFile" == "$LICENSE_FILE" || "$sourceFile" == "$README_FILE" ]] ; then # create LICENSE directory
+ sudo mkdir -p "$DIR_DOC"
+ (( $? )) && { echo "mkdir of $DIR_DOC failed"; exit 1; }
+ sudo chown root:root "${DIR_DOC}/.."
+ (( $? )) && { echo "chown of ${DIR_SOC}/.. failed"; exit 1; }
fi
sudo mv "${sourceFile}" "${targetDir}"
(( $? )) && { echo "mv of $sourceFile failed"; exit 1; }
From c50772289766895425d92ac0945ded7cfbea7d98 Mon Sep 17 00:00:00 2001
From: framp
Date: Sun, 28 Jul 2024 15:20:59 +0200
Subject: [PATCH 23/46] Updated curl call description
---
installer.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/installer.sh b/installer.sh
index 93930e7..87803b3 100755
--- a/installer.sh
+++ b/installer.sh
@@ -3,12 +3,12 @@
# Simple installer for shrink-backup
#
# Command to use to install shrink-backup:
-# curl https://raw.githubusercontent.com/UnconnectedBedna/shrink-backup/master/install | sudo bash
+# curl https://raw.githubusercontent.com/UnconnectedBedna/shrink-backup/main/installer.sh | sudo bash
#
set -uo pipefail
-# Has to be updatedwhen PR is accepted
+# Has to be updated when PR is accepted
readonly REPOSITORY="framps" # UnconnectedBedna
readonly BRANCH="install" # testing
From d7c85d20cedb6d53940d698a382b288370ee6186 Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Sun, 28 Jul 2024 15:32:52 +0200
Subject: [PATCH 24/46] Update shrink-backup for curl install script
Help snippet and such is not yet updated to reference the new filename of `exclude.txt` into shrink-backup.conf
Cleanup of unnecessary files is needed but no rush.
---
shrink-backup | 36 ++++++++++++++++++++++++++----------
1 file changed, 26 insertions(+), 10 deletions(-)
diff --git a/shrink-backup b/shrink-backup
index d95efa1..27fd65e 100755
--- a/shrink-backup
+++ b/shrink-backup
@@ -129,7 +129,13 @@ EXCLUDE_FILE=false
AUTOEXPAND=true
AUTORESIZE_RUN=false
UPDATE=false
-LOG_FILE="$(dirname $0)/shrink-backup.log"
+if $INSTALL_METHOD='curl'; then
+ LOG_FILE='/var/log/shrink-backup.log'
+ EXCLUDE_FILE_LOCATION='/usr/local/etc/shrink-backup.conf'
+else
+ LOG_FILE="$(dirname $0)/shrink-backup.log"
+ EXCLUDE_FILE_LOCATION="$(dirname $0)/shrink-backup.conf"
+fi
AUTORESIZE_WARNING=false
ZOOM=false
LOOPRUN=false
@@ -138,7 +144,6 @@ F2FS=false
#STARTLINE="$0 $*" # will produce double // if script is in $PATH
STARTLINE="$(dirname $0)/$(basename $0) $*" # will produce absolute path if script is in $PATH
#STARTLINE="$(realpath $0) $*" # same as bove, but will ALWYAS produce absolute path
-#x=0
COLS=85
BREAK="$(printf "%${COLS}s" | tr " " "#")"
@@ -464,7 +469,8 @@ function get_btrfs_variables() {
if [ "$EXCLUDE_FILE" = true ]; then
debug 'INFO' 'Filtering out volumes from exclude.txt'
for ((i = 0; i < ${#LOCAL_SUBVOLUMES[@]}; i++)); do
- if $(echo "/${LOCAL_SUBVOLUMES[i]}" | grep -q -f "$(dirname $0)/exclude.txt"); then
+ #if $(echo "/${LOCAL_SUBVOLUMES[i]}" | grep -q -f "$(dirname $0)/exclude.txt"); then
+ if $(echo "/${LOCAL_SUBVOLUMES[i]}" | grep -q -f "$EXCLUDE_FILE_LOCATION"); then
debug 'DEBUG' "Filtering out subvolume: ${LOCAL_SUBVOLUMES[i]}"
unset LOCAL_SUBVOLUMES["$i"]
fi
@@ -971,8 +977,10 @@ function do_rsync() {
debug 'DEBUG' "tmp_file=$tmp_file"
if [ "$EXCLUDE_FILE" = true ]; then
- debug 'DEBUG' "Running: rsync -ahvHAX --exclude-from=$(dirname $0)/exclude.txt --exclude={${IMG_PATH}/*,${TMP_DIR},${tmp_file}} --info=progress2 --stats "$RSYNC_DELETE" --force --partial --delete-excluded / $TMP_DIR"
- rsync -ahvHAX --exclude-from=$(dirname "$0")/exclude.txt --exclude={${IMG_PATH}/*,${TMP_DIR},${tmp_file}} --info=progress2 --stats "$RSYNC_DELETE" --force --partial --delete-excluded / "$TMP_DIR" 2>&1 | tee "$TTY_AVAILABILITY" > "$tmp_file"
+ #debug 'DEBUG' "Running: rsync -ahvHAX --exclude-from=$(dirname $0)/exclude.txt --exclude={${IMG_PATH}/*,${TMP_DIR},${tmp_file}} --info=progress2 --stats "$RSYNC_DELETE" --force --partial --delete-excluded / $TMP_DIR"
+ debug 'DEBUG' "Running: rsync -ahvHAX --exclude-from="$EXCLUDE_FILE_LOCATION" --exclude={${IMG_PATH}/*,${TMP_DIR},${tmp_file}} --info=progress2 --stats "$RSYNC_DELETE" --force --partial --delete-excluded / $TMP_DIR"
+ #rsync -ahvHAX --exclude-from=$(dirname "$0")/exclude.txt --exclude={${IMG_PATH}/*,${TMP_DIR},${tmp_file}} --info=progress2 --stats "$RSYNC_DELETE" --force --partial --delete-excluded / "$TMP_DIR" 2>&1 | tee "$TTY_AVAILABILITY" > "$tmp_file"
+ rsync -ahvHAX --exclude-from="$EXCLUDE_FILE_LOCATION" --exclude={${IMG_PATH}/*,${TMP_DIR},${tmp_file}} --info=progress2 --stats "$RSYNC_DELETE" --force --partial --delete-excluded / "$TMP_DIR" 2>&1 | tee "$TTY_AVAILABILITY" > "$tmp_file"
# Get the exit status of rsync from PIPESTATUS
if [ "${PIPESTATUS[0]}" -ne 0 ] && [ "${PIPESTATUS[0]}" -ne 23 ]; then # code 23 = rsync warning: some files vanished before they could be transferred (code 24) at main.c
output=$(tail -16 "$tmp_file")
@@ -2098,14 +2106,22 @@ if [ "$DEBUG" = true ]; then
fi
# Check if usage of exclude.txt is requested
+# if [ "$EXCLUDE_FILE" = true ]; then
+# debug 'INFO' "-f selected by user, using $(dirname $0)/exclude.txt"
+# if ! [ -f $(dirname "$0")/exclude.txt ]; then
+# echo -e "${Red}!! ERROR! ${Green}-f selected but exclude.txt ${Yellow}is not present in script directory!"
+# debug 'ERROR' 'exclude.txt does not exist in script directory, exit 3'
+# exit 3
+# fi
+# debug 'DEBUG' "$(dirname $0)/exclude.txt exists"
if [ "$EXCLUDE_FILE" = true ]; then
- debug 'INFO' "-f selected by user, using $(dirname $0)/exclude.txt"
- if ! [ -f $(dirname "$0")/exclude.txt ]; then
- echo -e "${Red}!! ERROR! ${Green}-f selected but exclude.txt ${Yellow}is not present in script directory!"
- debug 'ERROR' 'exclude.txt does not exist in script directory, exit 3'
+ debug 'INFO' "-f selected by user, using $EXCLUDE_FILE_LOCATION"
+ if ! [ -f "$EXCLUDE_FILE_LOCATION" ]; then
+ echo -e "${Red}!! ERROR! ${Green}-f selected but shrink-backup.conf ${Yellow}does not exist!"
+ debug 'ERROR' 'shrink-backup.conf does not exist, exit 3'
exit 3
fi
- debug 'DEBUG' "$(dirname $0)/exclude.txt exists"
+ debug 'DEBUG' "$EXCLUDE_FILE_LOCATION exists"
else
debug 'INFO' '-f NOT selected by user, using default exclude directories'
fi
From 4815f02b16414ca07359f84b0ceff612d9133c25 Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Fri, 2 Aug 2024 15:03:44 +0200
Subject: [PATCH 25/46] Fixed bug if other localisation than English is used
As discussed in bug #45
Thank you to [mandresve](https://github.com/mandresve) for the solution!
---
shrink-backup | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/shrink-backup b/shrink-backup
index 27fd65e..272aacc 100755
--- a/shrink-backup
+++ b/shrink-backup
@@ -391,7 +391,8 @@ function get_dev_variables() {
# Set automated calculated size (get_btrfs_variables if btrfs filesystem)
if [ "$AUTORESIZE_RUN" = true ] || [ "$UPDATE" = false ] || [ "$FSTYPE" == 'btrfs' ]; then
debug 'INFO' 'Calculating recommended root size'
- BLOCKSIZE=$(stat -f / | grep -i 'Block size' | awk '{print $3}') # bytes
+ #BLOCKSIZE=$(stat -f / | grep -i 'Block size' | awk '{print $3}') # bytes
+ BLOCKSIZE=$(stat -fc %s /) # bytes, so it works with other localisations
debug 'DEBUG' "BLOCKSIZE=${BLOCKSIZE} bytes"
if [ "$FSTYPE" == 'ext4' ]; then
debug 'INFO' 'ext4 filesystem detected, using resize2fs to set recommended root size'
From 2160c2b240db797ee3e21ed0cb2f584e6b3c39b5 Mon Sep 17 00:00:00 2001
From: framps
Date: Fri, 2 Aug 2024 21:24:21 +0200
Subject: [PATCH 26/46] Fixed typo
---
shrink-backup | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/shrink-backup b/shrink-backup
index 272aacc..6c4f63c 100755
--- a/shrink-backup
+++ b/shrink-backup
@@ -129,7 +129,7 @@ EXCLUDE_FILE=false
AUTOEXPAND=true
AUTORESIZE_RUN=false
UPDATE=false
-if $INSTALL_METHOD='curl'; then
+if [ $INSTALL_METHOD='curl' ]; then
LOG_FILE='/var/log/shrink-backup.log'
EXCLUDE_FILE_LOCATION='/usr/local/etc/shrink-backup.conf'
else
From f5227d022551b7dedf49f5c39a0057b53a57d4c3 Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Fri, 2 Aug 2024 21:48:15 +0200
Subject: [PATCH 27/46] Bug fix #40
Fix for #40
On CM4 if using nvme hat, it creates 2 boot disks used if booting from other devices than mmcblk.
A simple `head -1` to filter out the correct device path did the trick.
---
shrink-backup | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/shrink-backup b/shrink-backup
index 272aacc..a53c0a0 100755
--- a/shrink-backup
+++ b/shrink-backup
@@ -2059,7 +2059,7 @@ if [ "$FSTYPE" == 'ext4' ] || [ "$FSTYPE" == 'f2fs' ]; then
else
LOCAL_DEV_PTUUID=$(lsblk -no fsroots,ptuuid | grep '/ ' | awk '{print $2}')
fi
-LOCAL_DEV_PATH=$(lsblk -no ptuuid,type,path | grep "$LOCAL_DEV_PTUUID" | grep 'disk' | awk '{print $3}')
+LOCAL_DEV_PATH=$(lsblk -no ptuuid,type,path | grep "$LOCAL_DEV_PTUUID" | grep 'disk' | awk '{print $3}' | head -1)
debug 'DEBUG' "LOCAL_DEV_PTUUID=$LOCAL_DEV_PTUUID | LOCAL_DEV_PATH=$LOCAL_DEV_PATH"
PARTITION_TABLE=$(parted "$LOCAL_DEV_PATH" print | grep -i 'Partition Table' | awk '{print $3}')
#PARTITION_TABLE=$(blkid "$LOCAL_DEV_PATH" | sed -n 's|^.*PTTYPE="\(\S\+\)".*|\1|p')
From 65c727994b91f62c2dffdf9447abec7939e9ed39 Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Fri, 2 Aug 2024 22:05:06 +0200
Subject: [PATCH 28/46] Inconsitency corrections
---
shrink-backup | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/shrink-backup b/shrink-backup
index a53c0a0..227b407 100755
--- a/shrink-backup
+++ b/shrink-backup
@@ -1171,7 +1171,7 @@ function make_img() {
$SLEEPING
# Loop img file
- debug 'DEBUG' 'Running function: do_loop'
+ debug 'INFO' 'Running function: do_loop'
do_loop
# set img variables
@@ -1554,7 +1554,7 @@ function make_img() {
# Final check of created img file
if [ "$FSTYPE" == 'ext4' ] && [ "$F2FS" = false ]; then
- debug 'INFO' "Running do_e2fsck 'final'"
+ debug 'INFO' "Running function: do_e2fsck 'final'"
do_e2fsck 'final'
fi
From f5b5bb59c19abced88f8612a76852422cf1cf992 Mon Sep 17 00:00:00 2001
From: framps
Date: Fri, 2 Aug 2024 22:34:59 +0200
Subject: [PATCH 29/46] PR feddback
---
shrink-backup | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/shrink-backup b/shrink-backup
index 6c4f63c..a46e97d 100755
--- a/shrink-backup
+++ b/shrink-backup
@@ -129,7 +129,7 @@ EXCLUDE_FILE=false
AUTOEXPAND=true
AUTORESIZE_RUN=false
UPDATE=false
-if [ $INSTALL_METHOD='curl' ]; then
+if [ $INSTALL_METHOD = 'curl' ]; then
LOG_FILE='/var/log/shrink-backup.log'
EXCLUDE_FILE_LOCATION='/usr/local/etc/shrink-backup.conf'
else
From 7a9b91af253d1d160de72914817f1e87b25fff5c Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Sat, 3 Aug 2024 01:12:09 +0200
Subject: [PATCH 30/46] Fixed typo, again...
I forgot to mention to use " around variables for script consistency in the PR that made the last commit.
---
shrink-backup | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/shrink-backup b/shrink-backup
index cd9deef..dc8cc35 100755
--- a/shrink-backup
+++ b/shrink-backup
@@ -129,7 +129,7 @@ EXCLUDE_FILE=false
AUTOEXPAND=true
AUTORESIZE_RUN=false
UPDATE=false
-if [ $INSTALL_METHOD = 'curl' ]; then
+if [ "$INSTALL_METHOD" = 'curl' ]; then
LOG_FILE='/var/log/shrink-backup.log'
EXCLUDE_FILE_LOCATION='/usr/local/etc/shrink-backup.conf'
else
From aa6b29bf8ec2a468d8ab1ea25fc7b83e846bb19c Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Wed, 7 Aug 2024 12:03:56 +0200
Subject: [PATCH 31/46] Fix for files exclude.txt and shrink-backup.conf
The file `shrink-backup.conf` will be removed from the testing branch before merged into main.
If using curl the file `exclude.txt` will be renamed in the "installation".
#48
---
shrink-backup | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/shrink-backup b/shrink-backup
index dc8cc35..cbe762a 100755
--- a/shrink-backup
+++ b/shrink-backup
@@ -134,7 +134,7 @@ if [ "$INSTALL_METHOD" = 'curl' ]; then
EXCLUDE_FILE_LOCATION='/usr/local/etc/shrink-backup.conf'
else
LOG_FILE="$(dirname $0)/shrink-backup.log"
- EXCLUDE_FILE_LOCATION="$(dirname $0)/shrink-backup.conf"
+ EXCLUDE_FILE_LOCATION="$(dirname $0)/exclude.txt"
fi
AUTORESIZE_WARNING=false
ZOOM=false
From a0e470e7ddc9cc888a31c61be250bfd658b6876a Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Sun, 8 Sep 2024 22:41:15 +0200
Subject: [PATCH 32/46] Create CONTRIBUTING.md
PR:s are to be made to the testing branch, and in bash, the indentation is 2.
---
.github/CONTRIBUTING.md | 2 ++
1 file changed, 2 insertions(+)
create mode 100644 .github/CONTRIBUTING.md
diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
new file mode 100644
index 0000000..b9496c1
--- /dev/null
+++ b/.github/CONTRIBUTING.md
@@ -0,0 +1,2 @@
+All pull requests have to be made to the testing branch.
+Please try to follow the standards in the script, naming conversion, indentation (2 in bash) etc.
From 12f7fa722f8df9fc7df8c34663a786d7c7931398 Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Tue, 15 Oct 2024 13:05:39 +0200
Subject: [PATCH 33/46] Bug fix for issue #50
Fix for #50
Implemented the 3x loop when checking for device path on systems without a boot partition.
---
shrink-backup | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/shrink-backup b/shrink-backup
index cbe762a..c6992ae 100755
--- a/shrink-backup
+++ b/shrink-backup
@@ -117,7 +117,6 @@ trap "exit 10" SIGINT
function pause() {
read -p "$*"
}
-
# Uncomment the following line to enable the pause function
#pause 'Press [Enter] key to continue...'
@@ -269,7 +268,7 @@ do
done
# Check if script is run as root
-if [ "$EUID" != 0 ]; then
+if [ "$EUID" -ne 0 ]; then
echo -e "${Red}!! THIS SCRIPT MUST BE RUN AS ROOT! (WITH SUDO)"
help
fi
@@ -628,6 +627,22 @@ function set_img_variables() {
#pause 'Press [Enter] key to continue...'
IMG_DEV_ROOT_PATH=$(lsblk -no path,uuid "$LOOP" | grep "$LOCAL_ROOT_UUID" | awk '{print $1}')
debug 'DEBUG' "IMG_DEV_ROOT_PATH=$IMG_DEV_ROOT_PATH"
+ # 2s sleep is sometimes not enough, might have to do with slow network if img file is on a network share
+ if ! [ -e "$IMG_DEV_ROOT_PATH" ]; then
+ for (( i=1; i<=3; i++ )); do
+ echo -e "${Yellow}!! ${Yellow}LOOP paths can not be set, retrying in 5 seconds..."
+ debug 'WARNING' 'LOOP paths can not be set, retrying in 5 seconds'
+ debug 'WARNING' "IMG_DEV_ROOT_PATH=$IMG_DEV_ROOT_PATH"
+ sleep 5
+ IMG_DEV_ROOT_PATH=$(lsblk -no path,uuid "$LOOP" | grep "$LOCAL_ROOT_UUID" | awk '{print $1}')
+ if [ -e "$IMG_DEV_ROOT_PATH" ]; then
+ echo -e "${White}## ${Green}LOOP paths found, resuming backup..."
+ debug 'INFO' "LOOP paths found, resuming backup"
+ debug 'DEBUG' "IMG_DEV_ROOT_PATH=$IMG_DEV_ROOT_PATH"
+ break
+ fi
+ done
+ fi
fi
return 0
}
From cd855937b0430c1520ace8be8e3a7ceab9bb1416 Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Tue, 15 Oct 2024 13:39:15 +0200
Subject: [PATCH 34/46] Bugfix #50
Bugfix #50
Forgot to add the exit code if the device path is not found.
---
shrink-backup | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/shrink-backup b/shrink-backup
index c6992ae..6dc9418 100755
--- a/shrink-backup
+++ b/shrink-backup
@@ -643,6 +643,12 @@ function set_img_variables() {
fi
done
fi
+
+ if ! [ -e "$IMG_DEV_ROOT_PATH" ]; then
+ echo -e "${Red}!! LOOP PATHS CAN NOT BE SET!!!"
+ debug 'ERROR' 'LOOP PATHS CAN NOT BE SET'
+ exit 1
+ fi
fi
return 0
}
From e4c990d7f0661754eff2361e1f444b0415f03e04 Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Tue, 15 Oct 2024 18:01:59 +0200
Subject: [PATCH 35/46] QOL changes
- Added info in --loop window how to remove the loop
- Cleaned up old code comments not needed
- Changed the incorrect labeling 4k to 512B when calculating size to dd
---
shrink-backup | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/shrink-backup b/shrink-backup
index 6dc9418..fdf4f0e 100755
--- a/shrink-backup
+++ b/shrink-backup
@@ -329,6 +329,7 @@ function looprun() {
done
echo -e "${Purple}##############################################################################"
echo -e "${White}## ${Green}Done."
+ echo -e "${White}## ${IWhite}To remove loop type: ${Green}sudo losetup -d ${LOOP}"
debug 'DEBUG' 'Exiting script, exit 2'
if [ "$DEBUG" = true ]; then
@@ -384,7 +385,7 @@ function get_dev_variables() {
LOCAL_ROOT_START=$(( LOCAL_ROOT_START * 512 )) # bytes
LOCAL_BOOTSECTOR=$(( LOCAL_BOOTSECTOR * 512 )) # bytes
LOCAL_DDBOOTSECTOR=$(( (LOCAL_BOOTSECTOR + 5242880) / 512 )) # 512B blocks, 5242880 = 5MiB in bytes
- debug 'DEBUG' "LOCAL_ROOT_START=$LOCAL_ROOT_START bytes | LOCAL_BOOTSECTOR=$LOCAL_BOOTSECTOR bytes | LOCAL_DDBOOTSECTOR=$LOCAL_DDBOOTSECTOR 4k blocks"
+ debug 'DEBUG' "LOCAL_ROOT_START=$LOCAL_ROOT_START bytes | LOCAL_BOOTSECTOR=$LOCAL_BOOTSECTOR bytes | LOCAL_DDBOOTSECTOR=$LOCAL_DDBOOTSECTOR 512B blocks"
#fi
# Set automated calculated size (get_btrfs_variables if btrfs filesystem)
@@ -583,7 +584,6 @@ function set_img_variables() {
# ext4 & f2fs
if [ "$FSTYPE" == 'ext4' ] || [ "$FSTYPE" == 'f2fs' ]; then
- # I have no idea why, but if I do not put this sleep here, IMG_DEV_BOOT_PATH does not get set
sleep 2
IMG_DEV_BOOT_PATH=$(lsblk -no path,uuid "$LOOP" | grep "$LOCAL_BOOT_UUID" | awk '{print $1}')
IMG_DEV_ROOT_PATH=$(lsblk -no path,uuid "$LOOP" | grep "$LOCAL_ROOT_UUID" | awk '{print $1}')
@@ -622,9 +622,7 @@ function set_img_variables() {
# No boot partition exists
else
debug 'INFO' 'No boot partition detected'
- # I have no idea why, but if I do not put this sleep here, IMG_DEV_ROOT_PATH does not get set
sleep 2
- #pause 'Press [Enter] key to continue...'
IMG_DEV_ROOT_PATH=$(lsblk -no path,uuid "$LOOP" | grep "$LOCAL_ROOT_UUID" | awk '{print $1}')
debug 'DEBUG' "IMG_DEV_ROOT_PATH=$IMG_DEV_ROOT_PATH"
# 2s sleep is sometimes not enough, might have to do with slow network if img file is on a network share
@@ -643,7 +641,7 @@ function set_img_variables() {
fi
done
fi
-
+
if ! [ -e "$IMG_DEV_ROOT_PATH" ]; then
echo -e "${Red}!! LOOP PATHS CAN NOT BE SET!!!"
debug 'ERROR' 'LOOP PATHS CAN NOT BE SET'
From 1a4b0c9b0cc385d0ad3fd1a59b2df7533b35f2c9 Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Wed, 16 Oct 2024 08:18:11 +0200
Subject: [PATCH 36/46] Update installer.sh
This script will be in a fork of its own (install) in the future instead of main and testing.
Bash indentation is 2...
Out-commented some code not necessary and made comments, this will be removed later. (mostly for the framps that created the installer in the first place)
Added a "sudo check", or the script will exit.
Made changes to renaming the config file later in script, checking if a previous file is already exists and asks for overwrite confirmation.
---
installer.sh | 119 +++++++++++++++++++++++++++++++--------------------
1 file changed, 72 insertions(+), 47 deletions(-)
diff --git a/installer.sh b/installer.sh
index 87803b3..f6cb919 100755
--- a/installer.sh
+++ b/installer.sh
@@ -1,80 +1,105 @@
#!/bin/bash
#
# Simple installer for shrink-backup
+# Special thanks to https://github.com/framps
#
# Command to use to install shrink-backup:
-# curl https://raw.githubusercontent.com/UnconnectedBedna/shrink-backup/main/installer.sh | sudo bash
+# curl https://raw.githubusercontent.com/UnconnectedBedna/shrink-backup/install/installer.sh | sudo bash
#
+# Check if script is run as root
+if [ "$EUID" -ne 0 ]; then
+ echo 'THIS SCRIPT MUST BE RUN AS ROOT! (WITH SUDO)'
+ exit
+fi
+
set -uo pipefail
-# Has to be updated when PR is accepted
-readonly REPOSITORY="framps" # UnconnectedBedna
-readonly BRANCH="install" # testing
+readonly REPOSITORY="UnconnectedBedna"
+readonly BRANCH="testing" # change to install after testing and creation of fork
readonly PACKAGE_FILE="shrink-backup"
+readonly EXCLUDE_FILE="exclude.txt"
readonly LICENSE_FILE="LICENSE"
readonly README_FILE="README.md"
-readonly DIR_DOC="/usr/share/doc/$PACKAGE_FILE"
readonly DIR_EXE="/usr/local/sbin"
readonly DIR_ETC="/usr/local/etc"
+readonly DIR_DOC="/usr/share/doc/$PACKAGE_FILE"
readonly DOWNLOAD_REPOSITORY="https://raw.githubusercontent.com/$REPOSITORY/$PACKAGE_FILE/$BRANCH"
-readonly FILES_2_DOWNLOAD=("$PACKAGE_FILE" "${PACKAGE_FILE}.conf" "$LICENSE_FILE" "$README_FILE")
+readonly FILES_2_DOWNLOAD=("$PACKAGE_FILE" "$EXCLUDE_FILE" "$LICENSE_FILE" "$README_FILE")
readonly FILES_2_STORE=("$DIR_EXE" "$DIR_ETC" "$DIR_DOC" "$DIR_DOC")
readonly TMP_DIR=$(mktemp -d)
function cleanup() {
- local exitStatus=$?
- cd $pwd
- rmdir $TMP_DIR &>/dev/null
- if (( $exitStatus > 0 )); then
- echo "Installation of $PACKAGE_FILE failed with rc $exitStatus"
- else
- echo "$PACKAGE_FILE successfully installed"
- fi
- exit $exitStatus
+ local exitStatus=$?
+ cd $pwd
+ rmdir $TMP_DIR &>/dev/null
+ if (( $exitStatus > 0 )); then
+ echo "Installation of $PACKAGE_FILE failed with rc $exitStatus"
+ else
+ echo "$PACKAGE_FILE successfully installed"
+ fi
+ exit $exitStatus
}
pwd=$PWD
trap "cleanup" SIGINT SIGTERM EXIT
cd $TMP_DIR
-echo "Installing $PACKAGE_FILE ..."
+echo "Installing ${PACKAGE_FILE}..."
for (( i=0; i<${#FILES_2_DOWNLOAD[@]}; i++ )); do
- sourceFile="${FILES_2_DOWNLOAD[$i]}"
- targetDir="${FILES_2_STORE[$i]}"
-
- echo -n "Downloading $sourceFile from $DOWNLOAD_REPOSITORY/$sourceFile ... "
- http_code=$(curl -w "%{http_code}" -L -s $DOWNLOAD_REPOSITORY/$sourceFile -o $sourceFile)
-
- (( $? )) && { echo "Curl failed"; exit 1; }
- [[ $http_code != 200 ]] && { echo "http request failed with $http_code"; exit 1; }
- echo "done"
-
- echo -n "Installing $sourceFile into $targetDir ... "
- sudo chown root:root "${sourceFile}"
- (( $? )) && { echo "chown of $sourceFile failed"; exit 1; }
-
- sudo chmod 755 "${sourceFile}"
- (( $? )) && { echo "chmod of $sourceFile failed"; exit 1; }
-
- if [[ "$sourceFile" == "$PACKAGE_FILE" ]]; then # existing executable bit in github is not reflected by curl
- sudo chmod +x "$sourceFile"
- (( $? )) && { echo "chmod of $sourceFile failed"; exit 1; }
- sed --follow-symlinks -i -E "s/^(INSTALL_METHOD)=.+$/\1=\'curl\'/" "$sourceFile"
- (( $? )) && { echo "sed of $sourceFile failed"; exit 1; }
- elif [[ ! -d "$DIR_DOC" ]] && [[ "$sourceFile" == "$LICENSE_FILE" || "$sourceFile" == "$README_FILE" ]] ; then # create LICENSE directory
- sudo mkdir -p "$DIR_DOC"
- (( $? )) && { echo "mkdir of $DIR_DOC failed"; exit 1; }
- sudo chown root:root "${DIR_DOC}/.."
- (( $? )) && { echo "chown of ${DIR_SOC}/.. failed"; exit 1; }
- fi
- sudo mv "${sourceFile}" "${targetDir}"
- (( $? )) && { echo "mv of $sourceFile failed"; exit 1; }
- echo "done"
+ sourceFile="${FILES_2_DOWNLOAD[$i]}"
+ targetDir="${FILES_2_STORE[$i]}"
+
+ echo -n "Downloading $sourceFile from ${DOWNLOAD_REPOSITORY}/${sourceFile}..."
+ http_code=$(curl -w "%{http_code}" -L -s ${DOWNLOAD_REPOSITORY}/${sourceFile} -o $sourceFile)
+
+ (( $? )) && { echo "Curl failed"; exit 1; }
+ [[ $http_code != 200 ]] && { echo "http request failed with $http_code"; exit 1; }
+
+ echo -n "Installing $sourceFile into ${targetDir}..."
+ # we run bash as root, chown should not be needed
+ #chown root:root "${sourceFile}"
+ #(( $? )) && { echo "chown of $sourceFile failed"; exit 1; }
+
+ # I dont think all files should be 755
+ #chmod 755 "${sourceFile}"
+ #(( $? )) && { echo "chmod of $sourceFile failed"; exit 1; }
+
+ # Existing execution bit in github is not reflected by curl
+ if [[ "$sourceFile" == "$PACKAGE_FILE" ]]; then
+ chmod +x "$sourceFile"
+ (( $? )) && { echo "chmod of $sourceFile failed"; exit 1; }
+ sed --follow-symlinks -i -E "s/^(INSTALL_METHOD)=.+$/\1=\'curl\'/" "$sourceFile"
+ (( $? )) && { echo "sed of $sourceFile failed"; exit 1; }
+ # Create LICENSE directory
+ elif [[ ! -d "$DIR_DOC" ]] && [[ "$sourceFile" == "$LICENSE_FILE" || "$sourceFile" == "$README_FILE" ]] ; then
+ mkdir -p "$DIR_DOC"
+ (( $? )) && { echo "mkdir of $DIR_DOC failed"; exit 1; }
+ # Again, we are running bash as sudo...
+ #chown root:root "${DIR_DOC}/.."
+ #(( $? )) && { echo "chown of ${DIR_SOC}/.. failed"; exit 1; }
+ fi
+ mv "$sourceFile" "$targetDir"
+ (( $? )) && { echo "mv of $sourceFile failed"; exit 1; }
done
+# Renaming exclude.txt to shrink-backup.conf since it is now located in /usr/local/etc
+if [ -f ${DIR_ETC}/shrink-backup.conf ]; then
+ echo "${DIR_ETC}/shrink-backup.conf already exists"
+ while true; do
+ read -n 1 -r -p '!! Do you want to overwrite? [y/n] ' input
+ case $input in
+ [Yy]) echo -e '\nOverwriting...'; mv "${DIR_ETC}"/"${EXCLUDE_FILE}" "${DIR_ETC}"/shrink-backup.conf; break;;
+ [Nn]) echo -e '\nKeeping old file...'; rm "${DIR_ETC}"/"${EXCLUDE_FILE}"; break;;
+ *) echo -e "\nERROR! Please enter 'y/Y' or 'n/N'";;
+ esac
+ done
+else
+ mv "${DIR_ETC}"/"${EXCLUDE_FILE}" "${DIR_ETC}"/shrink-backup.conf
+fi
+
exit 0
From bc1c0d6444c34f620085530b4d5cfc88816e506d Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Wed, 16 Oct 2024 08:20:19 +0200
Subject: [PATCH 37/46] Delete shrink-backup.conf
This file is not needed, exclude.txt will be used and renamed instead when using the install script.
---
shrink-backup.conf | 9 ---------
1 file changed, 9 deletions(-)
delete mode 100644 shrink-backup.conf
diff --git a/shrink-backup.conf b/shrink-backup.conf
deleted file mode 100644
index cd351dc..0000000
--- a/shrink-backup.conf
+++ /dev/null
@@ -1,9 +0,0 @@
-/lost+found
-/proc/*
-/sys/*
-/dev/*
-/tmp/*
-/run/*
-/mnt/*
-/media/*
-/var/swap
From 41b1898bf4d6be11dd621c85cd627c866c818b04 Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Wed, 16 Oct 2024 08:43:33 +0200
Subject: [PATCH 38/46] Update installer.sh
Curl does not want to play nice and wait for user input when using `read`
Adding `< /dev/tty` might work.
---
installer.sh | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/installer.sh b/installer.sh
index f6cb919..95ffde3 100755
--- a/installer.sh
+++ b/installer.sh
@@ -53,13 +53,13 @@ for (( i=0; i<${#FILES_2_DOWNLOAD[@]}; i++ )); do
sourceFile="${FILES_2_DOWNLOAD[$i]}"
targetDir="${FILES_2_STORE[$i]}"
- echo -n "Downloading $sourceFile from ${DOWNLOAD_REPOSITORY}/${sourceFile}..."
+ echo "Downloading $sourceFile from ${DOWNLOAD_REPOSITORY}/${sourceFile}..."
http_code=$(curl -w "%{http_code}" -L -s ${DOWNLOAD_REPOSITORY}/${sourceFile} -o $sourceFile)
(( $? )) && { echo "Curl failed"; exit 1; }
[[ $http_code != 200 ]] && { echo "http request failed with $http_code"; exit 1; }
- echo -n "Installing $sourceFile into ${targetDir}..."
+ echo "Installing $sourceFile into ${targetDir}..."
# we run bash as root, chown should not be needed
#chown root:root "${sourceFile}"
#(( $? )) && { echo "chown of $sourceFile failed"; exit 1; }
@@ -91,7 +91,7 @@ done
if [ -f ${DIR_ETC}/shrink-backup.conf ]; then
echo "${DIR_ETC}/shrink-backup.conf already exists"
while true; do
- read -n 1 -r -p '!! Do you want to overwrite? [y/n] ' input
+ read -n 1 -r -p '!! Do you want to overwrite? [y/n] ' input < /dev/tty
case $input in
[Yy]) echo -e '\nOverwriting...'; mv "${DIR_ETC}"/"${EXCLUDE_FILE}" "${DIR_ETC}"/shrink-backup.conf; break;;
[Nn]) echo -e '\nKeeping old file...'; rm "${DIR_ETC}"/"${EXCLUDE_FILE}"; break;;
From f028a83f400731bb3dbce66c2634b87cf173f71f Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Wed, 16 Oct 2024 09:19:59 +0200
Subject: [PATCH 39/46] Update installer.sh - QOL
Added a bit of information after installation.
---
installer.sh | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/installer.sh b/installer.sh
index 95ffde3..e4c564c 100755
--- a/installer.sh
+++ b/installer.sh
@@ -38,6 +38,12 @@ function cleanup() {
echo "Installation of $PACKAGE_FILE failed with rc $exitStatus"
else
echo "$PACKAGE_FILE successfully installed"
+ echo 'Script location: /usr/local/bin/shrink-backup'
+ echo 'Exclude file locattion: /usr/local/etc/shrink-backup.conf'
+ echo 'README location: /usr/share/doc/shrink-backup/README.md'
+ echo 'LICENSE location: /usr/share/doc/shrink-backup/LICENSE'
+ echo 'For help: shrink-backup --help'
+ echo 'Thank you for using shrink-backup'
fi
exit $exitStatus
}
@@ -88,8 +94,10 @@ for (( i=0; i<${#FILES_2_DOWNLOAD[@]}; i++ )); do
done
# Renaming exclude.txt to shrink-backup.conf since it is now located in /usr/local/etc
+echo 'Renaming exclude.txt to shrink-backup.conf...'
if [ -f ${DIR_ETC}/shrink-backup.conf ]; then
- echo "${DIR_ETC}/shrink-backup.conf already exists"
+ echo 'WARNING!'
+ echo "${DIR_ETC}/shrink-backup.conf already exists!"
while true; do
read -n 1 -r -p '!! Do you want to overwrite? [y/n] ' input < /dev/tty
case $input in
From 4d4f8099d6785d5face3a991b1b7f3d0cd2d7f72 Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Wed, 16 Oct 2024 09:30:48 +0200
Subject: [PATCH 40/46] Update installer.sh - Typos
---
installer.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/installer.sh b/installer.sh
index e4c564c..1472004 100755
--- a/installer.sh
+++ b/installer.sh
@@ -16,7 +16,7 @@ fi
set -uo pipefail
readonly REPOSITORY="UnconnectedBedna"
-readonly BRANCH="testing" # change to install after testing and creation of fork
+readonly BRANCH="testing" # change to install after testing and creation of branch
readonly PACKAGE_FILE="shrink-backup"
readonly EXCLUDE_FILE="exclude.txt"
@@ -38,7 +38,7 @@ function cleanup() {
echo "Installation of $PACKAGE_FILE failed with rc $exitStatus"
else
echo "$PACKAGE_FILE successfully installed"
- echo 'Script location: /usr/local/bin/shrink-backup'
+ echo 'Script location: /usr/local/sbin/shrink-backup'
echo 'Exclude file locattion: /usr/local/etc/shrink-backup.conf'
echo 'README location: /usr/share/doc/shrink-backup/README.md'
echo 'LICENSE location: /usr/share/doc/shrink-backup/LICENSE'
From 52a03001df1488db6a6de379043b2ae70132b67a Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Thu, 17 Oct 2024 11:26:44 +0200
Subject: [PATCH 41/46] QOL update
Made formatting of confirmation windw before backups more pleasant to read.
---
shrink-backup | 70 ++++++++++++++++++++++++++++++---------------------
1 file changed, 41 insertions(+), 29 deletions(-)
diff --git a/shrink-backup b/shrink-backup
index fdf4f0e..84d9d8a 100755
--- a/shrink-backup
+++ b/shrink-backup
@@ -121,6 +121,7 @@ function pause() {
#pause 'Press [Enter] key to continue...'
# Set default values for script options
+unset diff_small
INSTALL_METHOD='default'
PROMPTS=true
DEBUG=false
@@ -1049,7 +1050,8 @@ function make_img() {
echo -e "# ${Yellow}DISABLE PROMPTS SELECTED (${Green}-y${Yellow}), NO WARNINGS ABOUT DELETION!!! ${Purple}$(printf "%+$(( COLS - 63 ))s" '#')"
fi
#echo -e "# ${IWhite}A backup will be created at ${Green}$IMG_FILE $(while [ $x -lt $(( COLS - 31 - $(echo ${IMG_FILE} | wc -m ) )) ]; do echo -n ' '; let x=$x+1; done; echo)${Purple}#"
- echo -e "# ${IWhite}A backup will be created at ${Green}$IMG_FILE ${Purple}$(printf "%+$(( COLS - 30 - $(echo ${IMG_FILE} | wc -m ) ))s" '#')"
+ echo -e "# ${IWhite}A backup will be created at: ${Purple}$(printf "%+$(( COLS - 31 ))s" '#')"
+ echo -e "# ${Green}$IMG_FILE ${Purple}$(printf "%+$(( COLS - 2 - $(echo ${IMG_FILE} | wc -m ) ))s" '#')"
echo -e "# ${Green}$FSTYPE ${IWhite}filesystem detected on root ${Purple}$(printf "%+$(( COLS - 30 - $(echo ${FSTYPE} | wc -m ) ))s" '#')"
if [ "$FSTYPE" == 'btrfs' ]; then
echo -e "# ${Green}${#LOCAL_SUBVOLUMES[@]} ${IWhite}btrfs volumes will be included ${Purple}$(printf "%+$(( COLS - 33 - $(echo ${#LOCAL_SUBVOLUMES[@]} | wc -m ) ))s" '#')"
@@ -1061,25 +1063,25 @@ function make_img() {
echo -e "# ${Yellow}Autoexpand filesystem at boot not available for ${Green}f2fs ${Purple}$(printf "%+$(( COLS - 55 ))s" '#')"
fi
echo -e "${Purple}# --------------------------------------------------------------------------------- #"
- echo -e "# ${IWhite}Write to logfile: ${Green}$DEBUG ${Purple}$(printf "%+$(( COLS - 20 - $(echo ${DEBUG} | wc -m ) ))s" '#')"
- echo -e "# ${IWhite}Zoom speed requested: ${Green}$ZOOM ${Purple}$(printf "%+$(( COLS - 24 - $(echo ${ZOOM} | wc -m ) ))s" '#')"
- echo -e "# ${IWhite}Autocalculate img root partition size: ${Green}$AUTORESIZE_RUN ${Purple}$(printf "%+$(( COLS - 41 - $(echo ${AUTORESIZE_RUN} | wc -m ) ))s" '#')"
+ echo -e "# ${IWhite}Write to logfile: ${Green}$DEBUG ${Purple}$(printf "%+$(( COLS - 33 - $(echo ${DEBUG} | wc -m ) ))s" '#')"
+ echo -e "# ${IWhite}Zoom speed requested: ${Green}$ZOOM ${Purple}$(printf "%+$(( COLS - 33 - $(echo ${ZOOM} | wc -m ) ))s" '#')"
+ echo -e "# ${IWhite}Autocalculate img root size: ${Green}$AUTORESIZE_RUN ${Purple}$(printf "%+$(( COLS - 33 - $(echo ${AUTORESIZE_RUN} | wc -m ) ))s" '#')"
echo -e "# ${IWhite}Autoexpand filesystem at boot: ${Green}$AUTOEXPAND ${Purple}$(printf "%+$(( COLS - 33 - $(echo ${AUTOEXPAND} | wc -m ) ))s" '#')"
- echo -e "# ${IWhite}Use exclude.txt: ${Green}$EXCLUDE_FILE ${Purple}$(printf "%+$(( COLS - 19 - $(echo ${EXCLUDE_FILE} | wc -m ) ))s" '#')"
+ echo -e "# ${IWhite}Use exclude.txt: ${Green}$EXCLUDE_FILE ${Purple}$(printf "%+$(( COLS - 33 - $(echo ${EXCLUDE_FILE} | wc -m ) ))s" '#')"
print_temp="$(( LOCAL_BOOTSECTOR / 1024 / 1024 ))"
- echo -e "# ${IWhite}Bootsector size: ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 22 - $(echo ${print_temp} | wc -m ) ))s" '#')"
+ echo -e "# ${IWhite}Bootsector size: ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 36 - $(echo ${print_temp} | wc -m ) ))s" '#')"
print_temp="$(( $(df / -k --sync --output=used | tail -1) / 1024 ))"
- echo -e "# ${IWhite}Estemated root usage: ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 27 - $(echo ${print_temp} | wc -m ) ))s" '#')"
+ echo -e "# ${IWhite}Estemated root usage: ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 36 - $(echo ${print_temp} | wc -m ) ))s" '#')"
if [ "$AUTORESIZE_RUN" = true ]; then
print_temp="$(( LOCAL_AUTORESIZE_MIN / 1024 / 1024 ))"
- echo -e "# ${IWhite}Auto calculated size (root partition): ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 44 - $(echo ${print_temp} | wc -m ) ))s" '#')"
+ echo -e "# ${IWhite}Auto calculated root size: ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 36 - $(echo ${print_temp} | wc -m ) ))s" '#')"
print_temp="$(( TRUNCATE_TOTAL / 1024 / 1024 ))"
- echo -e "# ${IWhite}Total img size: ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 21 - $(echo ${print_temp} | wc -m ) ))s" '#')"
+ echo -e "# ${IWhite}Total img size: ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 36 - $(echo ${print_temp} | wc -m ) ))s" '#')"
else
print_temp="$(( ADDED_SPACE / 1024 / 1024 ))"
- echo -e "# ${IWhite}Manually added space: ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 27 - $(echo ${print_temp} | wc -m ) ))s" '#')"
+ echo -e "# ${IWhite}Manually added space: ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 36 - $(echo ${print_temp} | wc -m ) ))s" '#')"
print_temp2="$(( TRUNCATE_TOTAL / 1024 / 1024 ))"
- echo -e "# ${IWhite}Total img size: ${Green}${print_temp2}MiB ${IWhite}with ${Green}${print_temp}MiB [extra space] ${IWhite}included ${Purple}$(printf "%+$(( COLS - 52 - $(echo ${print_temp2} | wc -m ) - $(echo ${print_temp} | wc -m ) ))s" '#')"
+ echo -e "# ${IWhite}Total img size: ${Green}${print_temp2}MiB ${IWhite}with ${Green}${print_temp}MiB [extra space] ${IWhite}included ${Purple}$(printf "%+$(( COLS - 67 - $(echo ${print_temp2} | wc -m ) - $(echo ${print_temp} | wc -m ) ))s" '#')"
if [ "$AUTORESIZE_WARNING" = true ]; then
echo -e "${Yellow}# --------------------------------------------------------------------------------- #"
echo -e "! WARNING!!! Manually added space is smaller than calculated recommended minimum $(printf "%+$(( COLS - 81 ))s" '!')"
@@ -1607,6 +1609,7 @@ function do_backup() {
debug 'DEBUG' "Running: fdisk --bytes -lo device,size "$LOOP" | grep "$IMG_DEV_ROOT_PATH" | awk '{print \$2}'"
IMG_ROOT_SIZE=$(fdisk --bytes -lo device,size "$LOOP" | grep "$IMG_DEV_ROOT_PATH" | awk '{print $2}' )
diff=$(( (LOCAL_AUTORESIZE_MIN - IMG_ROOT_SIZE) / 1024 / 1024 ))
+ [[ "$diff" != -* ]] && diff="+${diff}" # add a + in case the value is not negative for formatting reasons
debug 'DEBUG' "IMG_ROOT_SIZE=$IMG_ROOT_SIZE bytes | LOCAL_AUTORESIZE_MIN=$LOCAL_AUTORESIZE_MIN bytes | diff=${diff}MiB"
if [ "$IMG_ROOT_SIZE" -lt "$LOCAL_AUTORESIZE_MIN" ] && (( LOCAL_AUTORESIZE_MIN - IMG_ROOT_SIZE >= 268435456 )); then # 256MiB in bytes
@@ -1617,9 +1620,11 @@ function do_backup() {
RESIZE_FUNCTION='shrink'
else
if [ "$diff" != -* ]; then
- DIFFERENCE="Too small (${diff}MiB), not shrinking filesystem (must be >=512MiB)"
- else
DIFFERENCE="Too small (${diff}MiB), not expanding filesystem (must be >=256MiB)"
+ diff_small=true
+ else
+ DIFFERENCE="Too small (${diff}MiB), not shrinking filesystem (must be >=512MiB)"
+ diff_small=true
fi
fi
# Change TRUNCATE_TOTAL to be based on img file instead of local root if [extra space] is provided
@@ -1635,7 +1640,9 @@ function do_backup() {
debug 'INFO' '-y selected by user. prompts are disabled'
echo -e "# ${Yellow}DISABLE PROMPTS SELECTED (${Green}-y${Yellow}), NO WARNINGS ABOUT DELETION!!! ${Purple}$(printf "%+$(( COLS - 63 ))s" '#')"
fi
- echo -e "# ${IWhite}Updating ${Green}$IMG_FILE ${Purple}$(printf "%+$(( COLS - 11 - $(echo ${IMG_FILE} | wc -m ) ))s" '#')"
+ #echo -e "# ${IWhite}Updating ${Green}$IMG_FILE ${Purple}$(printf "%+$(( COLS - 11 - $(echo ${IMG_FILE} | wc -m ) ))s" '#')"
+ echo -e "# ${IWhite}Updating backup img: ${Purple}$(printf "%+$(( COLS - 23 ))s" '#')"
+ echo -e "# ${Green}$IMG_FILE ${Purple}$(printf "%+$(( COLS - 2 - $(echo ${IMG_FILE} | wc -m ) ))s" '#')"
echo -e "# ${Green}$FSTYPE ${IWhite}filesystem detected on root ${Purple}$(printf "%+$(( COLS - 30 - $(echo ${FSTYPE} | wc -m ) ))s" '#')"
if [ "$FSTYPE" == 'btrfs' ]; then
echo -e "# ${Green}${#LOCAL_SUBVOLUMES[@]} ${IWhite}btrfs volumes will be included"
@@ -1649,35 +1656,39 @@ function do_backup() {
debug 'DEBUG' '--fix option selected by user, rsync deleting files before copy'
fi
echo -e "${Purple}# --------------------------------------------------------------------------------- #"
- echo -e "# ${IWhite}Write to logfile: ${Green}$DEBUG ${Purple}$(printf "%+$(( COLS - 20 - $(echo ${DEBUG} | wc -m ) ))s" '#')"
- echo -e "# ${IWhite}Zoom speed requested: ${Green}$ZOOM ${Purple}$(printf "%+$(( COLS - 24 - $(echo ${ZOOM} | wc -m ) ))s" '#')"
- echo -e "# ${IWhite}Autocalculate img root partition size: ${Green}$AUTORESIZE_RUN ${Purple}$(printf "%+$(( COLS - 41 - $(echo ${AUTORESIZE_RUN} | wc -m ) ))s" '#')"
+ echo -e "# ${IWhite}Write to logfile: ${Green}$DEBUG ${Purple}$(printf "%+$(( COLS - 33 - $(echo ${DEBUG} | wc -m ) ))s" '#')"
+ echo -e "# ${IWhite}Zoom speed requested: ${Green}$ZOOM ${Purple}$(printf "%+$(( COLS - 33 - $(echo ${ZOOM} | wc -m ) ))s" '#')"
+ echo -e "# ${IWhite}Autocalculate img root size: ${Green}$AUTORESIZE_RUN ${Purple}$(printf "%+$(( COLS - 33 - $(echo ${AUTORESIZE_RUN} | wc -m ) ))s" '#')"
echo -e "# ${IWhite}Autoexpand filesystem at boot: ${Green}$AUTOEXPAND ${Purple}$(printf "%+$(( COLS - 33 - $(echo ${AUTOEXPAND} | wc -m ) ))s" '#')"
- echo -e "# ${IWhite}Use exclude.txt: ${Green}$EXCLUDE_FILE ${Purple}$(printf "%+$(( COLS - 19 - $(echo ${EXCLUDE_FILE} | wc -m ) ))s" '#')"
+ echo -e "# ${IWhite}Use exclude.txt: ${Green}$EXCLUDE_FILE ${Purple}$(printf "%+$(( COLS - 33 - $(echo ${EXCLUDE_FILE} | wc -m ) ))s" '#')"
print_temp="$(( LOCAL_BOOTSECTOR / 1024 / 1024 ))"
- echo -e "# ${IWhite}Bootsector size: ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 22 - $(echo ${print_temp} | wc -m ) ))s" '#')"
+ echo -e "# ${IWhite}Bootsector size: ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 36 - $(echo ${print_temp} | wc -m ) ))s" '#')"
if [ "$AUTORESIZE_RUN" = true ]; then
print_temp="$(( LOCAL_AUTORESIZE_MIN / 1024 / 1024 ))"
- echo -e "# ${IWhite}Auto calculated size (root partition): ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 44 - $(echo ${print_temp} | wc -m ) ))s" '#')"
+ echo -e "# ${IWhite}Auto calculated root size: ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 36 - $(echo ${print_temp} | wc -m ) ))s" '#')"
print_temp="$(( IMG_SIZE / 1024 / 1024 ))"
- echo -e "# ${IWhite}Old img size: ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 19 - $(echo ${print_temp} | wc -m ) ))s" '#')"
+ echo -e "# ${IWhite}Old img size: ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 36 - $(echo ${print_temp} | wc -m ) ))s" '#')"
print_temp="$(( TRUNCATE_TOTAL / 1024 / 1024 ))"
- echo -e "# ${IWhite}New img size: ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 19 - $(echo ${print_temp} | wc -m ) ))s" '#')"
- echo -e "# ${IWhite}Difference: ${Green}$DIFFERENCE ${Purple}$(printf "%+$(( COLS - 14 - $(echo ${DIFFERENCE} | wc -m ) ))s" '#')"
+ echo -e "# ${IWhite}New img size: ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 36 - $(echo ${print_temp} | wc -m ) ))s" '#')"
+ if [ -z "$diff_small" ]; then
+ echo -e "# ${IWhite}Difference: ${Green}$DIFFERENCE ${Purple}$(printf "%+$(( COLS - 32 - $(echo ${DIFFERENCE} | wc -m ) ))s" '#')"
+ else
+ echo -e "# ${IWhite}Difference: ${Green}$DIFFERENCE ${Purple}$(printf "%+$(( COLS - 14 - $(echo ${DIFFERENCE} | wc -m ) ))s" '#')"
+ fi
elif [ "$ADDED_SPACE" -ne 0 ]; then
print_temp="$(( $(df / -k --sync --output=used | tail -1) / 1024 ))"
- echo -e "# ${IWhite}Estemated root usage: ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 27 - $(echo ${print_temp} | wc -m ) ))s" '#')"
+ echo -e "# ${IWhite}Estemated root usage: ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 36 - $(echo ${print_temp} | wc -m ) ))s" '#')"
print_temp="$(( IMG_SIZE / 1024 / 1024 ))"
- echo -e "# ${IWhite}Old img size: ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 19 - $(echo ${print_temp} | wc -m ) ))s" '#')"
+ echo -e "# ${IWhite}Old img size: ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 36 - $(echo ${print_temp} | wc -m ) ))s" '#')"
print_temp="$(( TRUNCATE_TOTAL / 1024 / 1024 ))"
- echo -e "# ${IWhite}New img size: ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 19 - $(echo ${print_temp} | wc -m ) ))s" '#')"
+ echo -e "# ${IWhite}New img size: ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 36 - $(echo ${print_temp} | wc -m ) ))s" '#')"
print_temp="$(( ADDED_SPACE / 1024 / 1024 ))"
- echo -e "# ${IWhite}Difference: ${Green}MiB ${Purple}$(printf "%+$(( COLS - 18 - $(echo ${print_temp} | wc -m ) ))s" '#')"
+ echo -e "# ${IWhite}Difference: ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 36 - $(echo ${print_temp} | wc -m ) ))s" '#')"
else
print_temp="$(( $(df / -k --sync --output=used | tail -1) / 1024 ))"
- echo -e "# ${IWhite}Estemated root usage: ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 27 - $(echo ${print_temp} | wc -m ) ))s" '#')"
+ echo -e "# ${IWhite}Estemated root usage: ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 36 - $(echo ${print_temp} | wc -m ) ))s" '#')"
print_temp="$(( IMG_SIZE / 1024 / 1024 ))"
- echo -e "# ${IWhite}Total img size: ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 21 - $(echo ${print_temp} | wc -m ) ))s" '#')"
+ echo -e "# ${IWhite}Total img size: ${Green}${print_temp}MiB ${Purple}$(printf "%+$(( COLS - 36 - $(echo ${print_temp} | wc -m ) ))s" '#')"
fi
echo -e "${Purple}${BREAK}${IWhite}"
@@ -2112,6 +2123,7 @@ fi
# Enter variables into logfile
if [ "$DEBUG" = true ]; then
debug 'BREAK'
+ debug 'DEBUG' "INSTALL_METHOD=$INSTALL_METHOD"
debug 'DEBUG' "IMG_FILE=$IMG_FILE"
debug 'DEBUG' "PARTITION_TABLE=$PARTITION_TABLE"
debug 'DEBUG' "UPDATE=$UPDATE"
From 5ddf0f16826e736f0c9b92ee813c82edfe80189e Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Fri, 18 Oct 2024 09:24:12 +0200
Subject: [PATCH 42/46] Delete installer.sh
Installer now in install branch
---
installer.sh | 113 ---------------------------------------------------
1 file changed, 113 deletions(-)
delete mode 100755 installer.sh
diff --git a/installer.sh b/installer.sh
deleted file mode 100755
index 1472004..0000000
--- a/installer.sh
+++ /dev/null
@@ -1,113 +0,0 @@
-#!/bin/bash
-#
-# Simple installer for shrink-backup
-# Special thanks to https://github.com/framps
-#
-# Command to use to install shrink-backup:
-# curl https://raw.githubusercontent.com/UnconnectedBedna/shrink-backup/install/installer.sh | sudo bash
-#
-
-# Check if script is run as root
-if [ "$EUID" -ne 0 ]; then
- echo 'THIS SCRIPT MUST BE RUN AS ROOT! (WITH SUDO)'
- exit
-fi
-
-set -uo pipefail
-
-readonly REPOSITORY="UnconnectedBedna"
-readonly BRANCH="testing" # change to install after testing and creation of branch
-
-readonly PACKAGE_FILE="shrink-backup"
-readonly EXCLUDE_FILE="exclude.txt"
-readonly LICENSE_FILE="LICENSE"
-readonly README_FILE="README.md"
-readonly DIR_EXE="/usr/local/sbin"
-readonly DIR_ETC="/usr/local/etc"
-readonly DIR_DOC="/usr/share/doc/$PACKAGE_FILE"
-readonly DOWNLOAD_REPOSITORY="https://raw.githubusercontent.com/$REPOSITORY/$PACKAGE_FILE/$BRANCH"
-readonly FILES_2_DOWNLOAD=("$PACKAGE_FILE" "$EXCLUDE_FILE" "$LICENSE_FILE" "$README_FILE")
-readonly FILES_2_STORE=("$DIR_EXE" "$DIR_ETC" "$DIR_DOC" "$DIR_DOC")
-readonly TMP_DIR=$(mktemp -d)
-
-function cleanup() {
- local exitStatus=$?
- cd $pwd
- rmdir $TMP_DIR &>/dev/null
- if (( $exitStatus > 0 )); then
- echo "Installation of $PACKAGE_FILE failed with rc $exitStatus"
- else
- echo "$PACKAGE_FILE successfully installed"
- echo 'Script location: /usr/local/sbin/shrink-backup'
- echo 'Exclude file locattion: /usr/local/etc/shrink-backup.conf'
- echo 'README location: /usr/share/doc/shrink-backup/README.md'
- echo 'LICENSE location: /usr/share/doc/shrink-backup/LICENSE'
- echo 'For help: shrink-backup --help'
- echo 'Thank you for using shrink-backup'
- fi
- exit $exitStatus
-}
-
-pwd=$PWD
-trap "cleanup" SIGINT SIGTERM EXIT
-cd $TMP_DIR
-
-echo "Installing ${PACKAGE_FILE}..."
-
-for (( i=0; i<${#FILES_2_DOWNLOAD[@]}; i++ )); do
-
- sourceFile="${FILES_2_DOWNLOAD[$i]}"
- targetDir="${FILES_2_STORE[$i]}"
-
- echo "Downloading $sourceFile from ${DOWNLOAD_REPOSITORY}/${sourceFile}..."
- http_code=$(curl -w "%{http_code}" -L -s ${DOWNLOAD_REPOSITORY}/${sourceFile} -o $sourceFile)
-
- (( $? )) && { echo "Curl failed"; exit 1; }
- [[ $http_code != 200 ]] && { echo "http request failed with $http_code"; exit 1; }
-
- echo "Installing $sourceFile into ${targetDir}..."
- # we run bash as root, chown should not be needed
- #chown root:root "${sourceFile}"
- #(( $? )) && { echo "chown of $sourceFile failed"; exit 1; }
-
- # I dont think all files should be 755
- #chmod 755 "${sourceFile}"
- #(( $? )) && { echo "chmod of $sourceFile failed"; exit 1; }
-
- # Existing execution bit in github is not reflected by curl
- if [[ "$sourceFile" == "$PACKAGE_FILE" ]]; then
- chmod +x "$sourceFile"
- (( $? )) && { echo "chmod of $sourceFile failed"; exit 1; }
- sed --follow-symlinks -i -E "s/^(INSTALL_METHOD)=.+$/\1=\'curl\'/" "$sourceFile"
- (( $? )) && { echo "sed of $sourceFile failed"; exit 1; }
- # Create LICENSE directory
- elif [[ ! -d "$DIR_DOC" ]] && [[ "$sourceFile" == "$LICENSE_FILE" || "$sourceFile" == "$README_FILE" ]] ; then
- mkdir -p "$DIR_DOC"
- (( $? )) && { echo "mkdir of $DIR_DOC failed"; exit 1; }
- # Again, we are running bash as sudo...
- #chown root:root "${DIR_DOC}/.."
- #(( $? )) && { echo "chown of ${DIR_SOC}/.. failed"; exit 1; }
- fi
- mv "$sourceFile" "$targetDir"
- (( $? )) && { echo "mv of $sourceFile failed"; exit 1; }
-
-done
-
-# Renaming exclude.txt to shrink-backup.conf since it is now located in /usr/local/etc
-echo 'Renaming exclude.txt to shrink-backup.conf...'
-if [ -f ${DIR_ETC}/shrink-backup.conf ]; then
- echo 'WARNING!'
- echo "${DIR_ETC}/shrink-backup.conf already exists!"
- while true; do
- read -n 1 -r -p '!! Do you want to overwrite? [y/n] ' input < /dev/tty
- case $input in
- [Yy]) echo -e '\nOverwriting...'; mv "${DIR_ETC}"/"${EXCLUDE_FILE}" "${DIR_ETC}"/shrink-backup.conf; break;;
- [Nn]) echo -e '\nKeeping old file...'; rm "${DIR_ETC}"/"${EXCLUDE_FILE}"; break;;
- *) echo -e "\nERROR! Please enter 'y/Y' or 'n/N'";;
- esac
- done
-else
- mv "${DIR_ETC}"/"${EXCLUDE_FILE}" "${DIR_ETC}"/shrink-backup.conf
-fi
-
-exit 0
From 6f08ec8e4cd79c47543662d0ec06f3cd6022000a Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Sat, 19 Oct 2024 10:25:41 +0200
Subject: [PATCH 43/46] Update shrink-backup - v1.2
- Preparations for merging with main
- Changed all usage of `ls` into `stat`
- Code cleanup
---
shrink-backup | 38 +++++++++++---------------------------
1 file changed, 11 insertions(+), 27 deletions(-)
diff --git a/shrink-backup b/shrink-backup
index 84d9d8a..fc4d7cf 100755
--- a/shrink-backup
+++ b/shrink-backup
@@ -1,8 +1,8 @@
#!/usr/bin/env bash
#
# shrink-backup
-# version 1.2-beta
-# backup tool for backing up and updating .img files with autoexpansion on various operating systems
+# Version 1.2
+# Backup tool for creating and updating .img files (with autoexpansion function) on various linux operating systems
#
# Copyright (c) 2024, Marcus Johansson
# https://github.com/UnconnectedBedna/shrink-backup
@@ -168,7 +168,7 @@ fi
version() {
echo -e "${Purple}#########################################################################
# #
-# ${Green}shrink-backup version 1.1 ${Purple}#
+# ${Green}shrink-backup version 1.2 ${Purple}#
# #
# ${IWhite}Copyright (c) 2024, Marcus Johansson ${Purple}#
# ${White}https://github.com/UnconnectedBedna/shrink-backup ${Purple}#
@@ -344,7 +344,7 @@ exit 2
# Function to gather device information
function get_dev_variables() {
- # Run get_btrfs_variables and then exit THIS function
+ # Run get_btrfs_variables and then exit THIS function (added space = 0)
if [ "$FSTYPE" == 'btrfs' ] && [ "$AUTORESIZE_RUN" = false ] && [ "$ADDED_SPACE" -eq 0 ]; then
debug 'INFO' 'Running function: get_btrfs_variables'
get_btrfs_variables
@@ -392,7 +392,6 @@ function get_dev_variables() {
# Set automated calculated size (get_btrfs_variables if btrfs filesystem)
if [ "$AUTORESIZE_RUN" = true ] || [ "$UPDATE" = false ] || [ "$FSTYPE" == 'btrfs' ]; then
debug 'INFO' 'Calculating recommended root size'
- #BLOCKSIZE=$(stat -f / | grep -i 'Block size' | awk '{print $3}') # bytes
BLOCKSIZE=$(stat -fc %s /) # bytes, so it works with other localisations
debug 'DEBUG' "BLOCKSIZE=${BLOCKSIZE} bytes"
if [ "$FSTYPE" == 'ext4' ]; then
@@ -487,8 +486,8 @@ return 0
# Function to gather image information
function get_img_variables() {
- debug 'DEBUG' "Running: ls -l $IMG_FILE | awk '{print \$5}'"
- IMG_SIZE=$(ls -l "$IMG_FILE" | awk '{print $5}')
+ debug 'DEBUG' "Running: stat -c %s $IMG_FILE"
+ IMG_SIZE=$(stat -c %s "$IMG_FILE")
debug 'DEBUG' "IMG_SIZE=$IMG_SIZE bytes"
# Boot partition exists
@@ -496,7 +495,6 @@ function get_img_variables() {
# ext4 & f2fs
if [ "$FSTYPE" == 'ext4' ] || [ "$FSTYPE" == 'f2fs' ]; then
- # I have no idea why, but if I do not put this sleep here, IMG_DEV_BOOT_PATH does not get set
sleep 2
IMG_DEV_BOOT_PATH=$(lsblk -no path,uuid "$LOOP" | grep "$LOCAL_BOOT_UUID" | awk '{print $1}')
IMG_DEV_ROOT_PATH=$(lsblk -no path,uuid "$LOOP" | grep "$LOCAL_ROOT_UUID" | awk '{print $1}')
@@ -951,7 +949,7 @@ function do_resize() {
#debug 'DEBUG' "Running: parted -s -a none $LOOP unit B resizepart $IMG_ROOT_PARTN $TRUNCATE_TOTAL"
debug 'DEBUG' "Running: printf 'Yes\\\n' | parted -a none $LOOP unit B resizepart $IMG_ROOT_PARTN $TRUNCATE_TOTAL ---pretend-input-tty"
- #if ! output=$(parted -s -a none "$LOOP" unit B resizepart "$IMG_ROOT_PARTN" "$TRUNCATE_TOTAL" 2>&1); then # tested may 2024 and does not work, still asking for user confirmation even though --script is used
+ #if ! output=$(parted -s -a none "$LOOP" unit B resizepart "$IMG_ROOT_PARTN" "$TRUNCATE_TOTAL" 2>&1); then # tested may 2024 and does not work, still asking for user confirmation
if ! output=$(printf 'Yes\n' | parted -a none "$LOOP" unit B resizepart "$IMG_ROOT_PARTN" "$TRUNCATE_TOTAL" ---pretend-input-tty 2>&1); then
echo -e "${Yellow}$output\n${Red}!! PARTED FAILED!!!"
debug 'BREAK'
@@ -998,9 +996,7 @@ function do_rsync() {
debug 'DEBUG' "tmp_file=$tmp_file"
if [ "$EXCLUDE_FILE" = true ]; then
- #debug 'DEBUG' "Running: rsync -ahvHAX --exclude-from=$(dirname $0)/exclude.txt --exclude={${IMG_PATH}/*,${TMP_DIR},${tmp_file}} --info=progress2 --stats "$RSYNC_DELETE" --force --partial --delete-excluded / $TMP_DIR"
debug 'DEBUG' "Running: rsync -ahvHAX --exclude-from="$EXCLUDE_FILE_LOCATION" --exclude={${IMG_PATH}/*,${TMP_DIR},${tmp_file}} --info=progress2 --stats "$RSYNC_DELETE" --force --partial --delete-excluded / $TMP_DIR"
- #rsync -ahvHAX --exclude-from=$(dirname "$0")/exclude.txt --exclude={${IMG_PATH}/*,${TMP_DIR},${tmp_file}} --info=progress2 --stats "$RSYNC_DELETE" --force --partial --delete-excluded / "$TMP_DIR" 2>&1 | tee "$TTY_AVAILABILITY" > "$tmp_file"
rsync -ahvHAX --exclude-from="$EXCLUDE_FILE_LOCATION" --exclude={${IMG_PATH}/*,${TMP_DIR},${tmp_file}} --info=progress2 --stats "$RSYNC_DELETE" --force --partial --delete-excluded / "$TMP_DIR" 2>&1 | tee "$TTY_AVAILABILITY" > "$tmp_file"
# Get the exit status of rsync from PIPESTATUS
if [ "${PIPESTATUS[0]}" -ne 0 ] && [ "${PIPESTATUS[0]}" -ne 23 ]; then # code 23 = rsync warning: some files vanished before they could be transferred (code 24) at main.c
@@ -1207,7 +1203,6 @@ function make_img() {
if [ $PARTITION_TABLE == 'gpt' ]; then
echo -e "${White}## ${Green}GPT partition table detected, ${Yellow}sgdisk needed, ${IWhite}checking for application..."
$SLEEPING
- #if [[ ! -f $(which sgdisk 2>&1) ]]; then
if ! command -v sgdisk > /dev/null 2>&1; then
echo -e "${Yellow}!! sgdisk is NOT installed..."
debug 'INFO' 'sgdisk not available on system'
@@ -1220,7 +1215,6 @@ function make_img() {
fi
echo ''
debug 'INFO' 'Y or y pressed to confirm'
- #if [[ -f $(which apt 2>&1) ]]; then
if command -v apt > /dev/null 2>&1; then
echo -e "${White}## ${Green}apt found, ${IWhite}trying to install gdisk..."
read -p "Do you want to use apt to install gdisk? (will upgrade system) [y/n] " -n 1 -r
@@ -1234,7 +1228,6 @@ function make_img() {
debug 'INFO' 'Y or y pressed to confirm'
debug 'DEBUG' 'Running: apt update -y && apt upgrade -y && apt install gdisk -y'
apt update -y && apt upgrade -y && apt install gdisk -y
- #elif [[ -f $(which pacman 2>&1) ]]; then
elif command -v pacman > /dev/null 2>&1; then
echo -e "${White}## ${Green}pacman found, ${IWhite}trying to install gdisk..."
read -p "Do you want to use pacman to install gptfdisk? (will do -Syu first) [y/n] " -n 1 -r
@@ -1311,7 +1304,7 @@ function make_img() {
exit 1
fi
- # ext4 & f2fs on root
+ # ext4 or f2fs on root
elif [ "$FSTYPE" == 'ext4' ] || [ "$FSTYPE" == 'f2fs' ]; then
debug 'DEBUG' "Running: parted -s -a none $LOOP unit B mkpart primary $LOCAL_ROOT_START 100%"
#if ! output=$(parted -s -a none "$LOOP" unit B mkpart primary "$FSTYPE" "$LOCAL_ROOT_START" 100% 2>&1); then
@@ -1346,7 +1339,6 @@ function make_img() {
if [ "$F2FS" = true ]; then
echo -e "${White}## ${Green}--f2fs option selected, mkfs.f2fs is needed, ${IWhite}checking if installed..."
$SLEEPING
- #if [[ ! -f $(which mkfs.f2fs 2>&1) ]]; then
if ! command -v mkfs.f2fs > /dev/null 2>&1; then
echo -e "${Yellow}!! mkfs.f2fs is NOT installed..."
debug 'INFO' 'mkfs.f2fs (f2fs-tools) not available on system'
@@ -1939,7 +1931,7 @@ return 0
# Function to print result
function print_result() {
- declare -i AFTER_SIZE=$(ls -l "$IMG_FILE" | cut -d ' ' -f 5)
+ declare -i AFTER_SIZE=$(stat -c %s "$IMG_FILE")
AFTER_SIZE=$(( AFTER_SIZE / 1024 / 1024 ))
echo -e "${White}## ${Green}Backup done."
@@ -2138,19 +2130,11 @@ if [ "$DEBUG" = true ]; then
fi
# Check if usage of exclude.txt is requested
-# if [ "$EXCLUDE_FILE" = true ]; then
-# debug 'INFO' "-f selected by user, using $(dirname $0)/exclude.txt"
-# if ! [ -f $(dirname "$0")/exclude.txt ]; then
-# echo -e "${Red}!! ERROR! ${Green}-f selected but exclude.txt ${Yellow}is not present in script directory!"
-# debug 'ERROR' 'exclude.txt does not exist in script directory, exit 3'
-# exit 3
-# fi
-# debug 'DEBUG' "$(dirname $0)/exclude.txt exists"
if [ "$EXCLUDE_FILE" = true ]; then
debug 'INFO' "-f selected by user, using $EXCLUDE_FILE_LOCATION"
if ! [ -f "$EXCLUDE_FILE_LOCATION" ]; then
- echo -e "${Red}!! ERROR! ${Green}-f selected but shrink-backup.conf ${Yellow}does not exist!"
- debug 'ERROR' 'shrink-backup.conf does not exist, exit 3'
+ echo -e "${Red}!! ERROR! ${Green}-f selected but $EXCLUDE_FILE_LOCATION ${Yellow}does not exist!"
+ debug 'ERROR' "$EXCLUDE_FILE_LOCATION does not exist, exit 3"
exit 3
fi
debug 'DEBUG' "$EXCLUDE_FILE_LOCATION exists"
From b32cbd2bbe1f52c16f13f31a7ea4e3cab2a6de0b Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Sat, 19 Oct 2024 10:27:43 +0200
Subject: [PATCH 44/46] Update README.md - v1.2
Preparation for merging with main
---
README.md | 112 ++++++++++++++++++++++++++++--------------------------
1 file changed, 58 insertions(+), 54 deletions(-)
diff --git a/README.md b/README.md
index 0c50d52..c0368ee 100644
--- a/README.md
+++ b/README.md
@@ -4,34 +4,35 @@ _I made this script because I wanted a universal method of backing up my SBC:s i
shrink-backup is a very fast utility for backing up your SBC:s into minimal bootable img files for easy restore with autoexpansion at boot.
-Supports backing up `boot` & `root` partitions, data from other partitions will be written to `root` if not excluded ([`btrfs`](#btrfs) excluded, all subvolumes will be created).
+Supports backing up `root` & `boot` (if existing) partitions. Data from other partitions will be written to `root` if not excluded (exception for [`btrfs`](#btrfs), all existing subvolumes in `/etc/fstab` will be created).
Please see [`Info`](#info) section.
-Autoexpansion tested on **Raspberry Pi** os (bookworm and older), **Armbian**, **Manjaro-arm**, **DietPi** & **ArchLinuxARM** for rpi with `ext4` or [`f2fs`](#f2fs) root partition.
-(Also **experimental** [`btrfs`](#btrfs) functionality, please read further down)
+Autoexpansion tested on **Raspberry Pi** os (bookworm and older), **Armbian**, **Manjaro-arm**, **DietPi** & **ArchLinuxARM** for rpi with `ext4` or [`f2fs`](#f2fs) root partition.
+(Also **experimental** [`btrfs`](#btrfs) functionality, please read further down)
Full support for usage inside [webmin](https://webmin.com/) (including "custom command" button). Thank you to [iliajie](https://github.com/iliajie) for helping out. ❤️
-**Latest release:** [shrink-backup.v1.1](https://github.com/UnconnectedBedna/shrink-backup/releases/download/v1.1/shrink-backup.v1.1.tar.gz)
-[**Testing branch:**](https://github.com/UnconnectedBedna/shrink-backup/tree/testing) If you want to have the absolute latest version. There might be bugs.
+**Latest release:** [shrink-backup.v1.2](https://github.com/UnconnectedBedna/shrink-backup/releases/download/v1.2/shrink-backup.v1.2.tar.gz)
+[**Testing branch:**](https://github.com/UnconnectedBedna/shrink-backup/tree/testing) If you want to use the absolute latest version. There might be bugs.
**Very fast restore thanks to minimal size of img file.**
-**Can back up any device as long as filesystem on root is `ext4`** or **[`f2fs`](#f2fs)** (experimental [`btrfs`](#btrfs))
-Default device that will be backed up is determined by scanning what disk-device `root` resides on.
-This means that **if** `boot` is a partition, that partition must be on the **same device as `root`**.
+**Can back up any device as long as filesystem on root is `ext4`** or **[`f2fs`](#f2fs)** (experimental [`btrfs`](#btrfs))
+Default device that will be backed up is determined by scanning what disk-device `root` resides on.
+This means that **if** `boot` is a partition, that partition must be on the **same device and before the `root` partition**.
+The script considers everything on the device before `root` as the bootsector.
Backing up/restoring, to/from: usb-stick `/dev/sdX` with Raspberry pi os has been tested and works. Ie, writing an sd-card img to a usb-stick and vice versa works.
**Ultra-fast incremental backups to existing img files.**
-See [wiki](https://github.com/UnconnectedBedna/shrink-backup/wiki) for a bit more information about usage.
-[Ideas and feedback](https://github.com/UnconnectedBedna/shrink-backup/discussions) is always appreciated, whether it's positive or negative. Please just keep it civil. :)
-Or if you find a bug or think something is missing in the script, please file a [Bug report or Feature request](https://github.com/UnconnectedBedna/shrink-backup/issues/new/choose)
+See [wiki](https://github.com/UnconnectedBedna/shrink-backup/wiki) for information about installation methods, usage and examples.
+[Ideas and feedback](https://github.com/UnconnectedBedna/shrink-backup/discussions) is always appreciated, whether it's positive or negative. Please just keep it civil. :)
+If you find a bug or think something is missing in the script, please file a [Bug report or Feature request](https://github.com/UnconnectedBedna/shrink-backup/issues/new/choose)
**Don't forget to ensure the script is executable.**
-**To restore a backup, simply "burn" the img file to a device using your favorite method.**
-When booting up a restored image with autoresize active, **please wait until the the reboot sequence has occured.** The login prompt may very well become visible before the autoresize function has rebooted.
+**To restore a backup, simply "burn" the img file to a device using your favorite method.**
+When booting up a restored image with autoresize active, **please wait until the the reboot sequence has occurred.** The login prompt _may_ very well become visible before the autoresize function has rebooted.
@@ -81,8 +82,8 @@ sudo shrink-backup -l --loop /path/to/backup.img 1024 (write to log file, expand
The folder where the img file is created will **ALWAYS be excluded in the backup.**
If `-t` option is selected, `exclude.txt` **MUST exist** (but can be empty) within the **directory where the script is located** or the script will exit with an error.
-Use one directory per line in `exclude.txt`.
-`/directory/*` = create directory but exclude content.
+Use one directory per line in `exclude.txt`.
+`/directory/*` = create directory but exclude content.
`/directory` = exclude the directory completely.
If `-t` is **NOT** selected the following folders will be excluded:
@@ -99,14 +100,14 @@ If `-t` is **NOT** selected the following folders will be excluded:
```
#### `-l` (Log file)
-Use `-l` to write debug info into `shrink-backup.log` file located in the same directory as the script.
+Use `-l` to write debug info into `shrink-backup.log` file located in the same directory as the script.
Please provide this file if filing a [Bug report](https://github.com/UnconnectedBedna/shrink-backup/issues/new/choose)
#### `-z` (Zoom speed)
-The `-z` "zoom" option simply removes the one second sleep at each prompt to give the user time to read.
-By using the option, you save 15-25s when running the script.
+The `-z` "zoom" option simply removes the one second sleep at each prompt to give the user time to read.
+By using the option, you save 15-25s when running the script.
When used in combination with `-y` **warnings will also be bypassed! PLEASE use with care!**
@@ -116,10 +117,10 @@ Add `--fix` to your options if a backup fails during `rsync` with a "broken pipe
**Example:** `sudo shrink-backup -Ua --fix /path/to/backup.img`
-The reason it happens is because `rsync` normally deletes files during the backup, not creating a file-list > removing files from img before starting to copy.
+The reason it happens is because `rsync` normally deletes files during the backup, not creating a file-list > removing files from img before starting to copy.
So if you have removed and added new data on the system you backup from, there is a risk `rsync` tries to copy the new data before deleting data from the img, hence completely filling the img.
-Using `--fix` makes `rsync` create a file-list and delete data **before** starting to transfer new data. This also means the backup takes a little longer.
+Using `--fix` makes `rsync` create a file-list and delete data **before** starting to transfer new data. This also means the backup takes a little longer.
Having a "broken pipe" error during backup has in my experience never broken an img backup after either using `--fix` (can be used in combination with `-a`) or adding `[extra space]` while updating the backup with `-U`.
@@ -129,28 +130,29 @@ Use `--loop` to loop an img file to your `/dev`.
**Example:** `sudo shrink-backup --loop /path/to/backup.img`
-If used in combination with `[extra space]` the amount in MiB will be added to the **IMG FILE** NOT any partition.
-With this you can for example run `sudo gparted /dev/loop0` (if you have a graphical interface) to manually manage the img partitions in a graphical interface with `gparted`.
-If you added `[extra space]` this will then show up as unpartitioned space at the end of the device.
+If used in combination with `[extra space]` the amount in MiB will be added to the **IMG FILE** NOT any partition.
+With this you can for example run `sudo gparted /dev/loop0` (if you have a graphical interface) to manually manage the img partitions in a graphical interface with `gparted`.
+If you added `[extra space]` this will then show up as unpartitioned space at the end of the device where you can create partition(s) and manually copy data to by mounting the new loop partition that will become visible in `lsblk`.
+If you do this, don't forget to create or update the img with `-e` (disable autoexpansion) first. Autoexpansion will not work since the space will be occupied by your manually managed partition.
**Example:** `sudo shrink-backup --loop /path/to/backup.img 1024`
This functionality works on any linux system, just use the script on any img file anywhere available to the computer.
-To remove the loop: `sudo losetup -d /dev/loop0`, change `loop0` to the correct `dev` it got looped to.
+To remove the loop: `sudo losetup -d /dev/loop0`, change `loop0` to the correct `dev` it got looped to.
To remind yourself: `lsblk /dev/loop*` if you forgot the location after using `--mount`
#### `--f2fs` (Convert `ext4` into `f2fs` on img file)
-ONLY use this for **CONVERTING** filesystem into img file, **if you already have `f2fs` on your root, do not use this option.**
-The script will detect what filesystem is used on `root` and act accordingly.
+ONLY use this for **CONVERTING** filesystem into img file, **if you already have `f2fs` on your root, do not use this option.**
+The script will detect what filesystem is used on `root` and act accordingly.
Only supported with new backups, not when using `-U`.
-Autoexpansion at boot is not supported for `f2fs` (there is no way of resizing a mounted `f2fs` filesystem, unlike with `ext4`) so resizing root partition have to be made manually after writing img to sd-card.
+Autoexpansion at boot is not supported for `f2fs` (there is no way of resizing a mounted `f2fs` filesystem, unlike with `ext4`) so resizing root partition have to be made manually after writing img to sd-card.
Resize operations (when updating backup with `-U`) is not available for `f2fs` _as of now_.
-The script will make backups of `fstab` & `cmdline.txt` into `fstab.shrink-backup.bak` & `cmdline.txt.shrink-backup.bak` on the img.
+The script will make backups of `fstab` & `cmdline.txt` into `fstab.shrink-backup.bak` & `cmdline.txt.shrink-backup.bak` on the img.
It will then change from `ext4` to `f2fs` in `fstab` & `cmdline.txt` and add `discard` to the options on the `root` partition in `fstab`.
Please read information about [`f2fs`](#f2fs) further down.
@@ -158,13 +160,14 @@ Please read information about [`f2fs`](#f2fs) further down.
### Info
-**Rsync WILL cross filesystem boundries, so make sure you exclude external drives unless you want them included in the backup.**
+**Rsync WILL cross filesystem boundries, so make sure you [[#`-t` (exclude.txt)|exclude]] external mounts unless you want them included in the backup. (separate `/home` for example)**
-The script will **ONLY** create `boot` (if exits) and `root` partitions on the img file.
-**Not excluding other partitions will copy the data to the img `root` partition, not create more partitions,** so make sure to **_manually add_ `[extra space]`** if you do this.
-Experimental [`btrfs`](#btrfs) is an exception to this.
+The script will **ONLY** create `boot` (if exits) and `root` partitions on the img file.
+The script will **ONLY** look at your `root` partition when calculating sizes.
+**Not excluding other mounts will copy that data to the img `root` partition, not create more partitions,** so make sure to **_manually add_ `[extra space]`** if you do this.
+Experimental [`btrfs`](#btrfs) is an exception to this, all subvolumes will be created.
-The script will **ONLY** look at your `root` partition when calculating sizes.
+See [[#`--loop` (Loop img file)|--loop]] for how to manually include more partitions in the img.
@@ -187,7 +190,7 @@ To create a backup img using recomended size, use the `-a` option and the path t
**Example:** `sudo shrink-backup -a /path/to/backup.img`
-Theoretically the script should work on any device as long as root filesystem is `ext4`, [`f2fs`](#f2fs) or **experimental** [`btrfs`](#btrfs).
+Theoretically the script should work on any device as long as root filesystem is `ext4`, [`f2fs`](#f2fs) or **experimental** [`btrfs`](#btrfs).
Since the script uses `lsblk` to crosscheck with `/etc/fstab` to figure out where `root` resides it does not matter what device it is on.
Even if you forget to disable autoexpansion on a non supported OS, the backup will not fail, it will just skip creating the autoresize scripts. :)
@@ -211,11 +214,12 @@ Even if you forget to disable autoexpansion on a non supported OS, the backup wi
Added space is added on top of `df` reported "used space", not the size of the partition. Added space is in MiB, so if you want to add 1G, add 1024.
-The script can be instructed to set the img size by requesting recomended minimum size from `e2fsck` or `du` (`e2fsck` does not work on `f2fs` f.ex) by using the `-a` option.
-This is not the absolute smallest size you can achieve but is the "safest" way to create a "smallest possible" img file.
+The script can be instructed to set the img size by requesting recomended minimum size from `e2fsck` or `du` (`e2fsck` does not work on `f2fs` f.ex) by using the `-a` option.
+This is not the absolute smallest size you can achieve but is the "safest" way to create a "smallest possible" img file.
If you do not increase the size of the filesystem you are backing up from too much, you can most likely keep it updated with the update function (`-U`) of the script.
-By using `-a` in combination with `-U` the script will resize the img file if needed (not supported on [`f2fs`](#f2fs)).
+By using `-a` in combination with `-U` the script will resize the img file if needed (not supported on [`f2fs`](#f2fs)).
+Using combination `-Ua` on an img that has become overfilled works, if not add `--fix` and retry.
Please see [`--fix`](#--fix-broken-pipe) and [image update](#image-update) sections for more information.
@@ -226,7 +230,7 @@ To get the absolute smallest img file possible, do NOT use `-a` option, instead
**Example:** `sudo shrink-backup /path/to/backup.img 0`
-This will instruct the script to get the used space from `df` and adding 128MiB "*wiggle room*".
+This will instruct the script to get the used space from `df` and adding 128MiB "*wiggle room*".
If you are like me, doing a lot of testing, rewriting the sd-card multiple times when experimenting, the extra time it takes each "burn" will add up pretty fast.
**Example:**
@@ -235,15 +239,15 @@ If you are like me, doing a lot of testing, rewriting the sd-card multiple times
-rw-r--r-- 1 root root 3.3G Jul 22 22:37 test0.img # file created with 0
```
-**Disclaimer!**
-Because of how filesystems work, `df` is never a true representation of what will actually fit in a created img file.
+**Disclaimer!**
+Because of how filesystems work, `df` is never a true representation of what will actually fit in a created img file.
Each file, no matter the size, will take up one block of the filesystem, so if you have a LOT of very small files (running `docker` f.ex) the "0 added space method" might fail during rsync. Increase the 0 a little bit and retry.
-This also means you have VERY little free space on the img file after creation.
+This also means you have VERY little free space on the img file after creation.
If the filesystem you back up from increases in size, an update (`-U`) of the img file might fail.
-By using `-a` in combination with `-U` the script will resize the img file if needed.
-Using combination `-Ua` on an img that has become overfilled works, if not add `--fix` and retry.
+By using `-a` in combination with `-U` the script will resize the img file if needed (not supported on [`f2fs`](#f2fs)).
+Using combination `-Ua` on an img that has become overfilled works, if not add `--fix` and retry.
Please see [`--fix`](#--fix-broken-pipe) and [Image update](#image-update) sections for more information.
@@ -272,36 +276,36 @@ To update an existing img file simply use the `-U` option and the path to the im
### Resizing img file when updating
If `-a` is used in combination with `-U`, the script will compare the root partition on the img file to the size `resize2fs` recommends as minimum (or `du` calculations depending on filesystem).
-The **img file** `root` **partition** needs to be **>=256MB smaller** than `resize2fs` (or `du` calculations) recommended minimum to be expanded.
-The **img file** `root` **partition** needs to be **>=512MB bigger** than `resize2fs` (or `du` calculations) recommended minimum to be shrunk.
+The **img file** `root` **partition** needs to be **>=256MB smaller** than `resize2fs` (or `du` calculations) recommended minimum to be expanded.
+The **img file** `root` **partition** needs to be **>=512MB bigger** than `resize2fs` (or `du` calculations) recommended minimum to be shrunk.
This is to protect from unessesary resizing operations most likely not needed.
-If _manually added_ `[extra space]` is used in combination with `-U`, the img file's `root` partition will be expanded by that amount. **No checks are being performed to make sure the data you want to back up will actually fit.**
+If _manually added_ `[extra space]` is used in combination with `-U`, the img file's `root` partition will be expanded by that amount. **No checks are being performed to make sure the data you want to back up will actually fit.**
Only expansion is possible with this method.
## f2fs
-The script will detect `f2fs` on `root` automatically and act accordingly.
+The script will detect `f2fs` on `root` automatically and act accordingly.
**Do NOT USE [`--f2fs`](#--f2fs-Convert-ext4-into-f2fs-on-img-file) unless you are converting from a `ext4` filesystem (on your system) into `f2fs` on the img file.**
-Autoexpansion at boot is not possible with `f2fs`. User will have to manually expand img to cover entire storage media (f.ex sd-card) when restoring.
-Resizing of img `root` partition while updating img (`-U`) is not possible with `f2fs` _as of now_. User will have to create a new backup if img runs out of space.
+Autoexpansion at boot is not possible with `f2fs`. User will have to manually expand img to cover entire storage media (f.ex sd-card) when restoring.
+Resizing of img `root` partition while updating img (`-U`) is not possible with `f2fs` _as of now_. User will have to create a new backup if img runs out of space.
This is something I am planning to implement further down the line.
## btrfs
-**ALL testing has been done on Manjaro-arm**
+**ALL testing has been done on Manjaro-arm**
**THIS IS NOT A CLONE, IT IS A BACKUP OF REQUIRED FILES FOR A BOOTABLE BTRFS SYSTEM!**
-All options in script should work just as on `ext4`. The script will detect `btrfs` and act accordingly.
-The script will treat snapshots as nested volumes, so make sure to exclude snapshots if you have any, or directories and **nested volumes** will be created on the img file (not as copy-on-write snapshots).
-This can be done in `exclude.txt`, wildcards (*) _should_ work.
+All options in script should work just as on `ext4`. The script will detect `btrfs` and act accordingly.
+The script will treat snapshots as nested volumes, so make sure to exclude snapshots if you have any, or directories and **nested volumes** will be created on the img file (not as copy-on-write snapshots).
+This can be done in `exclude.txt`, wildcards (*) _should_ work.
When starting the script, the initial report window will tell you what volumes will be created. **Make sure these are correct before pressing Y**
-As of now, top level subvolumes are checked for in `/etc/fstab` and mounted accordingly, mount options should be preseved (for exmaple if you change compression).
+As of now, top level subvolumes are checked for in `/etc/fstab` and mounted accordingly, mount options should be preserved (if you for example changed compression).
Autoresize function works on Manjaro-arm.
From 0e115405a795bd4d973528c8dda73e4d66ca3fd3 Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Sat, 19 Oct 2024 10:43:43 +0200
Subject: [PATCH 45/46] Update README.md - v1.2 (fixed link)
Mental note... "Obsidian links will not work on github..." xD
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index c0368ee..4dd68f9 100644
--- a/README.md
+++ b/README.md
@@ -160,7 +160,7 @@ Please read information about [`f2fs`](#f2fs) further down.
### Info
-**Rsync WILL cross filesystem boundries, so make sure you [[#`-t` (exclude.txt)|exclude]] external mounts unless you want them included in the backup. (separate `/home` for example)**
+**Rsync WILL cross filesystem boundries, so make sure you [exclude](#-t-excludetxt) external mounts unless you want them included in the backup. (separate `/home` for example)**
The script will **ONLY** create `boot` (if exits) and `root` partitions on the img file.
The script will **ONLY** look at your `root` partition when calculating sizes.
From bf4d25635cdc4fcaea111e228f925c316adb4701 Mon Sep 17 00:00:00 2001
From: Marcus Johansson <30673661+UnconnectedBedna@users.noreply.github.com>
Date: Sat, 19 Oct 2024 11:05:38 +0200
Subject: [PATCH 46/46] Update README.md - v1.2
Missed the second link.
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 4dd68f9..c566bd2 100644
--- a/README.md
+++ b/README.md
@@ -167,7 +167,7 @@ The script will **ONLY** look at your `root` partition when calculating sizes.
**Not excluding other mounts will copy that data to the img `root` partition, not create more partitions,** so make sure to **_manually add_ `[extra space]`** if you do this.
Experimental [`btrfs`](#btrfs) is an exception to this, all subvolumes will be created.
-See [[#`--loop` (Loop img file)|--loop]] for how to manually include more partitions in the img.
+See [--loop](#--loop-loop-img-file) for how to manually include more partitions in the img.