Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

distro post-install #11

Draft
wants to merge 32 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0e25c1b
Create `setup-env`
Rudxain May 16, 2024
eb23044
explain `setup-env`
Rudxain May 16, 2024
63b19fe
exclude `setup-env` in `install`
Rudxain May 16, 2024
af14f57
exclude `setup-env` in min-deps
Rudxain May 16, 2024
f712f43
Create `etc_path.sh`
Rudxain May 16, 2024
af18e28
rm Android bin in `.sh/path`
Rudxain May 16, 2024
25cf93b
avoid assigning to `PREFIX` in `etc_path.sh`
Rudxain May 16, 2024
f19c3bb
forgor 💀
Rudxain May 16, 2024
5ffdeea
setup moves etc_path.sh to profile.d
Rudxain May 16, 2024
c338c5f
Rename setup-env to setup-distro/main
Rudxain May 16, 2024
1d8e315
Rename etc_path.sh to setup-distro/path.sh
Rudxain May 16, 2024
a8b1960
Update setup
Rudxain May 16, 2024
ecafad6
setup shouldn't be explained in root `README`
Rudxain May 16, 2024
16915ab
Create README.md for setup
Rudxain May 16, 2024
f2632a7
exclude `setup-distro` on `install` & min-deps
May 16, 2024
f085a06
fix perms
May 16, 2024
6baf52a
add purge-retro. warn about non-idemp
May 16, 2024
8318df3
Create Enable_AppArmor
Rudxain May 25, 2024
165add9
enable AA end main
Rudxain May 25, 2024
511a356
Create `dpkg-list-essential`
Rudxain May 25, 2024
e996b3a
use local ls-essential
Rudxain May 25, 2024
439653c
Create `apt-autopurge-busybox-dupes`
Rudxain May 25, 2024
04a58c7
add Helix system-wide updater
Rudxain May 30, 2024
fb80325
rename setup dir
Jun 10, 2024
032bcb1
add `apt` & `nft` config
Jun 10, 2024
445a643
add `apt` & `nft` config
Jun 10, 2024
2e42085
`update` is now only useful for admin
Jun 14, 2024
b8a5ee3
`update` is now only useful for admin
Jun 14, 2024
7d33307
add `dpkg-list-sizes`
Jun 29, 2024
d3f1c02
improve `main` post-install, enable FF touch
Jul 1, 2024
1c153de
FF `XINPUT` no longer needed
Rudxain Oct 26, 2024
ce0f148
`hx` should be fetched using GH API
Rudxain Oct 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .sh/path
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#!/bin/sh
# Android
if [ -d /system/bin ]; then
PATH="$PATH:/system/bin"
fi

if [ -d "$HOME/bin" ]; then
PATH="$HOME/bin:$PATH"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ Non-Termux:
```sh
cd
curl -#L https://github.com/Rudxain/dotfiles/tarball/main | \
tar -xzv --strip-components 1 --exclude={.termux,bin/termux-\*,.gitattributes,install,README.md,LICENSE} \
tar -xzv --strip-components 1 --exclude={.termux,bin/termux-\*,.gitattributes,setup-distro,install,README.md,LICENSE} \
&& . .profile
```

Termux:
```sh
cd
curl -#L https://github.com/Rudxain/dotfiles/tarball/main | \
tar -xzv --strip-components 1 --exclude={.gitattributes,install,README.md,LICENSE} \
tar -xzv --strip-components 1 --exclude={.gitattributes,setup-distro,install,README.md,LICENSE} \
&& . .profile
```

Expand Down
Empty file modified bin/termux-url-opener
100644 → 100755
Empty file.
38 changes: 0 additions & 38 deletions bin/update

This file was deleted.

3 changes: 2 additions & 1 deletion install
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ do_it() {
rsync \
--exclude '.git/' \
--exclude '.gitattributes' \
--exclude 'bootstrap.sh' \
--exclude 'setup-distro' \
--exclude 'install' \
--exclude 'README.md' \
--exclude 'LICENSE' \
-avh --no-perms . ~
Expand Down
9 changes: 9 additions & 0 deletions post-install/Enable_AppArmor
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
set -euf
# https://wiki.debian.org/AppArmor/HowToUse#Enable_AppArmor
sudo mkdir -p /etc/default/grub.d
echo 'GRUB_CMDLINE_LINUX_DEFAULT="$GRUB_CMDLINE_LINUX_DEFAULT apparmor=1 security=apparmor"' \
| sudo tee /etc/default/grub.d/apparmor.cfg
sudo update-grub
# user should choose when to do so
#sudo reboot
9 changes: 9 additions & 0 deletions post-install/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
This sub-repo isn't necessary, but if you're setting-up a clean install of a Debian-based distro it'll be very convenient.

I'm considering switching to NixOS, to make this process seamless.

> [!warning]
> `main` isn't idempotent!
> You should only run it once.
>
> I'm considering to make it idempotent by default, with an opt-in flag to use old behavior
23 changes: 23 additions & 0 deletions post-install/apt-autopurge-busybox-dupes
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
set -euf -o pipefail
# https://wiki.debian.org/ReduceDebian#Use_busybox_built-ins_instead_of_full_packages

# auto-marks packs that installed same cmds as busybox subcmds, then autopurges

# to-do:
# filter cmds that belong to "Essential" & "Required" packs,
# for optimization.
readonly bb="$(busybox --list)"

readonly c="$(wc -l <<< "$bb")"
i=0
for cmd in $bb
do
echo "$i / $c"
if pack="$(dpkg -S "$(type -P "$cmd")" 2> /dev/null)"
then
apt-mark auto "$(cut -d: -f1 <<< "$pack")" > /dev/null
fi
((i++))
done
apt -y autopurge
2 changes: 2 additions & 0 deletions post-install/apt-purge-retro
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
apt-get purge $(dpkg -l | grep \^rc | awk '{print $2}')
3 changes: 3 additions & 0 deletions post-install/apt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
APT::Install-Recommends "0";
APT::Install-Suggests "0";
APT::AutoRemove::SuggestsImportant "0";
6 changes: 6 additions & 0 deletions post-install/dpkg-list-essential
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
set -euf

dpkg-query -Wf '${Package;-40}${Essential}\n' \
| grep yes \
| awk '{print $1}'
8 changes: 8 additions & 0 deletions post-install/dpkg-list-sizes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
set -euf

n="${1-16}"

dpkg-query -Wf '${Installed-size}\t${Package}\n' |
sort -rn |
head "-n$((n))"
44 changes: 44 additions & 0 deletions post-install/main
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
set -euf -o pipefail

readonly HELP='$1 must be a path to a file
that contains old output from:
`apt-mark showmanual`
'

if [[ $# -lt 1 ]]
then
printf '%s' "$HELP"
exit 1
fi
readonly pack_ls="$(cat -- "$1")"

# to reduce time between auto-marking & installing,
# we must config now
cp apt.conf "${PREFIX:-}/etc/apt/apt.conf"
# Termux compatibility

# cleanup
apt-mark auto \*

apt-get update

# mark manual if existent.
# "--" for extra safety
apt-get -y install -- $pack_ls

apt-mark auto $(./dpkg-list-essential)
# more cleanup, just-in-case
apt-mark minimize-manual

apt autopurge

apt-get -y upgrade

mv path.sh "${PREFIX:-}/etc/profile.d/"

mv apt-purge-retro "${PREFIX:-/usr}/local/bin/"
chown root:root apt-purge-retro
chmod 755 "${PREFIX:-/usr}/local/bin/"*

./Enable_AppArmor
20 changes: 20 additions & 0 deletions post-install/nftables.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/sbin/nft -f

flush ruleset

table inet filter {
# 9 December 2021, at 00:51
# https://wiki.nftables.org/wiki-nftables/index.php/Simple_ruleset_for_a_workstation#fw.inet.basic
chain input {
type filter hook input priority 0; policy drop;
iif lo accept
ct state established,related accept
icmpv6 type { nd-neighbor-solicit, nd-router-advert, nd-neighbor-advert } accept
}
chain forward {
type filter hook forward priority filter;
}
chain output {
type filter hook output priority filter;
}
}
12 changes: 12 additions & 0 deletions post-install/path.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

# Android
if [ -d /system/bin ]; then
PATH="$PATH:/system/bin"
fi

if [ -d "${PREFIX:-/usr}/local/bin" ]; then
PATH="$PATH:${PREFIX:-/usr}/local/bin"
fi

export PATH
24 changes: 24 additions & 0 deletions post-install/update-hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
#shellcheck disable=2317
set -euf -o pipefail

# to-do: use official GH API rather than scraping
readonly RELEASE_URL='https://github.com/helix-editor/helix/releases/'
wget "${RELEASE_URL}latest" -O - | \
grep -E 'download/\d+\.\d+/helix-\d+\.\d+-x86_64\.AppImage'
#to-do check version before download

exit 0

readonly ROOT_URL='https://raw.githubusercontent.com/helix-editor/helix/master/'
readonly ROOT_DIR='/usr/share/'
readonly ICO="${ROOT_DIR}icons/"

wget "${ROOT_URL}contrib/helix.png" -P "$ICO"
wget "${ROOT_URL}logo.svg" -O "${ICO}helix.svg"
unset ICO

wget "${ROOT_URL}contrib/Helix.desktop" -P "${ROOT_DIR}applications" || true

wget "${ROOT_URL}contrib/completion/hx.bash" -P '/etc/bash_completion.d' || true

21 changes: 21 additions & 0 deletions post-install/update-packs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh
set -uf

if [ -n "${TERMUX_VERSION:-}" ]; then
# https://wiki.termux.com/wiki/Package_Management
if pkg upgrade; then
# I'm aware of the consequences
pkg autoclean
apt-get autopurge

npm update -g # for LSPs
fi
else
if apt-get update && apt-get upgrade
then
apt-get autoclean
apt-get autopurge

npm update -g # for LSPs
fi
fi