wip/shell

This commit is contained in:
Marc Beninca 2024-11-15 16:27:41 +01:00
parent 672b385447
commit f52abc28b3
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F
50 changed files with 0 additions and 0 deletions

3
shell/.shellcheckrc Normal file
View file

@ -0,0 +1,3 @@
disable=1090,3043
enable=all
shell=sh

71
shell/alias/apt.sh Normal file
View file

@ -0,0 +1,71 @@
# show package information
alias ac="\
apt-cache \
show \
"
# package versions policy
alias acp="\
apt-cache \
policy \
"
# search package
alias acs="\
apt-cache \
search \
"
#
alias agap="\
apt-get \
autopurge \
"
#
alias agar="\
apt-get \
autoremove \
"
# clean packages cache
alias agc="\
apt-get \
clean \
"
# upgrade allowing package installation or removal
alias agdu="\
apt-get \
dist-upgrade \
"
# install packages
alias agi="\
apt-get \
install \
"
#
alias agp="\
apt-get \
purge \
"
#
alias agr="\
apt-get \
remove \
"
# update packages catalog
alias agud="\
apt-get \
update \
"
# upgrade forbidding package installation or removal
alias agug="\
apt-get \
upgrade \
"

32
shell/alias/bash.sh Normal file
View file

@ -0,0 +1,32 @@
# change current directory to its parent
alias ..="\
cd \
.. \
"
# change current directory to its parent’s parent
alias ...="\
cd \
../.. \
"
# shorten alias
alias a="\
alias \
"
# swap directory (current ↔ previous)
alias sd="\
cd \
- \
"
# import source file
alias src="\
source \
"
# exit terminal
alias x="\
exit \
"

3
shell/alias/batcat.sh Normal file
View file

@ -0,0 +1,3 @@
alias bat="\
batcat \
"

48
shell/alias/btrfs.sh Normal file
View file

@ -0,0 +1,48 @@
alias bfdf="\
btrfs \
filesystem \
df \
"
alias bfdu="\
btrfs \
filesystem \
du \
--summarize \
"
alias bfu="\
btrfs \
filesystem \
usage \
"
alias bpg="\
btrfs \
property \
get \
"
alias bsc="\
btrfs \
subvolume \
create \
"
alias bsd="\
btrfs \
subvolume \
delete \
"
alias bss="\
btrfs \
subvolume \
snapshot \
"
alias bssr="\
btrfs \
subvolume \
snapshot -r \
"

19
shell/alias/byobu.sh Normal file
View file

@ -0,0 +1,19 @@
alias bb="\
byobu \
"
alias bba="\
byobu \
attach-session \
"
alias bbl="\
byobu \
ls \
"
alias bbn="\
byobu \
new-session \
-d \
"

11
shell/alias/chmod.sh Normal file
View file

@ -0,0 +1,11 @@
# change mode as directory
alias cmd="\
chmod \
\"755\" \
"
# change mode as file
alias cmf="\
chmod \
\"644\" \
"

11
shell/alias/chown.sh Normal file
View file

@ -0,0 +1,11 @@
# change owner as root
alias cor="\
chown \
\"0:0\" \
"
# change owner as user
alias cou="\
chown \
\"1000:1000\" \
"

4
shell/alias/clear.sh Normal file
View file

@ -0,0 +1,4 @@
# clear terminal
alias c="\
clear \
"

5
shell/alias/cp.sh Normal file
View file

@ -0,0 +1,5 @@
# copy interactively
alias cpi="\
cp \
--interactive \
"

4
shell/alias/emacs.sh Normal file
View file

@ -0,0 +1,4 @@
# short
alias em="\
emacs \
"

3
shell/alias/evince.sh Normal file
View file

@ -0,0 +1,3 @@
alias ev="\
evince \
"

441
shell/alias/git.sh Normal file
View file

@ -0,0 +1,441 @@
# add to index
alias ga="\
git \
add \
"
# add all to index
alias gaa="\
git \
add \
--all \
"
# add parts to index
alias gap="\
git \
add \
--patch \
"
# create a branch
alias gb="\
git \
branch \
"
# delete a branch
alias gbd="\
git \
branch \
--delete \
"
# force a branch deletion
alias gbdf="\
git \
branch \
--delete \
--force \
"
# list branches
alias gbl="\
git \
branch \
--all \
--list \
--verbose \
--verbose \
"
# set the link to a remote branch from a local branch
alias gbsu="\
git \
branch \
--set-upstream-to \
"
# clone a remote repository
alias gc="\
git \
clone \
"
# clean untracked files
alias gcf="\
git \
clean \
-d \
--force \
"
# commit the index
alias gcm="\
git \
commit \
--message \
"
# redo the last commit with a different message
alias gcma="\
git \
commit \
--amend \
--message \
"
# make a root commit
alias gcme="\
git \
commit \
--allow-empty \
--allow-empty-message \
--message \"\" \
"
# commit the index and sign
alias gcms="\
git \
commit \
--gpg-sign \
--message \
"
# switch to a branch or checkout file(s) from a commit
alias gco="\
git \
checkout \
"
# checkout an orphan branch
alias gcoo="\
git \
checkout \
--orphan \
"
# pick a commit
alias gcp="\
git \
cherry-pick \
"
# abort the commit pick
alias gcpa="\
git \
cherry-pick \
--abort \
"
# continue the commit pick
alias gcpc="\
git \
cherry-pick \
--continue \
"
# configure the user name
alias gcun="\
git \
config \
user.name \
"
# configure the user email
alias gcue="\
git \
config \
user.email \
"
# differences from last or between commits
alias gd="\
git \
diff \
"
# display what is indexed in cache
alias gdc="\
git \
diff \
--cached \
"
# indexed character-level differences
alias gdcw="\
git \
diff \
--cached \
--word-diff-regex=. \
"
# differences via external tool
alias gdt="\
git \
difftool \
--dir-diff \
"
# character-level differences
alias gdw="\
git \
diff \
--word-diff-regex=. \
"
# fetch from the remote repository
alias gf="\
git \
fetch \
--verbose \
--tags \
"
# fetch from remote repository and prune local orphan branches
alias gfp="\
git \
fetch \
--verbose \
--tags \
--prune \
"
# garbage collect all orphan commits
alias ggc="\
git \
reflog \
expire \
--all \
--expire \"all\" \
; \
git \
gc \
--aggressive \
--prune=\"now\" \
"
# initialize a new repository
alias gi="\
git \
init \
"
# initialize a new bare repository
alias gib="\
git \
init \
--bare \
"
# log commits history
alias gl="\
git \
log \
--all \
--graph \
--format=\"%C(auto)%h%d %C(red)%ai%C(auto) %an%n%B\" \
"
# log medium information
alias glm="\
git \
log \
--all \
--decorate \
--graph \
--pretty=medium \
"
# log commits history with patches
alias glp="\
git \
log \
--all \
--graph \
--format=\"%C(auto)%h%d %C(red)%ai%C(auto) %an%n%B\" \
--patch \
"
# abort the current merge commit
alias gma="\
git \
merge \
--abort \
"
# do a merge commit
alias gmc="\
git \
merge \
--no-ff \
--message \
"
# do a signed merge commit
alias gmcs="\
git \
merge \
--no-ff \
--gpg-sign \
-m \
"
# fast-forward to remote branch
alias gmf="\
git \
merge \
--ff-only \
"
# squash a branch and index its modifications
alias gms="\
git \
merge \
--squash \
"
# merge via external tool
alias gmt="\
git \
mergetool \
"
# push to the remote repository
alias gp="\
git \
push \
--verbose \
--tags \
"
# delete from the remote repository
alias gpd="\
git \
push \
--verbose \
--delete \
"
# force the push to the remote repository
alias gpf="\
git \
push \
--verbose \
--tags \
--force \
"
# rebase current branch onto another
alias grb="\
git \
rebase \
"
# abort current rebase
alias grba="\
git \
rebase \
--abort \
"
# continue current rebase
alias grbc="\
git \
rebase \
--continue \
"
# force rebase without fast-forward
alias grbf="\
git \
rebase \
--force-rebase \
"
# rebase interactively
alias grbi="\
git \
rebase \
--interactive \
"
# remove and add removal to index
alias grm="\
git \
rm \
"
# add a new remote repository
alias grma="\
git \
remote \
add \
"
# list remote repositories
alias grml="\
git \
remote \
--verbose \
"
# show a connection to a repository
alias grms="\
git \
remote \
show \
"
# set the location of the remote repository
alias grmsu="\
git \
remote \
set-url \
"
# remove file(s) from index or move current branch pointer
alias grs="\
git \
reset \
"
# wipe modifications or reset current branch to another commit
alias grsh="\
git \
reset \
--hard \
"
# current state of repository
alias gs="\
git \
status \
--untracked-files=all \
"
# show a commit
alias gsc="\
git \
show \
"
# tag a commit
alias gt="\
git \
tag \
"
# delete a tag
alias gtd="\
git \
tag \
--delete \
"
# tag a commit and sign
alias gts="\
git \
tag \
--sign \
"

12
shell/alias/gpg.sh Normal file
View file

@ -0,0 +1,12 @@
# turn gpg agent off
alias gak="\
gpgconf \
--kill \"gpg-agent\" \
"
# bind gpg agent to current tty
alias gau="\
gpg-connect-agent \
updatestartuptty \
/bye \
"

7
shell/alias/grep.sh Normal file
View file

@ -0,0 +1,7 @@
# grep from current directory with regex
alias g="\
grep \
--directories \"recurse\" \
--line-number \
--regexp \
"

10
shell/alias/kill.sh Normal file
View file

@ -0,0 +1,10 @@
# kill a process by id
alias k="\
kill \
"
# force kill a process by id
alias kf="\
kill \
-9 \
"

10
shell/alias/killall.sh Normal file
View file

@ -0,0 +1,10 @@
# kill all instances of a process by name
alias ka="\
killall \
"
# force kill all instances of a process by name
alias kaf="\
killall \
-9 \
"

13
shell/alias/ls.sh Normal file
View file

@ -0,0 +1,13 @@
export LS_COLORS="\
di=0;94\
"
# list current directory’s entries
alias l="\
ls \
--all \
--color \
-l \
-p \
--time-style \"+%Y%m%d-%H%M%S%-:::z\" \
"

12
shell/alias/lsblk.sh Normal file
View file

@ -0,0 +1,12 @@
# list block devices
alias lb="\
lsblk \
--output \"NAME,SIZE,TYPE,FSTYPE,LABEL,MOUNTPOINTS\" \
--noempty \
"
# list block devices (old)
alias lbo="\
lsblk \
--output \"NAME,SIZE,TYPE,FSTYPE,LABEL,MOUNTPOINT\" \
"

3
shell/alias/micro.sh Normal file
View file

@ -0,0 +1,3 @@
alias µ="\
micro \
"

10
shell/alias/mkdir.sh Normal file
View file

@ -0,0 +1,10 @@
# make a directory
alias md="\
mkdir \
"
# make a directory after making its parents
alias mdp="\
mkdir \
--parents \
"

10
shell/alias/mount.sh Normal file
View file

@ -0,0 +1,10 @@
alias m="\
mount \
"
# remount read-only medium in read-write
alias remount="\
mount \
-o \"remount,rw\" \
\"/usr/lib/live/mount/medium\" \
"

5
shell/alias/mv.sh Normal file
View file

@ -0,0 +1,5 @@
# move interactively
alias mvi="\
mv \
--interactive \
"

3
shell/alias/nano.sh Normal file
View file

@ -0,0 +1,3 @@
alias n="\
nano \
"

3
shell/alias/newsboat.sh Normal file
View file

@ -0,0 +1,3 @@
alias nb="\
newsboat \
"

View file

@ -0,0 +1,12 @@
# list otp accounts
alias otpl="\
otpclient-cli \
list \
"
# display otp code
alias otps="\
otpclient-cli \
show \
-a \
"

10
shell/alias/pass.sh Normal file
View file

@ -0,0 +1,10 @@
# display pass entry’s content
alias p="\
pass \
"
# copy passphrase into clipboard
alias pc="\
pass \
--clip \
"

7
shell/alias/ps.sh Normal file
View file

@ -0,0 +1,7 @@
# look for a string in processes names
alias pg="\
ps \
-A \
| \
grep \
"

16
shell/alias/pwgen.sh Normal file
View file

@ -0,0 +1,16 @@
# generate passwords
alias pwg="\
pwgen \
-1 \
--num-passwords 1048576 \
--secure \
"
# generate passwords with symbols
alias pwgs="\
pwgen \
-1 \
--num-passwords 1048576 \
--secure \
--symbols \
"

29
shell/alias/rsync.sh Normal file
View file

@ -0,0 +1,29 @@
# synchronize
alias rs="\
rsync \
--archive \
--partial \
--progress \
--verbose \
--no-inc-recursive \
"
# synchronize and delete after
alias rsda="\
rsync \
--archive \
--partial \
--progress \
--verbose \
--delete-after \
"
# synchronize and delete before
alias rsdb="\
rsync \
--archive \
--partial \
--progress \
--verbose \
--delete-before \
"

21
shell/alias/tar.sh Normal file
View file

@ -0,0 +1,21 @@
alias tc="\
tar \
--verbose \
--create \
--auto-compress \
--file \
"
alias tl="\
tar \
--verbose \
--list \
--file \
"
alias tx="\
tar \
--verbose \
--extract \
--file \
"

8
shell/alias/tree.sh Normal file
View file

@ -0,0 +1,8 @@
alias t="\
tree \
"
alias ta="\
tree \
-a \
"

40
shell/apt.sh Normal file
View file

@ -0,0 +1,40 @@
apt_clean() {
apt-get \
clean
}
apt_install_backports() {
apt_install_target "${DEBIAN_CODENAME}-backports" "${@}"
}
apt_install_release() {
apt_install_target "${DEBIAN_CODENAME}" "${@}"
}
apt_install_target() {
local target="${1}"
shift
local package
for package in "${@}"; do
log_info
log_info "${package}${target}"
apt-get \
install \
--assume-yes \
--target-release "${target}" \
"${package}"
apt_clean
done
}
apt_update() {
apt-get \
update
}
apt_upgrade() {
apt-get \
upgrade \
--assume-yes
apt_clean
}

5
shell/bash/completion.sh Normal file
View file

@ -0,0 +1,5 @@
file="/usr/share/bash-completion/bash_completion"
if [ -f "${file}" ]; then
. "${file}"
fi

5
shell/bash/history.sh Normal file
View file

@ -0,0 +1,5 @@
HISTCONTROL="ignorespace"
HISTSIZE=-1
HISTTIMEFORMAT="%Y%m%d %H%M%S "

36
shell/bash/prompt.sh Normal file
View file

@ -0,0 +1,36 @@
ps1() {
local date host
local code="${1}"
date="$(date +%H:%M:%S)"
local git
host="$(hostname)"
local path="${PWD}"
local user="${USER}"
local view="└ "
if [ "${code}" -ne 0 ]; then
view="${view}\e[0;31m"
else
view="${view}\e[0;32m"
fi
view="${view}${code}\e[0m @ \e[0;33m${date}\e[0m"
if [ "$(type -t __git_ps1)" == "function" ]; then
git="$(__git_ps1)"
if [ -n "${git}" ]; then
view="${view} –\e[0;35m${git}\e[0m"
fi
fi
view="${view}\n\e[0;36m${path}\e[0m"
view="${view}\n┌ "
if [ ${EUID} -eq 0 ]; then
view="${view}\e[0;31m"
else
view="${view}\e[0;32m"
fi
view="${view}${user}\e[0m @ \e[0;33m${host}\e[0m"
echo -e "${view}\n${PS2}"
}
PS1="\$(ps1 \${?})"
PS2="\
"

7
shell/btrfs.sh Normal file
View file

@ -0,0 +1,7 @@
bsl() {
if [ -n "${1}" ]; then
btrfs subvolume list "${1}" |
cut --delimiter " " --fields 9 |
sort
fi
}

8
shell/debian.sh Normal file
View file

@ -0,0 +1,8 @@
DEBIAN_CODENAME="$(
grep "VERSION_CODENAME" "/etc/os-release" |
cut --delimiter "=" --fields "2"
)"
debian_disable_frontend() {
export DEBIAN_FRONTEND="noninteractive"
}

121
shell/fs.sh Normal file
View file

@ -0,0 +1,121 @@
fs_make_btrfs() {
local device="${1}"
local label="${2}"
local uuid="${3}"
if [ -b "${device}" ]; then
set -- \
--force \
--checksum "sha256"
if [ -n "${label}" ]; then
set -- "${@}" \
--label "${label}"
fi
if [ -n "${uuid}" ]; then
set -- "${@}" \
--uuid "${uuid}"
fi
mkfs.btrfs "${@}" "${device}"
fi
}
fs_make_btrfs_swap() {
local path="${1}"
local size="${2}"
local uuid="${3}"
if [ -n "${path}" ]; then
set -- filesystem mkswapfile
if [ -n "${size}" ]; then
set -- "${@}" \
--size "${size}"
fi
if [ -n "${uuid}" ]; then
set -- "${@}" \
--uuid "${uuid}"
fi
btrfs "${@}" "${path}"
fi
}
fs_make_fat() {
local device="${1}"
local name="${2}"
local volid="${3}"
if [ -b "${device}" ]; then
set -- \
-F 32 \
-S 4096
if [ -n "${name}" ]; then
set -- "${@}" \
-n "${name}"
fi
if [ -n "${volid}" ]; then
set -- "${@}" \
-i "${volid}"
fi
mkfs.fat "${@}" "${device}"
fi
}
fs_raid_create() {
if [ -n "${4}" ]; then
local name="${1}"
local uuid="${2}"
shift 2
mdadm \
--create "/dev/md/${name}" \
--level 0 \
--metadata 1 \
--name "md:${name}" \
--raid-devices ${#} \
--uuid "${uuid}" \
"${@}"
fi
}
fs_wipe() {
local device="${1}"
local buffer="${2}"
local count="${3}"
if [ -b "${device}" ]; then
set -- \
status="progress" \
if="/dev/zero" \
of="${device}"
if [ -n "${buffer}" ]; then
set -- "${@}" \
bs="${buffer}"
fi
if [ -n "${count}" ]; then
set -- "${@}" \
count="${count}"
fi
dd "${@}"
fi
}
luks_format() {
local passphrase="${1}"
local device="${2}"
local label="${3}"
local uuid="${4}"
if [ -b "${device}" ]; then
set -- \
--batch-mode \
--cipher "aes-xts-plain64" \
--hash "sha512" \
--iter-time 4096 \
--key-size 512 \
--pbkdf "argon2id" \
--type "luks2" \
--use-random \
--verbose
if [ -n "${label}" ]; then
set -- "${@}" --label "${label}"
fi
if [ -n "${uuid}" ]; then
set -- "${@}" --uuid "${uuid}"
fi
echo "${passphrase}" |
cryptsetup "${@}" luksFormat "${device}"
fi
}

12
shell/gpg.sh Normal file
View file

@ -0,0 +1,12 @@
gpg_ssh() {
local user_id
user_id=$(id --user)
if [ "${user_id}" -ne 0 ]; then
if [ -f "${HOME}/.gnupg/gpg-agent.conf" ]; then
SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
export SSH_AUTH_SOCK
fi
fi
}
gpg_ssh

15
shell/gsettings.sh Normal file
View file

@ -0,0 +1,15 @@
ws() {
local bool
local group="org.gnome.mutter"
local name="workspaces-only-on-primary"
local var="${group}/${name}"
# get
bool="$(gsettings get "${group}" "${name}")"
log_debug "${var}: ${bool}"
# not
bool="$(not "${bool}")"
log_debug "bool: ${bool}"
# set
gsettings set "${group}" "${name}" "${bool}"
log_info "${var}: ${bool}"
}

44
shell/log.sh Normal file
View file

@ -0,0 +1,44 @@
LOG_LEVEL_FATAL=0
LOG_LEVEL_ERROR=1
LOG_LEVEL_WARN=2
LOG_LEVEL_INFO=3
LOG_LEVEL_DEBUG=4
LOG_LEVEL_TRACE=5
LOG_LEVEL=${LOG_LEVEL_INFO}
log_debug() {
if [ "${LOG_LEVEL}" -ge "${LOG_LEVEL_DEBUG}" ]; then
echo "[DEBUG]" "${@}"
fi
}
log_error() {
if [ "${LOG_LEVEL}" -ge "${LOG_LEVEL_ERROR}" ]; then
echo "[ERROR]" "${@}"
fi
}
log_fatal() {
if [ "${LOG_LEVEL}" -ge "${LOG_LEVEL_FATAL}" ]; then
echo "[FATAL]" "${@}"
fi
}
log_info() {
if [ "${LOG_LEVEL}" -ge "${LOG_LEVEL_INFO}" ]; then
echo "${@}"
fi
}
log_trace() {
if [ "${LOG_LEVEL}" -ge "${LOG_LEVEL_TRACE}" ]; then
echo "[TRACE]" "${@}"
fi
}
log_warn() {
if [ "${LOG_LEVEL}" -ge "${LOG_LEVEL_WARN}" ]; then
echo " [WARN]" "${@}"
fi
}

44
shell/main.sh Normal file
View file

@ -0,0 +1,44 @@
main_env_root() {
dirname "${ENV}"
}
main_link_bashrc() {
local file="/etc/bash.bashrc"
rm --force "${file}"
ln --symbolic "${MAIN_USERS_FILE}" "${file}"
}
# import modules
main_import_modules() {
local file="${1}"
if [ -f "${file}" ]; then
local count ifs module modules path root
path="$(realpath --canonicalize-existing "${file}")"
root="$(dirname "${path}")"
modules="$(find "${root}" -type "f" -name "*.sh" -printf "%P
" | sort)"
ifs="${IFS}"
IFS="
"
count=0
echo
echo ". ${root}"
for module in ${modules}; do
count=$((count + 1))
printf "%02d" "${count}"
echo " ${module%.sh}"
module="${root}/${module}"
if [ "${module}" != "${path}" ]; then
. "${module}"
fi
done
IFS="${ifs}"
return 0
else
log_fatal "No file: ${file}"
return 1
fi
}
# import modules
main_import_modules "${ENV}"

31
shell/mount-lxc.sh Normal file
View file

@ -0,0 +1,31 @@
mrc() {
local container="${1}"
local f
for f in "dev" "dev/pts" "proc" "sys"; do
mount --bind "/${f}" "overlay/mount/var/lib/lxc/${container}/squashfs-root/${f}"
done
}
crc() {
local container="${1}"
shift
chroot "overlay/mount/var/lib/lxc/${container}/squashfs-root" "${@}"
}
urc() {
local container="${1}"
local f
for f in "sys" "proc" "dev/pts" "dev"; do
umount --lazy "overlay/mount/var/lib/lxc/${container}/squashfs-root/${f}"
done
}
mmc() {
local container="${1}"
mount --bind "/deb" "overlay/mount/var/lib/lxc/${container}/squashfs-root/deb"
}
umc() {
local container="${1}"
umount "overlay/mount/var/lib/lxc/${container}/squashfs-root/deb"
}

83
shell/mount.sh Normal file
View file

@ -0,0 +1,83 @@
mo() {
local directory="${1}"
local file
if [ -n "${directory}" ]; then
directory="$(realpath "${directory}")"
file="${directory}/filesystem.squashfs"
if mkdir "overlay"; then
cd "overlay"
mkdir {lower,upper,work,mount}
if mount "${file}" "lower"; then
mount \
-o lowerdir="lower",upperdir="upper",workdir="work" \
-t "overlay" \
"overlay" "mount"
fi
cd ..
fi
else
echo "KO: directory?"
fi
}
uo() {
cd "overlay"
if umount "mount"; then
rmdir "mount"
rm --recursive "upper" "work"
if umount "lower"; then
rmdir "lower"
fi
fi
cd ..
rmdir "overlay"
}
mr() {
local f
for f in "dev" "dev/pts" "proc" "sys"; do
mount --bind "/${f}" "overlay/mount/${f}"
done
}
alias cr="\
chroot \
\"overlay/mount\" \
"
alias cru="\
chroot \
--userspec \"1000:1000\" \
\"overlay/mount\" \
"
ur() {
local f
for f in "sys" "proc" "dev/pts" "dev"; do
umount --lazy "overlay/mount/${f}"
done
}
mm() {
mount --make-rslave --rbind "/deb" "overlay/mount/deb"
}
um() {
umount --recursive "overlay/mount/deb"
}
ms() {
local directory="${1}"
local level="${2}"
if [ -n "${directory}" ]; then
if mkdir "${directory}"; then
[ -n "${level}" ] || level="18"
cp overlay/mount/{vmlinuz,initrd.img} "${directory}"
mksquashfs \
"overlay/mount" "${directory}/filesystem.squashfs" \
-noappend \
-comp "zstd" -Xcompression-level "${level}"
chown --recursive 1000:1000 "${directory}"
fi
fi
}

8
shell/proxy.sh Normal file
View file

@ -0,0 +1,8 @@
socks() {
local value
case "${1}" in
"on") value="manual" ;;
*) value="none" ;;
esac
gsettings set "org.gnome.system.proxy" "mode" "${value}"
}

113
shell/rescue/common.sh Normal file
View file

@ -0,0 +1,113 @@
rescue_configure() {
local hostname="${1}"
# apt / conf
printf "\
Acquire::AllowInsecureRepositories False;
Acquire::AllowWeakRepositories False;
Acquire::AllowDowngradeToInsecureRepositories False;
Acquire::Check-Valid-Until True;
APT::Install-Recommends False;
APT::Install-Suggests False;
APT::Get::Show-Versions True;
Dir::Etc::SourceParts \"\";
Dpkg::Progress True;
" >"/etc/apt/apt.conf.d/apt.conf"
# apt / sources
printf "%s" "\
deb https://deb.debian.org/debian \
${DEBIAN_CODENAME} main non-free-firmware contrib non-free
deb https://deb.debian.org/debian \
${DEBIAN_CODENAME}-backports main non-free-firmware contrib non-free
deb https://deb.debian.org/debian \
${DEBIAN_CODENAME}-updates main non-free-firmware contrib non-free
deb https://deb.debian.org/debian-security \
${DEBIAN_CODENAME}-security main non-free-firmware contrib non-free
" >"/etc/apt/sources.list"
# bash / rc
main_link_bashrc
mv .bashrc .bashrc.old
# host name
hostname "${hostname}"
# locales
printf "\
en_US.UTF-8 UTF-8
fr_FR.UTF-8 UTF-8
" >"/etc/locale.gen"
# generate locales
locale-gen
# update catalog
apt_update
# disable frontend
debian_disable_frontend
# install backports
apt_install_backports "tmux"
# install packages
apt_install_release "apt-file" "mosh" "screen" "byobu"
# update catalog
apt_update
}
rescue_install() {
# update catalog
apt_update
# disable frontend
debian_disable_frontend
# upgrade packages
apt_upgrade
# install packages
apt_install_release \
"man-db" \
"dmidecode" "efibootmgr" "lshw" "pciutils" "usbutils" \
"parted" "mdadm" "cryptsetup-bin" "lvm2" \
"btrfs-progs" "dosfstools" "duperemove" "squashfs-tools" \
"git" "micro" "nano" "python3" "rsync" "vim" \
"exa" "lf" "ncdu" "nnn" "ranger" "tree" \
"file" "htop" "iotop" "ipcalc" "libdigest-sha3-perl" "lsof"
# install backports
apt_install_backports \
"grub-pc-bin" \
\
"grub-efi-amd64-bin"
}
rescue_upload() {
local host="${1}"
local hostname="${2}"
if [ -n "${hostname}" ]; then
local user="root"
#
local user_host="${user}@${host}"
# remove fingerprints
ssh-keygen -R "${host}"
# copy ssh id
ssh-copy-id \
-o "StrictHostKeyChecking=accept-new" \
"${user_host}"
# upload root
rsync --delete --recursive \
"$(main_env_root)" "${user_host}:/etc"
# call setup
# TODO variable
ssh "${user_host}" -- "\
. \"/etc/bash/main.sh\" ; rescue_configure \"${hostname}\""
# create session
ssh "${user_host}" -- byobu new-session -d
# send keys
ssh "${user_host}" -- byobu send-keys "rescue_install" "C-m"
# attach session
mosh "${user_host}" -- byobu attach-session
else
echo "host & hostname"
return 1
fi
}
rescue_wipe_1_zero() {
fs_wipe "/dev/mapper/crypt" "512M"
}
rescue_wipe_3_close() {
umount "/media/boot"
umount "/media/crypt" &&
cryptsetup luksClose "crypt"
}

127
shell/rescue/hetzner.sh Normal file
View file

@ -0,0 +1,127 @@
rescue_wipe_0_init_hetzner_8_8() {
local device
set \
"/dev/sda" \
"/dev/sdb"
local members
local number
local passphrase
# read passphrase
passphrase="$(read_passphrase)"
#
lsblk
echo -n "WIPE" "${@}" "/?\\ OR CANCEL /!\\"
read -r
#
number=0
for device in "${@}"; do
number=$((number + 1))
echo
echo "#${number}: ${device}"
#
parted --script "${device}" \
mktable gpt \
unit "mib" \
mkpart "crypt-${number}" 33282 7630885 \
mkpart "boot-${number}" 514 33282 \
mkpart "esp-${number}" 2 514 \
set 3 esp on \
mkpart "bios-${number}" 1 2 \
set 4 bios_grub on
done
#
number=0
for device in "${@}"; do
number=$((number + 1))
echo
echo "#${number}: ${device}4"
# wipe bios
fs_wipe "${device}4"
done
#
number=0
for device in "${@}"; do
number=$((number + 1))
echo
echo "#${number}: ${device}3"
# format esp
fs_wipe "${device}3" "1M"
fs_make_fat "${device}3" "esp-${number}" "0000000${number}"
# mount esp
mkdir --parents "/media/esp/${number}"
mount "${device}3" "/media/esp/${number}"
done
#
number=0
for device in "${@}"; do
number=$((number + 1))
echo
echo "#${number}: ${device}2"
# wipe boot
fs_wipe "${device}2" "1G" 1
done
#
members=()
for device in "${@}"; do
members+=("${device}2")
done
fs_raid_create \
"boot" "00000000:00000000:00000000:00000002" "${members[@]}"
#
fs_make_btrfs "/dev/md/boot" "boot" \
"00000000-0000-0000-0000-00000000000b"
# mount boot
mkdir --parents "/media/boot"
mount \
--options "autodefrag,compress-force=zstd" \
"/dev/md/boot" "/media/boot"
#
number=0
for device in "${@}"; do
number=$((number + 1))
echo
echo "#${number}: ${device}1"
# wipe crypt head
fs_wipe "${device}1" "1G" 1
done
#
members=()
for device in "${@}"; do
members+=("${device}1")
done
fs_raid_create \
"crypt" "00000000:00000000:00000000:00000001" "${members[@]}"
# encrypt
luks_format "${passphrase}" "/dev/md/crypt"
# open
echo "${passphrase}" |
cryptsetup luksOpen "/dev/md/crypt" "crypt"
# passphrase
unset passphrase
}
rescue_wipe_2_make_hetzner_8_8() {
local passphrase
# close
cryptsetup luksClose "crypt"
# read passphrase
passphrase="$(read_passphrase)"
# encrypt
luks_format "${passphrase}" "/dev/md/crypt"
# open
echo "${passphrase}" |
cryptsetup luksOpen "/dev/md/crypt" "crypt"
# passphrase
unset passphrase
# format crypt
fs_make_btrfs "/dev/mapper/crypt" "crypt" \
"00000000-0000-0000-0000-00000000000c"
# mount crypt
mkdir --parents "/media/crypt"
mount \
--options "autodefrag,compress-force=zstd" \
"/dev/mapper/crypt" "/media/crypt"
# make swap file
fs_make_btrfs_swap "/media/crypt/swap" "64g" \
"00000000-0000-0000-0000-000000000005"
}

73
shell/rescue/ovh.sh Normal file
View file

@ -0,0 +1,73 @@
rescue_wipe_0_init_ovh_vle2() {
local device="/dev/sdb"
local passphrase
# read passphrase
passphrase="$(read_passphrase)"
# warn
lsblk
printf "%s" "WIPE ${device} /?\\ OR CANCEL /!\\"
read -r
#
parted --script "${device}" \
mktable gpt \
unit "mib" \
mkpart "crypt" 4610 40959 \
mkpart "boot" 514 4610 \
mkpart "esp" 2 514 \
set 3 esp on \
mkpart bios 1 2 \
set 4 bios_grub on
# bios / wipe
fs_wipe "${device}4"
# esp / wipe
fs_wipe "${device}3" "1M"
# esp / format
fs_make_fat "${device}3" "esp" "00000001"
# esp / mount
mkdir --parents "/media/esp"
mount "${device}3" "/media/esp"
# boot / wipe
fs_wipe "${device}2" "1G" 1
# boot / format
fs_make_btrfs "${device}2" "boot" \
"00000000-0000-0000-0000-00000000000b"
# boot / mount
mkdir --parents "/media/boot"
mount --options "autodefrag,compress-force=zstd" \
"${device}2" "/media/boot"
# crypt / wipe
fs_wipe "${device}1" "1G" 1
# crypt / encrypt
luks_format "${passphrase}" "${device}1"
# crypt / open
echo "${passphrase}" |
cryptsetup luksOpen "${device}1" "crypt"
# passphrase
unset passphrase
}
rescue_wipe_2_make_ovh_vle2() {
local device="/dev/sdb"
local passphrase
# crypt / close
cryptsetup luksClose "crypt"
# read passphrase
passphrase="$(read_passphrase)"
# crypt / encrypt
luks_format "${passphrase}" "${device}1"
# crypt / open
echo "${passphrase}" |
cryptsetup luksOpen "${device}1" "crypt"
# passphrase
unset passphrase
# crypt / format
fs_make_btrfs "/dev/mapper/crypt" "crypt" \
"00000000-0000-0000-0000-00000000000c"
# crypt / mount
mkdir --parents "/media/crypt"
mount --options "autodefrag,compress-force=zstd" \
"/dev/mapper/crypt" "/media/crypt"
# crypt / swap
fs_make_btrfs_swap "/media/crypt/swap" "4g" \
"00000000-0000-0000-0000-000000000005"
}

23
shell/util.sh Normal file
View file

@ -0,0 +1,23 @@
not() {
case "${1}" in
"false") echo "true" ;;
"true") echo "false" ;;
*) ;;
esac
}
read_passphrase() {
read_secret "PassPhrase: "
}
read_secret() {
local prompt="${1}"
local secret
printf "%s" "${prompt}" 1>&2
stty -echo
read -r secret
stty echo
echo >&2
echo "${secret}"
unset secret
}