-
-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
5,277 additions
and
4,749 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[Desktop Entry] | ||
Version=2.0 | ||
Name=DietPi-Services | ||
Type=Application | ||
Comment=Control system services and apply process tool tweaks | ||
Terminal=true | ||
Exec=/DietPi/dietpi/dietpi-services | ||
Icon=/var/lib/dietpi/dietpi-software/installed/desktop/icons/dietpi-icon.png | ||
Categories=ConsoleOnly;System; | ||
GenericName=DietPi-Services |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
$HTTP["url"] =~ "^/ompd($|/)" { | ||
|
||
# https://github.com/MichaIng/DietPi/issues/2156#issuecomment-497512475 | ||
server.stream-response-body = 1 | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"data_dir": "$G_FP_DIETPI_USERDATA/mycroft-data", | ||
// As DietPi uses plain ALSA, default paplay is not available | ||
"play_wav_cmdline": "aplay %1", | ||
// Default DietPi asound.conf requires listener sample rate 48000 (default: 16000) is most cases | ||
"listener": { | ||
"sample_rate": 48000 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,260 @@ | ||
#!/bin/bash | ||
{ | ||
#//////////////////////////////////// | ||
# DietPi Image creation/finalise Script | ||
# | ||
#//////////////////////////////////// | ||
# Created by Daniel Knight / [email protected] / dietpi.com | ||
# Updated by MichaIng / [email protected] / dietpi.com | ||
# | ||
#//////////////////////////////////// | ||
# - Reads disk to image | or use existing .img file | ||
# - Resizes RootFS partition | ||
# - Hashes and 7z's the final image ready for release. | ||
#//////////////////////////////////// | ||
|
||
# Import DietPi-Globals --------------------------------------------------------------- | ||
. /DietPi/dietpi/func/dietpi-globals | ||
G_PROGRAM_NAME='DietPi-Imager' | ||
G_CHECK_ROOT_USER | ||
G_CHECK_ROOTFS_RW | ||
G_INIT | ||
# Import DietPi-Globals --------------------------------------------------------------- | ||
|
||
FP_SOURCE='' | ||
FP_LOOPBACK='' | ||
FP_ROOT_DEV='' | ||
ROOT_PARTITION_INDEX='' | ||
OUTPUT_IMG_NAME='' | ||
OUTPUT_7Z_NAME='' | ||
GPT=0 | ||
DIETPI_VERSION='v6.25' | ||
|
||
Delete_Loopback(){ | ||
|
||
[[ $FP_LOOPBACK ]] && G_RUN_CMD losetup -d $FP_LOOPBACK | ||
|
||
} | ||
|
||
Exit_On_Fail(){ | ||
|
||
Delete_Loopback | ||
exit 1 | ||
|
||
} | ||
|
||
Menu_Main(){ | ||
|
||
G_WHIP_MENU_ARRAY=( | ||
|
||
'Drive' ': Save a drive/disk contents to an image, that you can work with' | ||
'Image' ': Use an existing image file (.img) to work with' | ||
|
||
) | ||
|
||
G_WHIP_MENU 'Please select an option:' || Exit_On_Fail | ||
if [[ $G_WHIP_RETURNED_VALUE == 'Drive' ]]; then | ||
|
||
# Detect drives and list for selection | ||
G_WHIP_MENU_ARRAY=($(lsblk -npo NAME,SIZE | grep '^/')) | ||
if [[ ! $G_WHIP_MENU_ARRAY ]] || ! G_WHIP_MENU 'Please select the drive you wish to save as an image:'; then | ||
|
||
Exit_On_Fail | ||
|
||
fi | ||
FP_SOURCE='/root/dietpi-imager_tmp.img' | ||
dd if=$G_WHIP_RETURNED_VALUE of=$FP_SOURCE bs=4K status=progress || Exit_On_Fail | ||
|
||
elif [[ $G_WHIP_RETURNED_VALUE == 'Image' ]]; then | ||
|
||
/DietPi/dietpi/dietpi-explorer 1 /root | ||
local fp_selected='/tmp/.dietpi-explorer_selected_location' | ||
[[ -f $fp_selected ]] || Exit_On_Fail | ||
FP_SOURCE=$(<$fp_selected) | ||
rm $fp_selected | ||
if [[ ! -f $FP_SOURCE ]]; then | ||
|
||
G_DIETPI-NOTIFY 1 "Source image file ($FP_SOURCE) does not exist, aborting..." | ||
Exit_On_Fail | ||
|
||
fi | ||
|
||
fi | ||
|
||
# Attach .img file to loop device | ||
modprobe loop || Exit_On_Fail | ||
FP_LOOPBACK=$(losetup -f) | ||
losetup $FP_LOOPBACK "$FP_SOURCE" || Exit_On_Fail | ||
partprobe $FP_LOOPBACK || Exit_On_Fail | ||
|
||
# Detect partitions and list for selection | ||
G_WHIP_MENU_ARRAY=($(lsblk -npo NAME,SIZE ${FP_LOOPBACK}?*)) | ||
G_WHIP_MENU "Please select the root partition of $FP_LOOPBACK" || Exit_On_Fail | ||
ROOT_PARTITION_INDEX=${G_WHIP_RETURNED_VALUE: -1} | ||
|
||
G_WHIP_DEFAULT_ITEM='DietPi_<device>-<arch>-<distro>' | ||
G_WHIP_INPUTBOX "Please enter the new/output filename for $FP_SOURCE\n - DietPi_<device>-<arch>-<distro>\n - EG: DietPi_RPi-ARMv6-Stretch" || Exit_On_Fail | ||
OUTPUT_IMG_NAME=$G_WHIP_RETURNED_VALUE | ||
|
||
G_WHIP_DEFAULT_ITEM=$DIETPI_VERSION | ||
G_WHIP_INPUTBOX 'Please enter the DietPi version for this image:' || Exit_On_Fail | ||
DIETPI_VERSION=$G_WHIP_RETURNED_VALUE | ||
|
||
} | ||
|
||
Main(){ | ||
|
||
Menu_Main | ||
|
||
# Install required packages | ||
G_AG_CHECK_INSTALL_PREREQ gdisk dosfstools parted zerofree p7zip | ||
|
||
# Auto detect GPT partition table, failsafe detection of MBR to debug possibly other wording/partition table types | ||
if [[ $(parted $FP_LOOPBACK print) == *'Partition Table: msdos'* ]]; then | ||
|
||
GPT=0 | ||
|
||
elif [[ $(parted $FP_LOOPBACK print) == *'Partition Table: gpt'* ]]; then | ||
|
||
GPT=1 | ||
|
||
else | ||
|
||
G_DIETPI-NOTIFY 1 "Unknown partition table type ($(parted $FP_LOOPBACK print | mawk '/^Partition Table:/ {print $3;exit}')), aborting..." | ||
Exit_On_Fail | ||
|
||
fi | ||
|
||
# GPT images (RockPro64) after reading the image AND again after shrinking | ||
# To fix: | ||
# - GPT PMBR size mismatch (4458495 != 15523839) will be corrected by w(rite). | ||
# - 15523806 | ||
# RUN | ||
# - gdisk "$IMAGE_FP/$IMAGE_NAME" | ||
# w | y | ||
(( $GPT )) && echo -e 'w\ny\nq\n' | gdisk $FP_LOOPBACK # Needs testing for automation... | ||
|
||
# root partition dev | ||
FP_ROOT_DEV="${FP_LOOPBACK}p${ROOT_PARTITION_INDEX}" | ||
|
||
# Fsck | ||
e2fsck -f $FP_ROOT_DEV | ||
|
||
# Remount image for any required edits. | ||
fp_mnt='loopback_rootfs' | ||
mkdir -p /mnt/$fp_mnt | ||
if G_ERROR_HANDLER_INFO_ONLY=1 G_RUN_CMD mount $FP_ROOT_DEV /mnt/$fp_mnt; then | ||
|
||
G_WHIP_MSG "Image mounted for file editing, make changes if required: $FP_ROOT_DEV > /mnt/$fp_mnt\n\nPress 'Ok' when you are finished." | ||
sync | ||
G_RUN_CMD umount /mnt/$fp_mnt | ||
partprobe $FP_LOOPBACK # Probably not required as no partition changes, regardless, no harm. | ||
|
||
fi | ||
|
||
# Fsck | ||
e2fsck -f $FP_ROOT_DEV | ||
|
||
# Shrink file system to minimum | ||
# - Run multiple times until no change is done any more | ||
local out | ||
FS_SIZE=0 | ||
while : | ||
do | ||
|
||
resize2fs -M $FP_ROOT_DEV 2>&1 | tee resize2fs_out | ||
if out=$(grep -im1 'nothing to do!' resize2fs_out); then | ||
|
||
# Re-add 4 MiB to be failsafe, was required on Raspbian Buster for successful boot | ||
FS_SIZE=$(mawk '{print $5 + 1024}' <<< $out) # 4k blocks | ||
rm resize2fs_out | ||
resize2fs $FP_ROOT_DEV $FS_SIZE | ||
G_DIETPI-NOTIFY 2 "Reduced RootFS size to $(( $FS_SIZE / 256 + 1 )) MiB" | ||
FS_SIZE=$(( $FS_SIZE * 8 )) # 4k blocks => 512 byte sectors | ||
break | ||
|
||
elif out=$(grep -im1 'no such file or directory' resize2fs_out); then | ||
|
||
G_DIETPI-NOTIFY 1 'Partition not found' | ||
Exit_On_Fail | ||
|
||
fi | ||
|
||
done | ||
|
||
# Estimate minimum end sector | ||
PART_START=$(fdisk -l -o Start $FP_LOOPBACK | tail -1) # 512 byte sectors | ||
PART_END=$(( $PART_START + $FS_SIZE )) | ||
|
||
G_DIETPI-NOTIFY 2 "Shrinking root partition to: $(( $FS_SIZE / 2048 + 1 )) MiB" | ||
parted $FP_LOOPBACK unit s resizepart $ROOT_PARTITION_INDEX $PART_END yes | ||
partprobe $FP_LOOPBACK | ||
sync | ||
|
||
# Override free space with zeros to purge removed data and allow further image/archive size reduction | ||
zerofree -v $FP_ROOT_DEV | ||
|
||
# GPT images (RockPro64) after reading the image AND again after shrinking | ||
# To fix: | ||
# - GPT PMBR size mismatch (4458495 != 15523839) will be corrected by w(rite). | ||
# - 15523806 | ||
# RUN | ||
# - gdisk "$IMAGE_FP/$IMAGE_NAME" | ||
# w | y | ||
(( $GPT )) && echo -e 'w\ny\nq\n' | gdisk $FP_LOOPBACK | ||
|
||
# Estimate used size | ||
PART_SIZE=$(( ( $(fdisk -l -o End $FP_LOOPBACK | tail -1) + 1 ) * 512 )) # 512 byte sectors => Byte | ||
IMAGE_SIZE=$(( $PART_SIZE + ( 512 * 256 ) )) # 64 byte for secondary GPT + safety net | ||
|
||
# Create final image in /root | ||
cd /root | ||
|
||
# Truncate image file to used size | ||
truncate --size=$IMAGE_SIZE "$FP_SOURCE" | ||
|
||
# Loopback finished, clear loop | ||
partprobe $FP_LOOPBACK | ||
sync | ||
Delete_Loopback | ||
|
||
# Add version number to output file name | ||
OUTPUT_7Z_NAME="$OUTPUT_IMG_NAME.7z" | ||
OUTPUT_IMG_NAME="${OUTPUT_IMG_NAME//DietPi_/DietPi_${DIETPI_VERSION}_}.img" | ||
|
||
# Move new img to /root | ||
mv $FP_SOURCE $OUTPUT_IMG_NAME # TODO: if not same already location/file... | ||
|
||
# Generate hashes: MD5, SHA1, SHA256 | ||
G_DIETPI-NOTIFY 2 'Generating hash.txt, please wait...' | ||
cat << _EOF_ > hash.txt | ||
FILE: $OUTPUT_IMG_NAME | ||
DATE: $(date) | ||
MD5: $(md5sum $OUTPUT_IMG_NAME | mawk '{print $1}') | ||
SHA1: $(sha1sum $OUTPUT_IMG_NAME | mawk '{print $1}') | ||
SHA256: $(sha256sum $OUTPUT_IMG_NAME | mawk '{print $1}') | ||
_EOF_ | ||
|
||
# Download current README | ||
wget https://raw.githubusercontent.com/MichaIng/DietPi/master/README.md -O README.md || Exit_On_Fail | ||
|
||
# Generate 7z archive | ||
# NB: LZMA2 ultra compression method requires 2G RAM | ||
[[ -f $OUTPUT_7Z_NAME ]] && rm $OUTPUT_7Z_NAME | ||
if 7zr a -m0=lzma2 -mx=9 $OUTPUT_7Z_NAME $OUTPUT_IMG_NAME hash.txt README.md; then | ||
|
||
rm hash.txt README.md | ||
G_WHIP_MSG "[INFO] /root/$OUTPUT_7Z_NAME created" | ||
|
||
fi | ||
|
||
} | ||
|
||
#///////////////////////////////////////////////////////////////////////////////////// | ||
# Main | ||
#///////////////////////////////////////////////////////////////////////////////////// | ||
Main | ||
#----------------------------------------------------------------------------------- | ||
exit | ||
#----------------------------------------------------------------------------------- | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.