Compare commits
8 Commits
0.0.1
..
08d6ccde0d
| Author | SHA1 | Date | |
|---|---|---|---|
| 08d6ccde0d | |||
| 7321d7e087 | |||
| 7609bf9c17 | |||
| 80c87e282b | |||
| 4922d1e369 | |||
| 080ac737fe | |||
| 8504eafa48 | |||
| 87be64e61b |
@@ -0,0 +1,25 @@
|
||||
---
|
||||
description: mtm-ddwipe project conventions
|
||||
---
|
||||
|
||||
# Project conventions
|
||||
- Use English throughout the project.
|
||||
- Keep shell scripts Bash-based when Bash is already used by the project.
|
||||
- Preserve the current behavior of the main script:
|
||||
- `mtm-ddwipe`: wipe devices.
|
||||
- Strengthen destructive-action safety checks in `mtm-ddwipe` when making changes.
|
||||
- Keep `mtm-ddwipe` interactive by default unless a change explicitly adds a safe opt-in flag.
|
||||
- Keep user-facing messages short, clear, and in English.
|
||||
- Prefer minimal, focused changes that do not alter the intent of the existing scripts, unless the script behavior is intentionally updated.
|
||||
- Maintain `.continue/rules/project.md` whenever project conventions or script behavior change.
|
||||
- `mtm-ddwipe` is a small Bash script with helper functions.
|
||||
- Keep the host and line-number removal behavior intact.
|
||||
- `mtm-ddwipe` must print a usage line and support `-h`/`--help`.
|
||||
- Validate that wipe targets are real block devices before operating on them.
|
||||
- Keep short, explicit confirmation prompts before destructive operations.
|
||||
- Keep error and help messages short, clear, and in English.
|
||||
- Keep help text concise and usage-first.
|
||||
|
||||
# Project identity
|
||||
- Main script: `mtm-ddwipe`
|
||||
- License: GNU GPL v3
|
||||
+112
-9
@@ -1,32 +1,135 @@
|
||||
#!/bin/bash
|
||||
|
||||
declare -r VERSION=${1}
|
||||
declare -r MESSAGE=${2}
|
||||
set -euo pipefail
|
||||
|
||||
declare -r TAGBRANCH=main
|
||||
declare CURRENTBRANCH=""
|
||||
declare ORIGBRANCH=""
|
||||
declare -r ARG1="${1:-}"
|
||||
declare -r ARG2="${2:-}"
|
||||
declare is_dry_run=false
|
||||
declare release_input=""
|
||||
|
||||
showHelp() {
|
||||
echo makerelease version
|
||||
cat <<'EOF'
|
||||
Usage:
|
||||
makerelease.sh VERSION
|
||||
makerelease.sh +0.0.1
|
||||
makerelease.sh +0.1
|
||||
makerelease.sh +1
|
||||
makerelease.sh --dry-run VERSION
|
||||
makerelease.sh --dry-run +0.0.1
|
||||
makerelease.sh --dry-run +0.1
|
||||
makerelease.sh --dry-run +1
|
||||
|
||||
Creates an annotated Git tag from the current dev branch.
|
||||
|
||||
If VERSION starts with +, it is treated as an increment:
|
||||
- +0.0.1 increments patch
|
||||
- +0.1 increments minor
|
||||
- +1 increments major
|
||||
|
||||
Use --dry-run to show the computed release version without running Git actions.
|
||||
|
||||
Requirements:
|
||||
- run from a clean Git working tree
|
||||
- current branch must be dev for real releases
|
||||
- main branch must exist locally
|
||||
EOF
|
||||
}
|
||||
|
||||
if [ "${VERSION}" == "" ]; then
|
||||
cleanup() {
|
||||
if [ -n "${ORIGBRANCH}" ] && [ "${CURRENTBRANCH}" != "${ORIGBRANCH}" ]; then
|
||||
git checkout "${ORIGBRANCH}" >/dev/null 2>&1 || true
|
||||
fi
|
||||
}
|
||||
|
||||
trap cleanup EXIT
|
||||
|
||||
if [ "${ARG1}" = "--dry-run" ] || [ "${ARG1}" = "-n" ]; then
|
||||
is_dry_run=true
|
||||
release_input="${ARG2:-}"
|
||||
else
|
||||
release_input="${ARG1}"
|
||||
fi
|
||||
|
||||
if [ -z "${release_input}" ]; then
|
||||
showHelp
|
||||
echo ""
|
||||
echo "no version provided!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CURRENTBRANCH=$(git rev-parse --abbrev-ref HEAD)
|
||||
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
||||
echo "You are not inside a Git repository!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! "${CURRENTBRANCH}" == "dev" ]; then
|
||||
if [ -n "$(git status --porcelain)" ]; then
|
||||
echo "Working tree is not clean!"
|
||||
echo "Commit or stash your changes before creating a release."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CURRENTBRANCH=$(git rev-parse --abbrev-ref HEAD)
|
||||
ORIGBRANCH="${CURRENTBRANCH}"
|
||||
|
||||
if [ "${is_dry_run}" = false ] && [ "${CURRENTBRANCH}" != "dev" ]; then
|
||||
echo "You are not in dev branch!"
|
||||
echo "Use dev branch to make a release!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
release_tag="${release_input}"
|
||||
if [ "${release_input}" != "${release_input#+}" ]; then
|
||||
current_tag="$(git describe --tags --abbrev=0 2>/dev/null || true)"
|
||||
if [ -z "${current_tag}" ]; then
|
||||
echo "No existing tag found to increment from!"
|
||||
exit 1
|
||||
fi
|
||||
case "${release_input}" in
|
||||
+1)
|
||||
release_tag="$(printf '%s' "${current_tag}" | awk -F. 'BEGIN{OFS="."} { $1+=1; $2=0; $3=0; print }')"
|
||||
;;
|
||||
+0.1)
|
||||
release_tag="$(printf '%s' "${current_tag}" | awk -F. 'BEGIN{OFS="."} { $2+=1; $3=0; print }')"
|
||||
;;
|
||||
+0.0.1)
|
||||
release_tag="$(printf '%s' "${current_tag}" | awk -F. 'BEGIN{OFS="."} { $3+=1; print }')"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported increment syntax: ${release_input}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if git rev-parse -q --verify "refs/tags/${release_tag}" >/dev/null; then
|
||||
echo "Tag ${release_tag} already exists!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "${is_dry_run}" = true ]; then
|
||||
echo "Dry run: computed release tag ${release_tag}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Release tag selected: ${release_tag}"
|
||||
read -r -p "Proceed with release? [y/N] " confirm
|
||||
case "${confirm}" in
|
||||
y|Y)
|
||||
;;
|
||||
*)
|
||||
echo "Release cancelled."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
git checkout "${TAGBRANCH}"
|
||||
git merge "${CURRENTBRANCH}"
|
||||
CURRENTBRANCH="${TAGBRANCH}"
|
||||
git merge "${ORIGBRANCH}"
|
||||
git push
|
||||
git tag -a "${VERSION}" -m "${MESSAGE}"
|
||||
git tag -a "${release_tag}" -m "Release ${release_tag}"
|
||||
git push --tags
|
||||
git checkout "${CURRENTBRANCH}"
|
||||
|
||||
echo "Created release tag ${release_tag}"
|
||||
|
||||
+76
-54
@@ -1,82 +1,104 @@
|
||||
#!/bin/bash
|
||||
|
||||
declare -r DEV="${1}"
|
||||
declare STARTDATE=""
|
||||
declare STARTDATESTRING=""
|
||||
|
||||
show_help() {
|
||||
echo "ddwipe dev (/dev/sdX)"
|
||||
echo ""
|
||||
echo "Version : 0.0.3"
|
||||
echo "Usage: mtm-ddwipe DEVICE"
|
||||
echo ""
|
||||
echo "Wipe a block device."
|
||||
echo "Version: 0.0.3"
|
||||
}
|
||||
|
||||
check_args() {
|
||||
if [ "${1}" == "" ]; then
|
||||
show_help
|
||||
exit 1
|
||||
fi
|
||||
case "${1}" in
|
||||
-h|--help)
|
||||
show_help
|
||||
exit 0
|
||||
;;
|
||||
"")
|
||||
show_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
check_dev_exist() {
|
||||
if [ ! -e "${1}" ]; then
|
||||
echo "${1} is missing."
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -e "${1}" ]; then
|
||||
echo "Missing device."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
check_dev_block() {
|
||||
if [ ! -b "${1}" ]; then
|
||||
echo "Not a block device."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
confirm_wipe() {
|
||||
lsblk "${1}"
|
||||
echo ""
|
||||
read -r -p "Wipe ${1} (y/[n])?" CHOICE
|
||||
case "${CHOICE}" in
|
||||
y|Y ) echo "";;
|
||||
* )
|
||||
echo "Canceled"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
lsblk "${1}"
|
||||
echo ""
|
||||
read -r -p "Wipe ${1} (y/[n])? " CHOICE
|
||||
case "${CHOICE}" in
|
||||
y|Y ) echo "";;
|
||||
* )
|
||||
echo "Canceled"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
wipe_dev() {
|
||||
echo "Begin wiping device ${1}"
|
||||
echo ""
|
||||
echo "Start date :"
|
||||
date
|
||||
echo ""
|
||||
echo "blkdiscard secure"
|
||||
if ! blkdiscard -f -p 1G -s "${1}"; then
|
||||
echo ""
|
||||
echo "blkdiscard zero"
|
||||
if ! blkdiscard -f -p 1G -z "${1}"; then
|
||||
echo ""
|
||||
echo "dd zero"
|
||||
if ! dd if=/dev/zero of="${1}" bs=1M status=progress; then
|
||||
# Need check if dd has all writed, if yes, return no error
|
||||
# echo "Error wiping device ${1}, use phisical destroy !"
|
||||
echo "Wiped with dd, check if full size is writed."
|
||||
echo "Otherwise use a mechanical destruction of the device."
|
||||
print_time
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
echo ""
|
||||
echo "Device ${1} wipped !"
|
||||
STARTDATE=$(date +%s)
|
||||
STARTDATESTRING="$(date)"
|
||||
echo "Begin wiping device ${1}"
|
||||
echo ""
|
||||
echo "Start date :"
|
||||
echo "${STARTDATESTRING}"
|
||||
echo ""
|
||||
echo "blkdiscard secure"
|
||||
if ! blkdiscard -f -p 500M -s -v "${1}"; then
|
||||
echo ""
|
||||
echo "blkdiscard zero"
|
||||
if ! blkdiscard -f -p 500M -z -v "${1}"; then
|
||||
echo ""
|
||||
echo "dd zero"
|
||||
if ! dd if=/dev/zero of="${1}" bs=1M status=progress; then
|
||||
# Need check if dd has all writed, if yes, return no error
|
||||
# echo "Error wiping device ${1}, use phisical destroy !"
|
||||
echo "Wiped with dd, check if full size is writed."
|
||||
echo "Otherwise use a mechanical destruction of the device."
|
||||
print_time
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
echo ""
|
||||
echo "Device ${1} wiped."
|
||||
}
|
||||
|
||||
print_time() {
|
||||
ENDDATE=$(date +%s)
|
||||
echo ""
|
||||
echo "End date :"
|
||||
date
|
||||
echo ""
|
||||
echo "Start date :"
|
||||
echo "${STARTDATESTRING}"
|
||||
|
||||
CALCTIME=$((ENDDATE-STARTDATE))
|
||||
echo ""
|
||||
echo "Total time :"
|
||||
date -d@${CALCTIME} -u +%H:%M:%S
|
||||
ENDDATE=$(date +%s)
|
||||
echo ""
|
||||
echo "End date :"
|
||||
date
|
||||
|
||||
CALCTIME=$((ENDDATE-STARTDATE))
|
||||
echo ""
|
||||
echo "Total time :"
|
||||
date -d@${CALCTIME} -u +%H:%M:%S
|
||||
}
|
||||
|
||||
check_args "${DEV}"
|
||||
check_dev_exist "${DEV}"
|
||||
check_dev_block "${DEV}"
|
||||
confirm_wipe "${DEV}"
|
||||
STARTDATE=$(date +%s)
|
||||
wipe_dev "${DEV}"
|
||||
print_time
|
||||
|
||||
Reference in New Issue
Block a user