forked from noctuid/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
post-install
executable file
·905 lines (814 loc) · 26.3 KB
/
post-install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
#!/usr/bin/env bash
# TODO
# - just remove salt stuff completely
# - tlp config (charging rates)
# - aur problems (aur helper issues, slowness, etc.)
# - evm doesn't work
# - https://stackoverflow.com/questions/30421986/why-does-npm-list-g-lead-to-npm-err-missing-error
# Goal: idempotent post-install setup script
# Notes:
# - almost nothing needs to be done manually; this handles all installation
# steps after the user has mounted the partitions, run ./system-install, and
# created a user and set that user's password
# - initial necessary configuration (bootloader, initramfs, time, hostname)
# - home and root configuration file syncing
# - adding the user to groups
# - package installation
# - package configuration/setup (e.g. font setup)
# - service activation
# - this script does not work perfectly; may need to rerun (e.g. network issues,
# potentially changes to packages/package names, potential problems with aur
# helper, etc.; example: installing siji-git current calls xset, so it has to
# be installed with X running)
# - this script is meant to be usable after running arch-chroot, so that the
# system can be fully set up before the first boot (the reasoning is that it's
# easier to set up a new system from an existing system; testing can be done
# before completely moving over to a new harddrive, for example; you can also
# just copy the system over:
# https://wiki.archlinux.org/index.php/Install_from_existing_Linux#From_a_host_running_Arch_Linux
# I prefer a clean, declarative installation though); because of this, it
# must work around some limitations:
# - runs as root since sudo does not work with a password in arch-chroot
# (would either need to have NOPASSWD for user or potentially use an askpass
# program if that is possible)
# - can't start services from chroot of course, but can enable (not user
# services though); user services must be enabled by running this script
# again on the new installation with the non-chroot operation (also does
# some other extra configuration)
# Using salt mainly for nice messaging (shows which sections failed, how many,
# etc.); have made optional because of problems with salt (once had difficultly
# installing it; once had other issues that were difficult to debug), so not
# using by default
# potential salt alternatives
# https://github.com/shawndellysse/farch
# https://github.com/rycee/home-manager/
# https://github.com/NixOS/nixpkgs/pull/9250
# aconfmgr (not for me but potentially useful)
# Rules:
# - any function meant to be used with "|| fail_echo" should return non-zero if
# any part of it fails (not using set -e; see
# http://mywiki.wooledge.org/BashFAQ/105; main annoyance was behavior where
# failed function will continue if do func ||)
# * Constants
basedir="$(dirname "$(realpath "$0")")"
log="$basedir"/log.txt
failure_log="$basedir"/failure_log.txt
builduser=noctuidbuilder
# * Argument Parsing
# can use tzselect to find
timezone=America/New_York
hostname=bahamut
user=noctuid
uhome=/home/"$user"
log_level=info
use_salt=false
force_reflector=false
print_option_help() {
echo "
usage: post-install [options] [operation]
options:
-t or --timezone <timezone>
Timezone to set. For example: --timezone \"America/New_York\"
You can use tzselect to find your timezone.
Current value: $timezone
-H or --hostname <hostname>
Hostname to set. For example: --hostname \"myhostname\"
Current value: $hostname
-u or --username <username>
Username of user whose ~/dotfiles are to be used. This user is also used
for building/installing packages.
Current value: $user
-l or --log-level <level>
Log level to pass to salt-call's --log-level. Keep in mind that setting a
lower log level than the default may make debugginging difficult or
impossible.
Current value: $log_level
-s or --use-salt
If specified, use salt for configuration/setup.
Current value: $use_salt
-f or --force-reflector
If specified, force updating mirror list with reflector even if it has
been updated before.
Currrent value: $force_reflector
-h or --help
Print this help text.
operations:
non-chroot
Do configuration that can't be done in a chroot and nothing else (e.g.
enabling systemd services and ufw). Meant to be run once after first boot
of system be done in a chroot. If this action is not specified, this
configuration will still be done if it is necessary and if not in a
chroot.
root-config
Just copy root config files from $uhome/dotfiles to /
boot
Generate initramfs and (re)install bootloader.
fix
Same as calling with root-config and then boot.
emacs
Install or update lucid Emacs master with native compilation
<no option/ default>
Do all setup."
}
while getopts t:H:u:l:nsfh-: opt
do
case $opt in
t) timezone=$OPTARG;;
H) hostname=$OPTARG;;
u) user=$OPTARG;;
l) log_level=$OPTARG;;
s) use_salt=true;;
f) force_reflector=true;;
-)
if [[ $OPTARG =~ ^(use-salt)$ ]] || \
[[ $OPTARG == *=* ]]; then
OPTION=${OPTARG%%=*}
OPTARG=${OPTARG#*=}
else
OPTION=$OPTARG
# shellcheck disable=SC2124
OPTARG=${@:$OPTIND:1}
((OPTIND++))
fi
case $OPTION in
timezone) timezone=$OPTARG;;
hostname) hostname=$OPTARG;;
user) user=$OPTARG;;
log-level) log_level=$OPTARG;;
use-salt) use_salt=true;;
force-reflector) force_reflector=true;;
help) print_option_help && exit 0;;
*) print_option_help && exit 1;;
esac;;
h) print_option_help && exit 0;;
*) print_option_help && exit 1;;
esac
done
# * Helpers
prompt_continue() {
echo "continue? [y/n]"
read -r reply
if [[ $reply != y ]]; then
exit 0
fi
}
# for more easily readable log when not using salt
fail_echo() {
echo "$1" | tee --append "$failure_log"
}
is_chroot() {
[[ $(stat -c %d:%i /) != $(stat -c %d:%i /proc/1/root/.) ]]
}
# TODO this doesn't work
# TODO maybe check if group before installing in install_package; fcitx-im is
# only group in ./packages currently
group_installed() {
pacman --sync --groups "$1" | while read -r line; do
pacman --query "$(echo "$line" | awk '{print $2}')" || return 1
done
}
# * Basic Setup
# ** Sudo
sudo_setup() {
if passwd --status root | awk '$2 == "NP" {exit 1}'; then
echo "Please set a password for root:"
passwd root || return 1
fi
echo "Updating sudo configuration."
# set up /etc/sudoers
# - allow root to execute any command
# - allow users in wheel group to use sudo
# - allow $builduser to execute pacman without password
if ! id -u "$builduser" &> /dev/null; then
useradd --system --create-home \
--shell /sbin/nologin "$builduser" || return 1
fi
echo "Defaults passwd_timeout=0
root ALL=(ALL) ALL
%wheel ALL=(ALL) ALL
$builduser ALL= NOPASSWD: /usr/bin/pacman" | EDITOR='tee' visudo
# potentially dangerous without sudo and proper setup; risky
# passwd -l root
}
# ** Time
time_setup() {
echo "Updating timezone and clock."
ln -sf /usr/share/zoneinfo/"$timezone" /etc/localtime \
&& hwclock --systohc --utc
# using ntpd instead
# timedatectl set-ntp true
}
# ** Locale
locale_setup() {
echo "Performing locale configuration."
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen || return 1
# necessary because of Emacs bug
echo "ja_JP.UTF-8 UTF-8" >> /etc/locale.gen \
&& locale-gen \
&& echo "LANG=en_US.UTF-8" > /etc/locale.conf
}
# ** Hostname
hostname_setup() {
echo "Updating hostname."
hostnamectl set-hostname "$hostname"
}
# * Pacman/AUR
pac_install() {
if ! pacman --query "$1" &> /dev/null; then
echo "Installing $1."
pacman -S --noconfirm "$1" \
|| fail_echo "Failed: pacman --noconfirm -S $package"
fi
}
update_mirror_list() {
pac_install reflector || return 1
echo "Updating mirrorlist with reflector."
cd /etc/pacman.d || return 1
if $force_reflector || [[ ! -f mirrorlist.reflector ]]; then
# update server list by speed
reflector --verbose -l 200 --sort rate \
--save mirrorlist.reflector || return 1
if [[ ! -f mirrorlist.backup ]]; then
cp mirrorlist mirrorlist.backup
fi
cp mirrorlist.reflector mirrorlist || return 1
fi
}
install_paru() {
if ! pacman -Q paru-bin &> /dev/null; then
echo "Installing paru."
# doesn't work
# if ! group_installed base_devel; then
# pacman -S --noconfirm --needed base-devel
# fi
pacman -S --noconfirm --needed base-devel
pac_install git
build_dir="$uhome"/build/paru-bin
if [[ -d "$build_dir" ]]; then
rm -rf "$build_dir"
fi
mkdir -p "$build_dir"
git clone https://aur.archlinux.org/paru-bin.git "$build_dir"
chown "$user":"$user" "$build_dir" \
&& cd "$build_dir" \
&& sudo -u "$user" makepkg --noconfirm -fsr \
&& pacman --noconfirm -U -- *.pkg.tar*
fi
}
install_emacs_lucid() {
echo "Installing emacs-git with lucid toolkit and native comp."
emacs_recipe=emacs-git
if [[ -n $1 ]] || ! pacman -Q "$emacs_recipe" &> /dev/null; then
cd /tmp \
&& paru --getpkgbuild "$emacs_recipe" \
&& sudo chown "$user" "$emacs_recipe" \
&& cd "$emacs_recipe" \
&& sed --in-place --regexp-extended 's/(^LUCID=)/\1YES/' PKGBUILD \
&& sed --in-place --regexp-extended 's/(^FAST_BOOT=)/\1YES/' PKGBUILD \
&& sed --in-place --regexp-extended 's/(^JIT=)/\1YES/' PKGBUILD \
&& sudo -u "$user" makepkg --noconfirm --syncdeps --install
fi
}
# * Home Config Setup
home_config_setup() { # <user>
echo "Symlinking user config files."
cp "$uhome"/bin/restow /usr/local/bin
pac_install stow \
&& sudo -u "$1" restow
rm /usr/local/bin/restow
}
# * Install Package Managers
# ** Nix
# undecided whether it is a good idea to mix pacman and nix as a lot of
# applications have issues (see OpenGL workarounds in linux packages file)
install_nix_packages() { # <update?>
if ! pacman -Q nix; then
pacman -S nix
sudo -u "$user" nix-channel \
--add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager
sudo -u "$user" nix-channel \
--add http://nixos.org/channels/nixpkgs-unstable nixpkgs
sudo -u "$user" nix-channel \
--add https://github.com/guibou/nixGL/archive/main.tar.gz nixgl
sudo -u "$user" nix-channel --update
systemctl enable nix-daemon
fi
cd "$uhome"/dotfiles/nix || return 1
if [[ $1 == update ]]; then
sudo -u "$user" nix flake update
elif [[ -n $1 ]]; then
sudo -u "$user" nix flake update "$@"
fi
# impure is required to be able to use nixgl
sudo -u "$user" nix run "path:.#homeConfigurations.noct.activationPackage" \
--impure
}
# ** EVM
# have had problems installing evm with gem
install_evm() {
if [[ ! -d "$uhome"/.evm ]]; then
git clone https://github.com/rejeep/evm.git "$uhome"/.evm
fi
}
# ** All
install_installers() {
# TODO install_nix
install_evm
install_package python-pip
install_package ruby
install_package go
install_package npm
install_package "roswell aur" "$user"
}
# * MPV Scripts
# MEH
# NOTE only works with official mpv, not mpv-git
install_internal_mpv_script() { # name script_dir
name=$1
script_dir=$2
mkdir -p "$script_dir"
ln -sf /usr/share/mpv/scripts/"$name" "$script_dir"/
}
install_raw_mpv_script() { # url script_dir
url=$1
script_dir=$2
mkdir -p "$script_dir"
(cd "$script_dir" && curl -O -L -C - "$url")
}
install_mpv_script_from_release() { # url script_dir
url=$1
script_dir=$2
mkdir -p "$script_dir"
curl --silent "$url" | jq --raw-output '.assets[].browser_download_url' \
| while read -r asset; do
(cd "$script_dir" && curl -s -O -L -C - "$asset")
done
}
install_mpv_script() { # url clone_dir script_dir names
url=$1
clone_dir=$2
script_dir=$3
names=$4
if [[ -z $names ]]; then
names='.*\.lua'
fi
mkdir -p "$script_dir"
if [[ -z $clone_dir ]]; then
clone_dir=$(basename "$url" .git)
fi
clone_dir=$script_dir/$clone_dir
if [[ ! -d $clone_dir ]]; then
git -C "$script_dir" clone "$url" "$clone_dir"
fi
find "$clone_dir" -mindepth 1 -type f -regextype posix-extended \
-regex "$names" \
-exec ln -sf {} "$script_dir"/ \;
# if have scripts dir
# find "$clone_dir" -mindepth 2 -type d -iname 'scripts' \
# -exec bash -c 'ln -sf $1/* $2' _ {} "$script_dir" \;
}
install_mpv_scripts() {
echo "Installing mpv scripts and shaders."
# local
ln -sf "$uhome"/src/mpv/mpv-webtorrent-hook \
"$uhome"/.config/mpv/scripts/
ln -sf "$uhome"/src/mpv/mpv-btfs-hook \
"$uhome"/.config/mpv/scripts/
# Git repos
install_mpv_script \
https://github.com/rossy/mpv-repl \
"" \
"$uhome"/.config/mpv/scripts
install_mpv_script \
https://github.com/jgreco/mpv-youtube-quality \
"" \
"$uhome"/.config/mpv/scripts \
".*youtube-quality\.lua"
install_mpv_script \
https://github.com/Eisa01/mpv-scripts \
eisa-mpv-scripts \
"$uhome"/.config/mpv/scripts \
".*(SmartCopyPaste-[0-9.]*\.lua|UndoRedo.*\.lua)"
install_mpv_script \
https://github.com/jonniek/mpv-playlistmanager \
"" \
"$uhome"/.config/mpv/scripts \
".*(playlistmanager|titleresolver)\.lua"
install_mpv_script \
https://github.com/dya-tel/mpv-scripts dya-tel-mpv-scripts \
"$uhome"/.config/mpv/scripts \
".*(reload|fuzzydir)\.lua"
# From Releases
# not making multiple copies; already CPU intensive enough
# not really using
# install_mpv_script_from_release \
# https://api.github.com/repos/TheAMM/mpv_thumbnail_script/releases/latest \
# "$uhome"/.config/mpv/scripts
# Gists
install_raw_mpv_script \
https://gist.githubusercontent.com/Hakkin/4f978a5c87c31f7fe3ae/raw/1d1daf22f0ec5f0219e4e72216e772828f5c8e4c/betterchapters.lua \
"$uhome"/.config/mpv/scripts
# script doesn't work (anymore?)
install_raw_mpv_script \
https://raw.githubusercontent.com/wiiaboo/mpv-scripts/master/audio-balance.lua \
"$uhome"/.config/mpv/scripts
# conditionally loading
nightedt_dir="$uhome"/.config/mpv/scripts/nightedt-mpv-scripts
if [[ ! -d $nightedt_dir ]]; then
git clone https://github.com/nightedt/mpv-scripts \
"$nightedt_dir"
fi
# Shaders
install_mpv_script_from_release \
https://api.github.com/repos/igv/FSRCNN-TensorFlow/releases/latest \
"$uhome"/.config/mpv/shaders
install_mpv_script \
https://github.com/bjin/mpv-prescalers \
"" \
"$uhome"/.config/mpv/shaders \
".*nnedi3-nns64-win8x4\.hook"
install_mpv_script \
https://github.com/bloc97/Anime4K \
"" \
"$uhome"/.config/mpv/shaders \
".*Anime4K_Adaptive_v1\.0RC2\.glsl"
# fix permissions
chown -R "$user":"$user" "$uhome"/.config/mpv/{scripts,shaders}
}
# * Salt
setup_salt() {
pac_install salt
# clear previous files; fine if fails
rm -r /srv/salt &> /dev/null
mkdir -p /srv/salt
# cd to the directory of this script
cd "$basedir" || exit 1
cp ./top.sls /srv/salt
cp ./user_groups.sls /srv/salt
cp ./root_config.sls /srv/salt
cp ./packages.sls /srv/salt
cp ./pre_service_setup.sls /srv/salt
cp ./services.sls /srv/salt
cp ./setup.sls /srv/salt
cp ./extra-setup /srv/salt
# TODO xdg used for user services
# I don't think display is used at all
# nor is dbus... can probably remvoe all of these
sed -i -e "s/set user =/set user = '$user'/g" /srv/salt/setup.sls
# sed -i -e "s/set user =/set user = '$user'/g" \
# -e "s;set xdg =;set xdg = '$XDG_RUNTIME_DIR';g" \
# -e "s/set display =/set display = '$DISPLAY'/g" \
# -e "s;set dbus =;set dbus = '$DBUS_SESSION_BUS_ADDRESS';g" \
# /srv/salt/setup.sls
cp -r ./etc /srv/salt
cp -r ./boot /srv/salt
cp -r ./usr /srv/salt
cp -r ./var /srv/salt
# can't use alternative separator here
sed -i "/^ *\//d" \
/srv/salt/var/lib/transmission/.config/transmission-daemon/settings.json
# overwrite any example configuration files
cp -r ../.root/etc /srv/salt
}
generate_packages_sls() {
# TODO alternatively could use templating for each package type:
# https://docs.saltstack.com/en/latest/topics/tutorials/states_pt3.html
# shellcheck disable=SC2188
> "$basedir"/packages.sls
while read -r line; do
if [[ -z $line ]] || [[ $line =~ \# ]]; then
continue
fi
package=$(echo "$line" | awk '{print $1}')
method=$(echo "$line" | awk '{print $2}')
method=${method:-pac}
nix_path=$(echo "$line" | awk '{print $3}')
echo "$package-pkg:" >> "$basedir"/packages.sls
# if [[ $method == pac ]]; then
# echo " pkg.installed:
# - pkgs:
# - $package
# " >> "$basedir"/packages.sls
if [[ $method == pac ]]; then
echo " cmd.run:
- name: pacman --noconfirm -S $package
- unless: pacman -Q $package
" >> "$basedir"/packages.sls
elif [[ $method == aur ]]; then
echo " cmd.run:
- name: paru --noconfirm -S $package
- unless: pacman -Q $package
- runas: $builduser
" >> "$basedir"/packages.sls
elif [[ $method == nix ]]; then
# TODO -require? install nix where?
echo " cmd.run:
- runas: $user
- name: nix-env -iA $nix_path
- unless: nix-env -q $package
" >> "$basedir"/packages.sls
elif [[ $method == ros ]]; then
echo " cmd.run:
- name: ros install $package
- unless: ros list installed | grep $package
- require:
- roswell-pkg
" >> "$basedir"/packages.sls
elif [[ $method == pip ]]; then
echo " cmd.run:
- name: pip install $package
- unless: pip list | grep ^$package
- require:
- python-pip-pkg
" >> "$basedir"/packages.sls
elif [[ $method == gem ]]; then
echo " cmd.run:
- runas: $user
- name: $method install $package
- unless: gem list -i \"^$package\$\"
- require:
- ruby-pkg
" >> "$basedir"/packages.sls
elif [[ $method == go ]]; then
echo " cmd.run:
- runas: $user
- name: $method get $package
- unless: go list '...' | grep $package
- require:
- go-pkg
" >> "$basedir"/packages.sls
elif [[ $method == evm ]]; then
# - require:
# - $method-pkg
# - runas: $user
echo " cmd.run:
- name: $uhome/.evm/bin/evm install $package
- unless: $uhome/.evm/bin/evm list | grep \"$package \[I\]\"
" >> "$basedir"/packages.sls
elif [[ $method == npm ]]; then
# currently only using for commands and npm list is weird
echo " cmd.run:
- name: npm install -g $package
- unless: npm --global --depth 0 list | grep --quiet $package
- require:
- $method-pkg
" >> "$basedir"/packages.sls
fi
done < "$basedir"/packages
}
# * No Salt
# ** User Groups
update_user_groups() { # <user>
local user
user=$1
echo "Updating ${user}'s groups."
# https://wiki.archlinux.org/index.php/users_and_groups#Group_list
usermod --groups users,wheel,uucp,games,lock,input,uinput,kvm,libvirt,nix-users \
--append "$user"
}
validate_user() { # <user>
local user
user=$1
if ! id -u "$user"; then
echo "Please create $user:
- useradd --create-home $user
- passwd $user
Note that this script will take care of adding the user to groups."
exit 1
fi
if [[ "$(passwd --status "$user" | awk '{print $2}')" == NP ]]; then
echo "Please give $user a password
- passwd $user"
exit 1
fi
}
share_directory_with_secondary_user() { # <dirname under home> <user2> <git repo?>
local name dir user2 uhome2
name=$1
dir=$uhome/$name
user2=$2
uhome2=/home/$user2
chown -R :users "$dir"
find "$dir" -exec chmod g=u {} +
# set sgid bit to ensure newly created files in dir get "users" as the group
find "$dir" -type d -exec chmod g+s "$dir" {} +
# set default permissions for group to be same as user
setfacl -R -d -m g::rwX "$dir"
ln -sf "$dir" "$uhome2/"
# change symlink permissions
chown --no-dereference "$user2":"$user2" "$uhome2/$name"
# just store manually in .gitconfig in this repo
# if [[ -n $git ]]; then
# sudo -u "$user2" git config --global --add safe.directory "$dir"
# fi
}
configure_secondary_user() { # <user>
local user2
user2=$1
uhome2=/home/$user2
validate_user "$user2"
update_user_groups "$user2"
# hide primary user's files from secondary users
# leave x bit to allow cd into (so can have rwx permissions on some
# subdirectories)
chmod 710 "$uhome"
chown :users "$uhome"
# share dotfiles directory with secondary user
share_directory_with_secondary_user dotfiles "$user2" true
# create straight before stow to prevent Emacs packages from being installed
# in main user's dotfiles directory
sudo -u "$user2" mkdir -p "$uhome2"/.emacs.d/straight
# prevent new profile from being stored in dotfiles (user.normal is correct,
# not user2)
sudo -u "$user2" mkdir -p \
"$uhome2"/.mozilla/firefox/"$user".normal/chorme/_userChrome.css
sudo -u "$user2" mkdir -p "$uhome2"/.config/fcitx
sudo -u "$user2" mkdir -p "$uhome2"/.config/ranger/plugins
# remove default bashrc to prevent conflict with restow
rm -f "uhome2"/.bashrc
# symlink dotfiles with stow
home_config_setup "$user2"
# set up wallpaper
sudo -u "$user2" mkdir -p "$uhome2"/.config/setroot
cp "$uhome"/wallpaper/secondary "$uhome2"/wallpaper_image
echo "setroot '--zoom' '$uhome2/wallpaper_image'" > \
"$uhome2"/.config/setroot/.setroot-restore
chown "$user2":"$user2" "$uhome2"/.config/setroot/.setroot-restore
chmod +x "$uhome2"/.config/setroot/.setroot-restore
echo "
- Manually run \"walset /home/$user2/wallpaper_image\" as $user2 to set up pywal
- Install firefox plugins
- Run :installnative in firefox after installing tridactyl
- Prefix I in tmux to install plugins
- Future work:
- run home-manager for different user
- Gruvbox wallpaper and theme?
- Separate git config/signing setup"
}
# ** Copy Root Config files
copy_root_config_files() {
echo "Copying root config files from dotfiles to /."
# must be mounted before try to copy refind.conf over
if ! mountpoint -q /boot/efi; then
mount LABEL=SYSTEM /boot/efi
fi
if ! mountpoint -q /boot/efi; then
echo "Please mount ESP partition, so refind.conf can be copied to it."
exit 1
fi
cp -R "$basedir"/boot "$basedir"/etc "$basedir"/usr "$basedir"/var /
# remove comments
sed -i "/^ *\//d" \
/var/lib/transmission/.config/transmission-daemon/settings.json
}
# ** Package Installation
install_package() {
line=$1
package=$(echo "$line" | awk '{print $1}')
method=$(echo "$line" | awk '{print $2}')
method=${method:-pac}
nix_path=$(echo "$line" | awk '{print $3}')
if [[ $method == pac ]]; then
pac_install "$package"
elif [[ $method == aur ]]; then
if ! pacman --query "$package" &> /dev/null; then
echo "Installing $package."
sudo -u "$builduser" paru --noconfirm -S "$package" \
|| fail_echo "Failed: sudo -u \"$builduser\" paru --noconfirm -S $package"
fi
elif [[ $method == nix ]]; then
if ! nix-env --query "$package"; then
echo "Installing $package."
nix-env -iA "$nix_path" \
|| fail_echo "Failed: nix-env -iA $nix_path"
fi
elif [[ $method == ros ]]; then
if ! ros list installed | grep --quiet "$package"; then
echo "Installing $package."
ros install "$package" \
|| fail_echo "Failed: ros install $package"
fi
elif [[ $method == pip ]]; then
if ! pip list | grep --quiet "^$package"; then
echo "Installing $package."
pip install "$package" \
|| fail_echo "Failed: pip install $package"
fi
elif [[ $method == gem ]]; then
if ! gem list --installed "^$package$" &> /dev/null; then
echo "Installing $package."
gem install "$package" \
|| fail_echo "Failed: gem install $package"
fi
elif [[ $method == go ]]; then
if ! go list '...' | grep --quiet "$package"; then
echo "Installing $package."
go get "$package" \
|| fail_echo "Failed: go get $package"
fi
elif [[ $method == evm ]]; then
if ! evm list | grep --quiet "$package [I]"; then
echo "Installing $package."
PATH="$uhome/.evm/bin:$PATH" evm install "$package" \
|| fail_echo "Failed: evm install $package"
fi
elif [[ $method == npm ]]; then
if ! npm --global --depth 0 list | grep --quiet "$package"; then
echo "Installing $package."
npm install --global "$package" \
|| fail_echo "Failed: npm install --global $package"
fi
fi
}
install_packages() {
echo "Installing packages."
while read -r line; do
if [[ -z $line ]] || [[ $line =~ \# ]]; then
continue
fi
install_package "$line"
done < "$basedir"/packages
install_emacs_lucid
}
# ** Program Configuration
configure_packages() {
echo "Configuring packages."
"$basedir"/extra-setup all "$user"
}
# ** Nix User Packages (Home Manager)
nix_user_setup() {
home-manager switch --flake '<flake-uri>#jdoe'
}
# * Main
default() {
validate_user "$user"
echo "Prerequisites:
- Inside chroot (or on existing installation that should be updated)
- Internet connection
- Base system has already been installed (system-install)
- $user has been created (give the user a password before rebooting)
- /home/\$user/dotfiles is in place and up to date
- Extra keys have been signed (check these are up to date) (see ./pacman-keys)
Current variables:
- Timezone: $timezone
- Hostname: $hostname
- Username: $user
- Log level: $log_level
- Using salt?: $use_salt
- Force reflector update?: $force_reflector
Please make sure that the ESP is already mounted under /boot/efi if installing a
new system.
For more information, rerun with --help flag.
See $log and $failure_log for info after run."
prompt_continue
echo "Performing basic setup..."
sudo_setup || fail_echo "Failed to update sudo configuration."
time_setup || fail_echo "Failed to update timezone/clock."
locale_setup || fail_echo "Failed to update locale configuration."
hostname_setup || fail_echo "Failed to set hostname."
home_config_setup "$user" || fail_echo "Failed to setup dotfiles with stow."
update_mirror_list || fail_echo "Failed to update pacman mirror list."
if ! install_paru; then
fail_echo "Failed to install paru. Aborting."
exit 1
fi
install_installers
if $use_salt; then
echo "Installing and running salt."
generate_packages_sls
setup_salt
salt-call --log-level "$log_level" --local state.apply
else
update_user_groups "$user" || fail_echo "Failed to update user groups."
copy_root_config_files || fail_echo "Failed to copy root config files."
install_packages
install_nix_packages
install_mpv_scripts
configure_packages
fi
if is_chroot; then
echo "Chroot detected. To finish installation, reboot and run this
script again with --enable-services."
fi
}
if [[ $EUID -ne 0 ]]; then
echo "Please run this script as root."
exit 1
fi
# shellcheck disable=SC2188
> "$failure_log"
case $1 in
non-chroot) "$basedir"/extra-setup non_chroot "$user";;
root-config) copy_root_config_files;;
# SEE ./boot/README.org for bootloader troubleshooting steps
fix|refind|boot) copy_root_config_files \
&& "$basedir"/extra-setup refind_setup \
&& "$basedir"/extra-setup initramfs_setup;;
systemd-boot) copy_root_config_files \
&& "$basedir"/extra-setup systemd_boot_setup \
&& "$basedir"/extra-setup initramfs_setup;;
user) configure_secondary_user "$2";;
emacs) install_emacs_lucid true;;
nix) install_nix_packages "$2";;
*) default 2>&1 | tee "$log";;
esac