commit ae87732af36e21292f2cac83bf72aadd25ab7f03
parent 528ca6be1737c69fa3f5ada831b4b954f649f82f
Author: awy <awy@awy.one>
Date: Thu, 20 Mar 2025 14:09:08 +0300
update
Diffstat:
M | rice.sh | | | 106 | +++++++++++++++++++++++++++++++++++++++++++++---------------------------------- |
1 file changed, 61 insertions(+), 45 deletions(-)
diff --git a/rice.sh b/rice.sh
@@ -11,31 +11,41 @@ PERMUSER="$(id -nu "1000")"
id "$PERMUSER" > /dev/null 2>&1 || { echo "User $PERMUSER does not exist. Exiting."; exit 1; }
+if [ -x "$(command -v doas)" ]; then
+ evalcommand="doas -u $PERMUSER"
+else
+ evalcommand="sudo -u $PERMUSER"
+fi
+
+run_as_user() {
+ $evalcommand "$@"
+}
+
DEPLIST="`sed -e 's/#.*$//' -e '/^$/d' dependencies.txt | tr '\n' ' '`"
pacman -Sy --noconfirm
-pacman -S $DEPLIST --noconfirm
+pacman -S "$DEPLIST" --noconfirm --needed
-usermod -aG seat,input,audio,video $PERMUSER
-doas -u $PERMUSER cp -r "$WORKDIRECTORY"/.config /home/$PERMUSER
-doas -u $PERMUSER cp -r "$WORKDIRECTORY"/.local /home/$PERMUSER
-doas -u $PERMUSER cp -a "$WORKDIRECTORY"/.zprofile /home/$PERMUSER
+usermod -aG seat,input,audio,video "$PERMUSER"
+run_as_user cp -r "$WORKDIRECTORY"/.config /home/"$PERMUSER"
+run_as_user cp -r "$WORKDIRECTORY"/.local /home/"$PERMUSER"
+run_as_user cp -a "$WORKDIRECTORY"/.zprofile /home/"$PERMUSER"
-doas -u $PERMUSER mkdir -p /home/$PERMUSER/.config/git
-doas -u $PERMUSER mkdir -p /home/$PERMUSER/.config/npm
-doas -u $PERMUSER touch /home/$PERMUSER/.config/npm/npmrc
-doas -u $PERMUSER mkdir -p /home/$PERMUSER/.cache/zsh
-doas -u $PERMUSER mkdir -p /home/$PERMUSER/.local/share/themes
-doas -u $PERMUSER mkdir -p /home/$PERMUSER/.local/share/icons
+run_as_user mkdir -p /home/"$PERMUSER"/.config/git
+run_as_user mkdir -p /home/"$PERMUSER"/.config/npm
+run_as_user touch /home/"$PERMUSER"/.config/npm/npmrc
+run_as_user mkdir -p /home/"$PERMUSER"/.cache/zsh
+run_as_user mkdir -p /home/"$PERMUSER"/.local/share/themes
+run_as_user mkdir -p /home/"$PERMUSER"/.local/share/icons
cd "$WORKDIRECTORY" || exit
-doas -u $PERMUSER git clone https://github.com/zdharma-continuum/fast-syntax-highlighting
+run_as_user git clone https://github.com/zdharma-continuum/fast-syntax-highlighting
mkdir -p /usr/share/zsh/plugins
cp -rf fast-syntax-highlighting /usr/share/zsh/plugins
cd "$WORKDIRECTORY"
-doas -u $PERMUSER mkdir -p /home/$PERMUSER/.ssh
-doas -u $PERMUSER mkdir -p /home/$PERMUSER/.gnupg
-doas -u $PERMUSER touch /home/$PERMUSER/.gnupg/gpg-agent.conf
+run_as_user mkdir -p /home/"$PERMUSER"/.ssh
+run_as_user mkdir -p /home/"$PERMUSER"/.gnupg
+run_as_user touch /home/"$PERMUSER"/.gnupg/gpg-agent.conf
cat <<EOL >> /home/$PERMUSER/.gnupg/gpg-agent.conf
enable-ssh-support
@@ -51,12 +61,12 @@ init-module=\${XDG_CONFIG_HOME}/npm/config/npm-init.js
logs-dir=\${XDG_STATE_HOME}/npm/logs
EOL
-doas -u $PERMUSER find /home/$PERMUSER/.gnupg -type f -exec chmod 600 {} \;
-doas -u $PERMUSER find /home/$PERMUSER/.gnupg -type d -exec chmod 700 {} \;
-doas -u $PERMUSER find /home/$PERMUSER/.ssh -type f -exec chmod 600 {} \;
-doas -u $PERMUSER find /home/$PERMUSER/.ssh -type d -exec chmod 700 {} \;
+run_as_user find /home/"$PERMUSER"/.gnupg -type f -exec chmod 600 {} \;
+run_as_user find /home/"$PERMUSER"/.gnupg -type d -exec chmod 700 {} \;
+run_as_user find /home/"$PERMUSER"/.ssh -type f -exec chmod 600 {} \;
+run_as_user find /home/"$PERMUSER"/.ssh -type d -exec chmod 700 {} \;
-chsh -s /bin/zsh $PERMUSER
+chsh -s /bin/zsh "$PERMUSER"
mkdir -p /root/.config/nvim
cat <<EOL >> /root/.config/nvim/init.vim
@@ -75,8 +85,11 @@ sed -Ei "s/^#(DisableSandbox).*/\1/" /etc/pacman.conf
# Use all cores for compilation.
sed -i "s/-j2/-j$(nproc)/;/^#MAKEFLAGS/s/^#//" /etc/makepkg.conf
-# Use doas for Pacman authentification
-sed -i 's/#PACMAN_AUTH=.*$/PACMAN_AUTH=(doas)/' /etc/makepkg.conf
+
+if [ -x "$(command -v doas)" ]; then
+ # Use doas for Pacman authentification
+ sed -i 's/#PACMAN_AUTH=.*$/PACMAN_AUTH=(doas)/' /etc/makepkg.conf
+fi
cat <<EOL >> /usr/share/libalpm/hooks/statusbar.hook
[Trigger]
@@ -104,33 +117,33 @@ When = PostTransaction
Exec = /usr/bin/setcap cap_net_admin=ep /usr/sbin/sing-box
EOL
-doas -u $PERMUSER git clone https://aur.archlinux.org/paru.git
+run_as_user git clone https://aur.archlinux.org/paru.git
cd paru
-doas -u $PERMUSER makepkg -csi --noconfirm
+run_as_user makepkg -csi --noconfirm
cd "$WORKDIRECTORY"
DEPLIST="`sed -e 's/#.*$//' -e '/^$/d' aurdeps.txt | tr '\n' ' '`"
-doas -u $PERMUSER paru -S $DEPLIST --noconfirm
-doas -u $PERMUSER dbus-launch gsettings set org.gnome.desktop.interface gtk-theme "Nordic"
-doas -u $PERMUSER dbus-launch gsettings set org.gnome.desktop.wm.preferences theme "Nordic"
-doas -u $PERMUSER dbus-launch gsettings set org.gnome.desktop.wm.preferences button-layout 'appmenu'
-doas -u $PERMUSER dbus-launch gsettings set org.gnome.desktop.interface font-name "Sans 11"
+run_as_user paru -S "$DEPLIST" --noconfirm
+run_as_user dbus-launch gsettings set org.gnome.desktop.interface gtk-theme "Nordic"
+run_as_user dbus-launch gsettings set org.gnome.desktop.wm.preferences theme "Nordic"
+run_as_user dbus-launch gsettings set org.gnome.desktop.wm.preferences button-layout 'appmenu'
+run_as_user dbus-launch gsettings set org.gnome.desktop.interface font-name "Sans 11"
cd ..
rm -rf hyprdots
rm -rf paru
rm -rf go
dinitctl enable cronie
-echo "*/10 * * * * /home/$PERMUSER/.local/bin/cron/newsup\n*/30 * * * * /home/$PERMUSER/.local/bin/cron/checkup\n*/10 * * * * /usr/local/bin/mailsync" | doas -u $PERMUSER crontab -
+echo "*/10 * * * * /home/$PERMUSER/.local/bin/cron/newsup\n*/30 * * * * /home/$PERMUSER/.local/bin/cron/checkup\n*/10 * * * * /usr/local/bin/mailsync" | run_as_user crontab -
-doas -u $PERMUSER git clone https://github.com/lukesmithxyz/mutt-wizard /home/$PERMUSER/mutt-wizard
-cd /home/$PERMUSER/mutt-wizard
+run_as_user git clone https://github.com/lukesmithxyz/mutt-wizard /home/"$PERMUSER"/mutt-wizard
+cd /home/"$PERMUSER"/mutt-wizard
make install
-cd /home/$PERMUSER
-doas -u $PERMUSER git clone https://git.awy.one/automated-librewolf
+cd /home/"$PERMUSER"
+run_as_user git clone https://git.awy.one/automated-librewolf
cd automated-librewolf
-doas -u $PERMUSER ./configure_librewolf.sh
-cd /home/$PERMUSER
+run_as_user ./configure_librewolf.sh
+cd /home/"$PERMUSER"
rm -rf automated-librewolf
rm -rf mutt-wizard
@@ -146,33 +159,36 @@ scriptopts_dir="$config_dir/script-opts"
conf_file="$scriptopts_dir/uosc.conf"
echo "Downloading archive..."
-doas -u $PERMUSER curl -Ls -o $zip_file $zip_url || abort "Couldn't download: $zip_url"
+run_as_user curl -Ls -o $zip_file $zip_url || abort "Couldn't download: $zip_url"
echo "Extracting archive..."
-doas -u $PERMUSER unzip -qod $config_dir $zip_file || abort "Couldn't extract: $zip_file"
+run_as_user unzip -qod $config_dir $zip_file || abort "Couldn't extract: $zip_file"
echo "Deleting archive..."
rm -f $zip_file || echo "Couldn't delete: $zip_file"
-doas -u $PERMUSER mkdir -p $scriptopts_dir || echo "Couldn't create: $scriptopts_dir"
-doas -u $PERMUSER curl -Ls -o $conf_file $conf_url || echo "Couldn't download: $conf_url"
+run_as_user mkdir -p $scriptopts_dir || echo "Couldn't create: $scriptopts_dir"
+run_as_user curl -Ls -o $conf_file $conf_url || echo "Couldn't download: $conf_url"
# thumbfast
-doas -u "$PERMUSER" curl -Ls -o "$config_dir/scripts/thumbfast.lua" $thumbfastlua_url || echo "Couldn't download: $thumbfastlua_url"
-doas -u "$PERMUSER" curl -Ls -o "$scriptopts_dir/thumbfast.conf" $thumbfastconf_url || echo "Couldn't download: $thumbfastconf_url"
+run_as_user curl -Ls -o "$config_dir/scripts/thumbfast.lua" $thumbfastlua_url || echo "Couldn't download: $thumbfastlua_url"
+run_as_user curl -Ls -o "$scriptopts_dir/thumbfast.conf" $thumbfastconf_url || echo "Couldn't download: $thumbfastconf_url"
sed -Ei "s/(network).*/\1=yes/" "$scriptopts_dir/thumbfast.conf"
# sponsorblock
-doas -u "$PERMUSER" curl -Ls -o "$config_dir/scripts/sponsorblock_minimal.lua" $sponsorblock_url || echo "Couldn't download: $sponsorblock_url"
+run_as_user curl -Ls -o "$config_dir/scripts/sponsorblock_minimal.lua" $sponsorblock_url || echo "Couldn't download: $sponsorblock_url"
# for mutt-wizard to work with gopass
ln -s /bin/gopass /bin/pass
# nvchad
-doas -u "$PERMUSER" git clone https://git.awy.one/nvchad /home/"$PERMUSER"/.config/nvim
+run_as_user git clone https://git.awy.one/nvchad /home/"$PERMUSER"/.config/nvim
rm -rf /home/"$PERMUSER"/.config/nvim/.git
# pam
sed -i '/auth[[:space:]]*include[[:space:]]*system-local-login/a auth optional pam_gnome_keyring.so' /etc/pam.d/login
sed -i '/session[[:space:]]*include[[:space:]]*system-local-login/a session optional pam_gnome_keyring.so auto_start' /etc/pam.d/login
-echo "password optional pam_gnome_keyring.so" >> /etc/pam.d/passwd
+echo "password optional pam_gnome_keyring.so" >> /etc/pam.d/passwd
+
+yes | paru -Scc
+rm -rf /home/"$PERMUSER"/.cargo
echo "Your linux is riced!"