--- Prompt Section (collect all user input here) ---
Disk Selection
echo "Available disks:"
lsblk -d -o NAME,SIZE,MODEL
while true; do
read -p "Enter Disk (e.g. sda, nvme0n1): " disk_input
disk="/dev/{disk_input%/}"
if [ ! -b "disk" ]; then
echo "Disk $disk does not exist. Try again."
continue
fi
break
done
Hostname
while true; do
read -p "Hostname: " hostname
[[ -z "$hostname" ]] && echo "Hostname cannot be empty." && continue
break
done
Root Password
while true; do
read -s -p "Root password: " root_password
echo
read -s -p "Confirm root password: " root_password2
echo
[[ "rootpassword"!="root_password2" ]] && echo "Passwords do not match." && continue
[[ -z "$root_password" ]] && echo "Password cannot be empty." && continue
break
done
Username
while true; do
read -p "Username: " user
[[ -z "$user" ]] && echo "Username cannot be empty." && continue
break
done
User Password
while true; do
read -s -p "User password: " user_password
echo
read -s -p "Confirm user password: " user_password2
echo
[[ "userpassword"!="user_password2" ]] && echo "Passwords do not match." && continue
[[ -z "$user_password" ]] && echo "Password cannot be empty." && continue
break
done
Export variables for later use
export disk hostname root_password user user_password
Partition Naming
if [[ "disk"==∗nvme∗]];thenpart1="{disk}p1"
part2="{disk}1"
part2="${disk}2"
fi
mount -o noatime,compress=lzo,ssd,space_cache=v2,discard=async,subvol=@ "part2" /mnt/home
mount -o noatime,compress=lzo,ssd,space_cache=v2,discard=async,subvol=@var "part2" /mnt/.snapshots
You are trying to create a subvolume named .snapshotsinside the @ subvolume. But the directory /mnt/@/ is a subvolume, and it does not exist as a traditional directory on the container filesystem until you mount it. The command tries to create a subvolume /mnt/@/.snapshots on the top-level mount point, which doesn't make sense.
Explanation:
The command btrfs subvolume create expects a path to a directory on a mounted subvolume or the filesystem root.
At this point /mnt/@ is not mounted — it is just a directory on /mnt (which is the mountpoint of your btrfs partition and the root subvolume).
You cannot create a subvolume inside another subvolume unless that subvolume is mounted.
How to fix this?
Create the top-level subvolumes (@, @home, @var, @.snapshots) all at the root level (i.e., inside /mnt), not nested.
check for possible errors and recommed some stuff -
install.sh -
#!/bin/bash
set -euo pipefail
--- Prompt Section (collect all user input here) ---
Disk Selection
echo "Available disks:"
lsblk -d -o NAME,SIZE,MODEL
while true; do
read -p "Enter Disk (e.g. sda, nvme0n1): " disk_input
disk="/dev/{disk_input%/}"
if [ ! -b "disk" ]; then
echo "Disk $disk does not exist. Try again."
continue
fi
break
done
Hostname
while true; do
read -p "Hostname: " hostname
[[ -z "$hostname" ]] && echo "Hostname cannot be empty." && continue
break
done
Root Password
while true; do
read -s -p "Root password: " root_password
echo
read -s -p "Confirm root password: " root_password2
echo
[[ "rootpassword"!=root_password2" ]] && echo "Passwords do not match." && continue
[[ -z "$root_password" ]] && echo "Password cannot be empty." && continue
break
done
Assistant
Your installation setup overall looks quite thorough and well structured. Below are some possible errors, issues, and recommendations for your install.sh, chroot.sh, run.sh, and aur.sh scripts to make the installation smoother, safer, and more robust.
1. install.sh
Potential Issues & Recommendations:
a) Btrfs subvolumes creation
You’re creating subvolumes inside /mnt/@ without mounting the @ subvolume first, which will fail:
mount -o noatime,compress=lzo,ssd,space_cache=v2,discard=async,subvol=@ "$part2" /mnt
mkdir -p /mnt/home /mnt/var /mnt/.snapshots
mount -o noatime,compress=lzo,ssd,space_cache=v2,discard=async,subvol=@home "$part2" /mnt/home
mount -o noatime,compress=lzo,ssd,space_cache=v2,discard=async,subvol=@var "$part2" /mnt/var
mount -o noatime,compress=zstd,ssd,space_cache=v2,discard=async,subvol=@snapshots "$part2" /mnt/.snapshots
User
fix these -
Sensitive passwords stored in plaintext files Secure /root/install.conf file permissions; consider in-memory or prompt-only
c) MIME setup
Using find with grep and xdg-mime inside a while loop may be slow — consider alternative scripted approaches.
Also no need to run sudo inside this script because intended to run as normal user.
Assistant
Certainly! Below are fixes/refactors for both your password storage concern and the MIME setup to be more efficient and correct.
1. Fix sensitive password storage in /root/install.conf
Current problem:
You write user and root passwords in plaintext to /mnt/root/install.conf with world-readable default permissions, which is a security risk.
Fix:
Write /root/install.conf with restrictive permissions immediately after file creation.
Delete the file after use (inside the chroot or immediately after arch-chroot returns) to avoid leftover credentials.
Alternatively, to avoid writing plaintext passwords to disk, pass the passwords via environment variables or prompt directly inside the chroot. (This is more complex and maybe not desired.)
Minimal fix in your existing flow (inside install.sh):
Your updated scripts are mostly on point now — good job incorporating best practices! Below, I provide some final corrections, clarifications, and recommendations based on your current install.sh and chroot.sh.
Last line creates subvolume /mnt/.snapshots (notice the missing @ prefix and creating .snapshots at top level, while you use subvol @snapshots in mounts).
The other three create subvolumes at root level, not inside@. So all four subvolumes should be consistent.
Fix:
Either create all four at root level with @prefix, or mount @ first and create others nested under it.
Since you mount @snapshots later, create the subvolume accordingly:
Your script is mostly solid and clean! Below are some suggestions and small fixes to improve robustness, avoid errors, and clarify some points:
1. gsettings calls
If this script can run outside a GNOME environment or without an active DBUS session, gsettings will fail.
Optional safer way:
Wrap with a check if you have a graphical session:
bash
if command -v gsettings >/dev/null 2>&1 && [ -n "$DISPLAY" ]; then
gsettings set org.gnome.desktop.interface gtk-theme 'Gruvbox-Dark'
gsettings set org.gnome.desktop.interface icon-theme "Papirus-Dark"
gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark'
fi
(You can also check $XDG_CURRENT_DESKTOP to confirm.)
2. Mime setup improvements
You're setting user-level default MIME apps with no sudo — good.
Make sure this script is run by the user who owns the $HOME.
3. Snapper .snapshots handling
bash
umount /.snapshots/
rm -r /.snapshots/
This assumes /.snapshots is currently mounted.
To prevent errors if not mounted, do:
bash
if mountpoint -q /.snapshots; then
umount /.snapshots/
fi
rm -rf /.snapshots/
Also consider checking before deleting to avoid accidental data loss.
4. firefox launch
bash
firefox
This will open Firefox window, blocking the script until it closes; perhaps not desired in a setup script.
If you want Firefox to launch in the background:
bash
nohup firefox >/dev/null 2>&1 &
Or comment/remove it if unnecessary.
5. Firefox profile detection & symlink
User
I am launching firefox so that it can create the files directory so that later I can place my user.js there.
updated run.sh -
#!/usr/bin/env bash
set -euo pipefail
mkdir -p "$XDG_STATE_HOME"/bash
Your explanation makes sense — launching Firefox once so the profile directory is created and then linking your custom user.js is a common workaround. However, launching Firefox in this way blocks your script until you close Firefox, which might be inconvenient.
Here are some recommendations to improve this step and general robustness:
1. Launch Firefox non-blocking (background) with a timeout
Launch Firefox in background and give it e.g., 5-10 seconds to create profiles but don’t hold the script indefinitely:
bash
# Launch Firefox in background (no window shown)
firefox --headless &
# Wait up to 15 seconds for profile directory to be created
timeout=15
elapsed=0
until profile_dir=$(find ~/.mozilla/firefox -maxdepth 1 -type d -name '*.default-release' | head -n1) && [[ -n "$profile_dir" ]]; do
sleep 1
((elapsed++))
if (( elapsed >= timeout )); then
echo "Timeout waiting for Firefox profile creation"
break
fi
done
if [[ -n "$profile_dir" ]]; then
ln -sf "$HOME/.dotfiles/user.js" "$profile_dir/user.js"
fi
# Kill headless Firefox if still running
pkill firefox || true
Explanation:
firefox --headless runs without GUI; modern Firefox supports that.
timeout loop waits for profile creation folder.
Symlink created once detected.
Then Firefox is killed.
If your Firefox version doesn’t support --headless, you can use the plain background (&) and manually kill.
2. Alternative: Use firefox --CreateProfile (profile creation command)
Firefox supports --CreateProfile NAME [PATH] command to create a new profile without launching GUI:
You can then directly ln -sf into the created directory.
User
make use of this -
2. Alternative: Use firefox --CreateProfile (profile creation command)
Firefox supports --CreateProfile NAME [PATH] command to create a new profile without launching GUI:
firefox --CreateProfile default
or specifying path
firefox --CreateProfile default "$HOME/.mozilla/firefox/yourprofile"
You can then directly ln -sf into the created directory.
Check your Firefox version for support:
firefox --help | grep CreateProfile
If it’s supported, this is cleaner.
profile name shouled be username
Assistant
Certainly! You can create a Firefox profile programmatically using firefox --CreateProfile username (where username is your chosen profile name, here your Linux username), then symlink your user.js to that profile directory—all without launching a GUI Firefox instance.
Here's how you can integrate this into your script using the username as profile name, safely and cleanly:
bash
# Create Firefox profile named after the username (if not exists)
profile_dir="$HOME/.mozilla/firefox/${user}.default-release"
# Check if the profile already exists by listing profiles.ini
if ! grep -q "Name=${user}" "$HOME/.mozilla/firefox/profiles.ini" 2>/dev/null; then
echo "Creating Firefox profile: $user"
firefox --CreateProfile "$user"
else
echo "Firefox profile $user already exists."
fi
# Now find the actual profile directory created by Firefox (profiles.ini can help)
# profiles.ini maps profile names to their relative or absolute paths.
# To be safe, parse profiles.ini:
get_profile_path() {
awk -v prof="$1" '
$0 ~ "\\[Profile[0-9]+\\]" { in_profile=1; next }
in_profile && /^Name=/ { name=substr($0,6) }
in_profile && /^Path=/ { path=substr($0,6) }
in_profile && /^IsRelative=/ { is_rel=$0; sub(/^IsRelative=/,"",is_rel) }
in_profile && /^$/ {
if (name==prof) {
if (is_rel == "1") {
print ENVIRON["HOME"] "/.mozilla/firefox/" path
} else {
print path
}
exit
}
in_profile=0
}
' "$HOME/.mozilla/firefox/profiles.ini"
}
profile_path=$(get_profile_path "$user")
if [[ -z "$profile_path" ]]; then
# fallback: assume standard location
profile_path="$HOME/.mozilla/firefox/${user}.default-release"
fi
echo "Linking user.js to Firefox profile at $profile_path"
ln -sf "$HOME/.dotfiles/user.js" "$profile_path/user.js"
User
#!/usr/bin/env bash
set -euo pipefail
mkdir -p "$XDG_STATE_HOME"/bash
Your script looks well structured and mostly good. I’m glad the zram section is working well! Here are some minor suggestions and a couple of tweaks to make your script a bit more robust and clean, focusing on areas you might want to improve or just consider:
1. Firefox profile w/ headless launch and symlinking
Your approach with firefox --headless & and waiting for profile creation is solid.
Consider adding a small delay after symlinking, just in case Firefox is still initializing files.
You already kill Firefox after timeout — good cleanup.
Optional addition (only if needed):
bash
sleep 1
after symlink to make sure filesystem settles.
2. zram-generator.conf syntax
If you want to make sure the percent (%) in ram * 2 is handled correctly by printf, double the percent sign:
If you're happy with your script, great! Otherwise, if you want me to polish/refactor full script or split into smaller functions with comments, just ask :)
mount -o noatime,compress=lzo,ssd,space_cache=v2,discard=async,subvol=@ "part2"/mntmkdir−p/mnt/home,var,.snapshotsmount−onoatime,compress=lzo,ssd,spacecache=v2,discard=async,subvol=@home"part2" /mnt/home
mount -o noatime,compress=lzo,ssd,space_cache=v2,discard=async,subvol=@var "part2"/mnt/vapart2" /mnt/.snapshots
firefox
if [ -d ~/.mozilla/firefox ]; then
dir=(ls/.mozilla/firefox/∣grep".default−release"∣head−n1)if[−n"dir" ]; then
ln -sf /home/USER/.dotfiles/user.js/home/USER/.mozilla/firefox/$dir/user.js
fi
fi
This modifies host's /etc/pacman.d/mirrorlistoutside the chroot. This is fine if you want your install environment to have updated mirrors, but better done inside the chroot (chroot.sh) for the installed system.
You do a similar reflector call insidechroot.sh — this inconsistency could cause confusion.
Recommendation: Do reflector once inside the chroot, to avoid modifying the live environment accidentally.
e) Password handling / security
Exporting passwords as environment variables can be dangerous.
They are also written to plaintext file /mnt/root/install.conf.
Make sure /mnt/root/install.conf is properly secured:
bash
chmod 600 /mnt/root/install.conf
Avoid storing unencrypted passwords where possible. If you trust the environment and the install process is temporary, this might be acceptable, but it’s a risk.
f) Missing checks for existing mounts
Try to umount /mnt directly without checking if mounted.
Use safer way to avoid failure if mount doesn't exist:
bash
if mountpoint -q /mnt; then
umount -R /mnt
fi
2. chroot.sh
Potential Issues & Recommendations:
a) rm -rf /root/* will delete install.conf
You source /root/install.conf but then do:
bash
rm -rf /root/*
This will delete your install.conf right after loading it.
Safer to remove the password containing file after you no longer need it. Or delete only specific files.
Alternatively, delete it in the outer install.sh after finishing arch-chroot.
b) Locale generation
Changing /etc/locale.gen with sed:
bash
sed -i 's/#en_US.UTF-8/en_US.UTF-8/g' /etc/locale.gen
This assumes only one locale line needs uncommenting.
What if multiple locales? Consider appending or verifying locale exists before uncommenting.
c) Grub config line
bash
sed -i '/^#GRUB_DISABLE_OS_PROBER=false$/c\GRUB_DISABLE_OS_PROBER=false' /etc/default/grub
This assumes line is commented exactly like that.
Better to replace or append more robustly, or use sed with ^#?GRUB_DISABLE_OS_PROBER=.*$
d) freshclam run outside systemd
freshclam runs once to update ClamAV definitions, but not as a service.
May want to enable clamav-freshclam.service for automatic updates.
e) Sudo policy
Suggest adding Defaults env_reset to /etc/sudoers.d/wheel (or check existing sudoers for compatibility).
f) Enable snapper timers and grub-btrfsd
Good practice.
Ensure grub-btrfs package supports grub-btrfsd systemd service on your installed arch version.
g) Enabling services
systemctl enable NetworkManager libvirtd clamav-daemon — might consider also enabling sshd if you want remote access.
h) User shell
You set /bin/bash shell, consider if you want zsh or fish as the default for new users.
3. run.sh
Potential Issues & Recommendations:
a) Hardcoding SRC_DIR and DEST_DIR
Using /home/${USER}/Downloads — might be absent or deleted.
Consider checking if directories exist before proceeding.
Use set -euo pipefail to catch errors early.
b) Using gsettings without checking DE
gsettings applies only if running GNOME or compatible.
Running this headless or on sway might error.
c) MIME setup
Using find with grep and xdg-mime inside a while loop may be slow — consider alternative scripted approaches.
Also no need to run sudo inside this script because intended to run as normal user.
d) Snapper mount and config
You try:
bash
umount /.snapshots/
rm -r /.snapshots/
This assumes snapper subvolumes /@/.snapshots are mounted on /.snapshots.
Make sure this mount exists, or check first (mountpoint -q).
e) firefox run at script start
Running firefox here will launch Firefox window unexpectedly.
Consider removing or making it optional.
f) UFW rules setup
Rules like allow 6881:6999/tcp are BitTorrent ports. Make sure user expects those.
4. aur.sh
Potential Issues & Recommendations:
a) git clone unconditionally will fail on re-runs
Check if repo exists before cloning:
bash
if [ ! -d paru ]; then
git clone https://aur.archlinux.org/paru.git
fi
b) Install packages with paru
You specify an incomplete list (last package snp looks typo?).
Check package names exist: snp is not an Arch package.
c) snapper snapshot description typos
You have "Before initial AUR" & "After initial AUR" — great to snapshot points.
Summary of top critical fixes and tips:
Issue
Recommendation
Btrfs subvolume creation failing
Create subvolumes only at top-level or mount subvolumes before nested creation
Sensitive passwords stored in plaintext files
Secure /root/install.conf file permissions; consider in-memory or prompt-only
Overwriting /etc/fstab with append (>>)
Use overwrite (>) to prevent duplicate fstab entries
rm -rf /root/* deletes install.conf prematurely
Delete sensitive files after arch-chroot completes
Run reflector only inside chroot for target install
Hardcoded paths and assumptions in run.sh
Add existence checks, set -euo pipefail for robustness
git clone without check in aur.sh
Check for existing clone before cloning
If you want, I can prepare a corrected/refactored minimal example for install.sh btrfs subvolume creation, or a safer way to handle passwords. Just ask!
bash
while true; do
read -s -p "Root password: " root_password
echo
read -s -p "Confirm root password: " root_password2
echo
[[ "$root_password" != "$root_password2" ]] && echo "Passwords do not match." && continue
[[ -z "$root_password" ]] && echo "Password cannot be empty." && continue
break
done
while true; do
read -s -p "User password: " user_password
echo
read -s -p "Confirm user password: " user_password2
echo
[[ "$user_password" != "$user_password2" ]] && echo "Passwords do not match." && continue
[[ -z "$user_password" ]] && echo "Password cannot be empty." && continue
break
done
Use these variables to set passwords, no longer needing to store them on disk.
2. Improve MIME setup in run.sh
Current approach (inefficient):
bash
find /usr/share/applications -iname '*.desktop' -print0 | while IFS= read -r -d $'\0' d; do
for m in $(grep MimeType "$d" | cut -d= -f2 | tr ";" " "); do
xdg-mime default "$(basename "$d")" "$m"
done
done
This uses many subshells, as well as invoking grep multiple times.
Also, running sudo inside run.sh is unnecessary if this is a user-level script.
Better approach:
You can write a simple awk or shell script to parse .desktop files once and set MIME defaults.
Consider this:
bash
#!/usr/bin/env bash
shopt -s nullglob
for desktopfile in /usr/share/applications/*.desktop; do
mime_types=$(grep '^MimeType=' "$desktopfile" | head -n1 | cut -d= -f2)
if [[ -n $mime_types ]]; then
IFS=';' read -ra mimes <<< "$mime_types"
for mime in "${mimes[@]}"; do
# skip empty mime types
[[ -z "$mime" ]] && continue
xdg-mime default "$(basename "$desktopfile")" "$mime"
done
fi
done
This script avoids using find + grep + cut in repeated loops.
It uses shell string manipulation only.
Regarding sudo
Remove all sudo usages from your user-level scripts unless strictly needed.
xdg-mime only changes user mime database, so it doesn’t need sudo.
Running sudo unnecessarily causes prompts and may fail if no sudoers rights.
--- Prompt Section (collect all user input here) ---
Disk Selection
echo "Available disks:"
lsblk -d -o NAME,SIZE,MODEL
while true; do
read -p "Enter Disk (e.g. sda, nvme0n1): " disk_input
disk="/dev/{disk_input%/}"
if [ ! -b "disk" ]; then
echo "Disk $disk does not exist. Try again."
continue
fi
break
done
Hostname
while true; do
read -p "Hostname: " hostname
[[ -z "$hostname" ]] && echo "Hostname cannot be empty." && continue
break
done
Root Password
while true; do
read -s -p "Root password: " root_password
echo
read -s -p "Confirm root password: " root_password2
echo
[[ "rootpassword"!="root_password2" ]] && echo "Passwords do not match." && continue
[[ -z "$root_password" ]] && echo "Password cannot be empty." && continue
break
done
Username
while true; do
read -p "Username: " user
[[ -z "$user" ]] && echo "Username cannot be empty." && continue
break
done
User Password
while true; do
read -s -p "User password: " user_password
echo
read -s -p "Confirm user password: " user_password2
echo
[[ "userpassword"!="user_password2" ]] && echo "Passwords do not match." && continue
[[ -z "$user_password" ]] && echo "Password cannot be empty." && continue
break
done
Export variables for later use
export disk hostname root_password user user_password
Partition Naming
if [[ "disk"==∗nvme∗]];thenpartprefix="{disk}p"
else
part_prefix="${disk}"
fi
mount -o noatime,compress=lzo,ssd,space_cache=v2,discard=async,subvol=@ "part2"/mntmkdir−p/mnt/home,var,.snapshotsmount−onoatime,compress=lzo,ssd,spacecache=v2,discard=async,subvol=@home"part2" /mnt/home
mount -o noatime,compress=lzo,ssd,space_cache=v2,discard=async,subvol=@var "part2"/mnt/vapart2" /mnt/.snapshots
if mountpoint -q /mnt; then
umount -R /mnt
fi
echo "Installation completed. Please reboot your system."
No issues there.
d) Password file permission
Good to see chmod 600 on /mnt/root/install.conf.
e) genfstab usage
Use overwrite (>) to avoid duplicates — done right.
f) Unmounting /mnt safely:
bash
if mountpoint -q /mnt; then
umount -R /mnt
fi
A safe and clean way.
2. Corrections and suggestions for chroot.sh
a) Removing /root/install.conf
This line is perfect:
bash
shred -u /root/install.conf
This securely deletes the file after sourcing it.
If shred is not available, consider fallback to:
bash
rm -f /root/install.conf
b) Fix for sed line changing GRUB_DISABLE_OS_PROBER
Current:
bash
sed -i '/^#GRUB_DISABLE_OS_PROBER=false$/c\GRUB_DISABLE_OS_PROBER=false' /etc/default/grub
This only works if the exact commented line exists.
Better to handle both cases, and ensure GRUB_DISABLE_OS_PROBER=false is set:
bash
if grep -q "^#GRUB_DISABLE_OS_PROBER=false" /etc/default/grub; then
sed -i 's/^#GRUB_DISABLE_OS_PROBER=false/GRUB_DISABLE_OS_PROBER=false/' /etc/default/grub
elif ! grep -q "^GRUB_DISABLE_OS_PROBER=" /etc/default/grub; then
echo "GRUB_DISABLE_OS_PROBER=false" >> /etc/default/grub
fi
c) freshclam best run under clamav-freshclam.service
mkdir -p "THEMEDIR/gtk−3.0"cp−r"{SRC_DIR}/assets/gtk/scalable" "THEMEDIR/gtk−3.0/assets"2>/dev/null∣∣trueif[{SRC_DIR}/main/gtk-3.0/gtk-Dark.scss" ]; then
sassc -M -t expanded "SRCDIR/main/gtk−3.0/gtk−{THEME_DIR}/gtk-3.0/gtk.css"
cp "THEMEDIR/gtk−3.0/gtk.css""{THEME_DIR}/gtk-3.0/gtk-dark.css"
fi
--- GTK4 ---
mkdir -p "THEMEDIR/gtk−4.0"cp−r"{SRC_DIR}/assets/gtk/scalable" "THEMEDIR/gtk−4.0/assets"2>/dev/null∣∣trueif[{SRC_DIR}/main/gtk-4.0/gtk-Dark.scss" ]; then
sassc -M -t expanded "SRCDIR/main/gtk−4.0/gtk−{THEME_DIR}/gtk-4.0/gtk.css"
cp "THEMEDIR/gtk−4.0/gtk.css""{THEME_DIR}/gtk-4.0/gtk-dark.css"
fi
--- index.theme ---
cat > "THEMEDIR/index.theme"<<EOF[DesktopEntry]Type=X−GNOME−MetathemeName={THEME_NAME}
Comment=Gruvbox Dark GTK Theme
EOF
gsettings set org.gnome.desktop.interface gtk-theme 'Gruvbox-Dark'
gsettings set org.gnome.desktop.interface icon-theme "Papirus-Dark"
gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark'
Mime setup
shopt -s nullglob
for desktopfile in /usr/share/applications/*.desktop; do
mime_types=(grep′MimeType=′"desktopfile" | head -n1 | cut -d= -f2)
if [[ -n mimetypes]];thenIFS=′;′read−mime_types"
for mime in "{mimes[@]}"; do
# skip empty mime types
[[ -z "mime" ]] && continue
xdg-mime default "(basename"desktopfile")" "mime"donefitype; done
for type in jpeg svg png gif webp bmp tiff; do xdg-mime default swayimg.desktop image/$type; done
Snapper setup
umount /.snapshots/
rm -r /.snapshots/
sudo snapper -c root create-config / || true
sudo snapper -c home create-config /home || true
sudo snapper -c var create-config /var || true
mount -a
firefox
if [ -d ~/.mozilla/firefox ]; then
dir=(ls/.mozilla/firefox/∣grep".default−release"∣head−n1)if[−n"dir" ]; then
ln -sf /home/USER/.dotfiles/user.js/home/USER/.mozilla/firefox/$dir/user.js
fi
fi
dir=$(ls ~/.mozilla/firefox/ | grep ".default-release" | head -n1)
if [ -n "$dir" ]; then
ln -sf /home/$USER/.dotfiles/user.js /home/$USER/.mozilla/firefox/$dir/user.js
fi
Be sure $USER and $HOME are consistent. Better:
bash
profile_dir=$(find ~/.mozilla/firefox -maxdepth 1 -type d -name '*.default-release' | head -n1)
if [[ -n "$profile_dir" ]]; then
ln -sf "$HOME/.dotfiles/user.js" "$profile_dir/user.js"
fi
mkdir -p "THEMEDIR/gtk−3.0"cp−r"{SRC_DIR}/assets/gtk/scalable" "THEMEDIR/gtk−3.0/assets"2>/dev/null∣∣trueif[{SRC_DIR}/main/gtk-3.0/gtk-Dark.scss" ]; then
sassc -M -t expanded "SRCDIR/main/gtk−3.0/gtk−{THEME_DIR}/gtk-3.0/gtk.css"
cp "THEMEDIR/gtk−3.0/gtk.css""{THEME_DIR}/gtk-3.0/gtk-dark.css"
fi
--- GTK4 ---
mkdir -p "THEMEDIR/gtk−4.0"cp−r"{SRC_DIR}/assets/gtk/scalable" "THEMEDIR/gtk−4.0/assets"2>/dev/null∣∣trueif[{SRC_DIR}/main/gtk-4.0/gtk-Dark.scss" ]; then
sassc -M -t expanded "SRCDIR/main/gtk−4.0/gtk−{THEME_DIR}/gtk-4.0/gtk.css"
cp "THEMEDIR/gtk−4.0/gtk.css""{THEME_DIR}/gtk-4.0/gtk-dark.css"
fi
--- index.theme ---
cat > "THEMEDIR/index.theme"<<EOF[DesktopEntry]Type=X−GNOME−MetathemeName={THEME_NAME}
Comment=Gruvbox Dark GTK Theme
EOF
gsettings set org.gnome.desktop.interface gtk-theme 'Gruvbox-Dark'
gsettings set org.gnome.desktop.interface icon-theme "Papirus-Dark"
gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark'
Mime setup
shopt -s nullglob
for desktopfile in /usr/share/applications/*.desktop; do
mime_types=(grep′MimeType=′"desktopfile" | head -n1 | cut -d= -f2)
if [[ -n mimetypes]];thenIFS=′;′read−mime_types"
for mime in "{mimes[@]}"; do
# skip empty mime types
[[ -z "mime" ]] && continue
xdg-mime default "(basename"desktopfile")" "mime"donefitype; done
for type in jpeg svg png gif webp bmp tiff; do xdg-mime default swayimg.desktop image/$type; done
Snapper setup
if mountpoint -q /.snapshots; then
umount /.snapshots/
fi
rm -rf /.snapshots/
sudo snapper -c root create-config / || true
sudo snapper -c home create-config /home || true
sudo snapper -c var create-config /var || true
mount -a
firefox
profile_dir=(find/.mozilla/firefox−maxdepth1−typed−name′∗.default−release′∣head−n1)if[[−n"profile_dir" ]]; then
ln -sf "HOME/.dotfiles/user.js""profile_dir/user.js"
fi
5. Complete snippet with headless Firefox workaround example
bash
# Launch Firefox headlessly to create profile folder
firefox --headless &
timeout=15
elapsed=0
until profile_dir=$(find ~/.mozilla/firefox -maxdepth 1 -type d -name '*.default-release' | head -n1) && [[ -n "$profile_dir" ]]; do
sleep 1
((elapsed++))
if (( elapsed >= timeout )); then
echo "Timeout waiting for Firefox profile directory."
break
fi
done
if [[ -n "$profile_dir" ]]; then
ln -sf "$HOME/.dotfiles/user.js" "$profile_dir/user.js"
echo "Linked user.js to Firefox profile."
else
echo "Firefox profile directory not found, user.js not linked."
fi
pkill firefox || true
If you want, I can help you fully refactor this section or create a standalone script that just sets up Firefox user.js safely and cleanly.
Explanation:
We check if profile with name $user exists in profiles.ini. If not, create it.
Parse profiles.ini to get the full path to the profile folder, supporting relative and absolute paths.
Symlink user.js.
Avoid launching normal Firefox GUI. No wait loops needed.
Integration snippet for your script:
Replace your existing Firefox profile setup block with:
bash
# Firefox profile setup using profile named as username
if ! grep -q "Name=${user}" "$HOME/.mozilla/firefox/profiles.ini" 2>/dev/null; then
echo "Creating Firefox profile named '$user'..."
firefox --CreateProfile "$user"
else
echo "Firefox profile '$user' exists."
fi
profile_path=$(get_profile_path "$user")
if [[ -z "$profile_path" ]]; then
echo "Warning: Could not find Firefox profile path for user '$user'"
profile_path="$HOME/.mozilla/firefox/${user}.default-release"
fi
ln -sf "$HOME/.dotfiles/user.js" "$profile_path/user.js"
Make sure you define the get_profile_path function before using it.
If your system uses older Firefox without --CreateProfile, fallback to launching headless Firefox as before.
Let me know if you want me to prepare an all-in-one snippet for your full script!
mkdir -p "THEMEDIR/gtk−3.0"cp−r"{SRC_DIR}/assets/gtk/scalable" "THEMEDIR/gtk−3.0/assets"2>/dev/null∣∣trueif[{SRC_DIR}/main/gtk-3.0/gtk-Dark.scss" ]; then
sassc -M -t expanded "SRCDIR/main/gtk−3.0/gtk−{THEME_DIR}/gtk-3.0/gtk.css"
cp "THEMEDIR/gtk−3.0/gtk.css""{THEME_DIR}/gtk-3.0/gtk-dark.css"
fi
--- GTK4 ---
mkdir -p "THEMEDIR/gtk−4.0"cp−r"{SRC_DIR}/assets/gtk/scalable" "THEMEDIR/gtk−4.0/assets"2>/dev/null∣∣trueif[{SRC_DIR}/main/gtk-4.0/gtk-Dark.scss" ]; then
sassc -M -t expanded "SRCDIR/main/gtk−4.0/gtk−{THEME_DIR}/gtk-4.0/gtk.css"
cp "THEMEDIR/gtk−4.0/gtk.css""{THEME_DIR}/gtk-4.0/gtk-dark.css"
fi
--- index.theme ---
cat > "THEMEDIR/index.theme"<<EOF[DesktopEntry]Type=X−GNOME−MetathemeName={THEME_NAME}
Comment=Gruvbox Dark GTK Theme
EOF
gsettings set org.gnome.desktop.interface gtk-theme 'Gruvbox-Dark'
gsettings set org.gnome.desktop.interface icon-theme "Papirus-Dark"
gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark'
Mime setup
shopt -s nullglob
for desktopfile in /usr/share/applications/*.desktop; do
mime_types=(grep′MimeType=′"desktopfile" | head -n1 | cut -d= -f2)
if [[ -n mimetypes]];thenIFS=′;′read−mime_types"
for mime in "{mimes[@]}"; do
# skip empty mime types
[[ -z "mime" ]] && continue
xdg-mime default "(basename"desktopfile")" "mime"donefitype; done
for type in jpeg svg png gif webp bmp tiff; do xdg-mime default swayimg.desktop image/$type; done
Snapper setup
if mountpoint -q /.snapshots; then
umount /.snapshots/
fi
rm -rf /.snapshots/
sudo snapper -c root create-config / || true
sudo snapper -c home create-config /home || true
sudo snapper -c var create-config /var || true
mount -a
Wait up to 15 seconds for profile directory to be created
timeout=7 # Thala for a reason
elapsed=0
until profile_dir=(find ~/.mozilla/firefox -maxdepth 1 -type d -name '*.default-release' | head -n1) && [[ -n "profile_dir" ]]; do
sleep 1
((elapsed++))
if (( elapsed >= timeout )); then
echo "Timeout waiting for Firefox profile creation"
break
fi
done
if [[ -n "profiledir"]];thenln−sf"HOME/.dotfiles/user.js" "$profile_dir/user.js"
fi