-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinux-setup.sh
More file actions
executable file
·1614 lines (1401 loc) · 54.5 KB
/
linux-setup.sh
File metadata and controls
executable file
·1614 lines (1401 loc) · 54.5 KB
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
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Linux Setup Script
# Configures a fresh Kali Linux / Debian / Ubuntu installation with development tools and customizations
set -eo pipefail
VERSION="1.3"
FORCE_MODE=false
NO_MODE=false
NO_HACKING_TOOLS=false
HARDEN_ONLY=false
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Show usage information
show_usage() {
cat << EOF
Linux Setup Script v${VERSION}
Configures a fresh Debian/Kali Linux installation with development tools and customizations
Usage: $0 [OPTIONS]
Options:
--force, -f Run in non-interactive mode, automatically answering 'Yes' to all prompts
--yes, -y Same as --force
--no, -n Run in non-interactive mode, automatically answering 'No' to all prompts
--no-hacking-tools Skip installation of hacking/pentest tools (even on Kali)
--harden-only Apply only supply-chain hardening configs (no installs, no shell changes)
--help, -h Display this help message and exit
Interactive Mode (default):
The script will prompt for confirmation on certain actions:
- Overwriting existing .zshrc configuration
- Changing default shell to zsh
- Overwriting existing Terminator configuration
- Configuring German keyboard layout in XFCE
Force/Yes Mode (--force, --yes, -f, -y):
All prompts are automatically answered 'Yes'. Useful for:
- Automated/unattended installations
- CI/CD pipelines
- Re-running the script to get updates without manual intervention
No Mode (--no, -n):
All prompts are automatically answered 'No'. Useful for:
- Installing packages without overwriting existing configurations
- Running the script but skipping optional configurations
Harden-Only Mode (--harden-only):
Applies supply-chain hardening configs without installing any packages.
Writes package manager configs (npm, Bun, Cargo, uv, pip), system-level
fallbacks, telemetry opt-outs, and Go module hardening env vars.
Useful for hardening existing systems without a full setup run.
Examples:
$0 # Interactive installation
$0 --force # Non-interactive installation (answer Yes to all)
$0 --yes # Same as --force
$0 --no # Non-interactive installation (answer No to all)
$0 --harden-only # Apply supply-chain hardening configs only
EOF
exit 0
}
# Preserve original args before parsing consumes them via shift.
# Used by self-update (exec "$0") to re-run with the same flags.
ORIGINAL_ARGS=("$@")
# Parse command-line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--force|-f|--yes|-y)
FORCE_MODE=true
shift
;;
--no|-n)
NO_MODE=true
shift
;;
--no-hacking-tools)
NO_HACKING_TOOLS=true
shift
;;
--harden-only)
HARDEN_ONLY=true
shift
;;
--help|-h)
show_usage
;;
*)
echo -e "${RED}Error: Unknown option '$1'${NC}"
echo "Use --help for usage information"
exit 1
;;
esac
done
# Logging function
log() {
echo -e "${GREEN}[$(date +'%Y-%m-%d %H:%M:%S')] $1${NC}"
}
warn() {
echo -e "${YELLOW}[WARNING] $1${NC}"
}
error() {
echo -e "${RED}[ERROR] $1${NC}"
exit 1
}
# Check if running as root
if [[ $EUID -eq 0 ]]; then
warn "This script should normally not be run as root. Please run as a regular user with sudo privileges."
fi
# Check if we're on a Debian-based system (hard requirement)
if ! grep -qE "(debian|ID_LIKE.*debian)" /etc/os-release 2>/dev/null; then
error "This script requires a Debian-based Linux distribution. Detected system is not compatible."
fi
# Backup a file with timestamp
backup_file() {
local file_path="$1"
if [ -f "$file_path" ]; then
local backup_path="${file_path}.backup.$(date +'%Y-%m-%d_%H-%M-%S')"
cp "$file_path" "$backup_path"
log "Backed up to: $backup_path"
fi
}
# Prompt user with yes/no question
# Usage: prompt_yes_no "Question?" "Y" (or "N" for default No)
# Returns: 0 for yes, 1 for no
prompt_yes_no() {
local prompt="$1"
local default="$2"
local response
# In force mode, automatically answer yes
if [[ "$FORCE_MODE" == "true" ]]; then
log "Force mode: Auto-answering 'Yes' to: $prompt"
return 0
fi
# In no mode, automatically answer no
if [[ "$NO_MODE" == "true" ]]; then
log "No mode: Auto-answering 'No' to: $prompt"
return 1
fi
if [[ "$default" == "Y" ]]; then
read -p "$prompt (Y/n): " response
response=${response:-Y}
else
read -p "$prompt (y/N): " response
response=${response:-N}
fi
if [[ "$response" =~ ^[Yy]$ ]]; then
return 0
else
return 1
fi
}
# Check if we're on Kali Linux (preferred but not required)
is_kali_linux() {
grep -q "Kali" /etc/os-release 2>/dev/null
}
# Check if we're on Ubuntu or Ubuntu-based distribution
is_ubuntu() {
if [ -f /etc/os-release ]; then
. /etc/os-release
[ "$ID" = "ubuntu" ] || [ "$ID_LIKE" = "ubuntu" ] || echo "$ID_LIKE" | grep -q "ubuntu"
else
return 1
fi
}
# Update or add a single export in ~/.profile (idempotent)
# Uses grep to check existence, sed to update in place, or appends if new
#
# Usage: update_profile_export <var_name> <var_value>
# var_name: Environment variable name (e.g., DO_NOT_TRACK)
# var_value: Value to set (will be quoted in the export)
#
# Returns: 0 on success
update_profile_export() {
local var_name="$1"
local var_value="$2"
local profile_file="$HOME/.profile"
# Create file if it doesn't exist
[ ! -f "$profile_file" ] && touch "$profile_file"
# Escape special characters for shell double-quoted string:
# - Backslashes must be escaped first (before other escapes add more)
# - Double quotes, dollar signs, and backticks need escaping
local escaped_value="$var_value"
escaped_value="${escaped_value//\\/\\\\}" # \ -> \\
escaped_value="${escaped_value//\"/\\\"}" # " -> \"
escaped_value="${escaped_value//\$/\\\$}" # $ -> \$
escaped_value="${escaped_value//\`/\\\`}" # ` -> \`
# For sed replacement, also escape & (special in replacement string)
local sed_value="$escaped_value"
sed_value="${sed_value//&/\\&}" # & -> \&
if grep -q "^export ${var_name}=" "$profile_file" 2>/dev/null; then
# Update existing export in place
sed -i "s|^export ${var_name}=.*|export ${var_name}=\"${sed_value}\"|" "$profile_file"
else
# Append new export
echo "export ${var_name}=\"${escaped_value}\"" >> "$profile_file"
fi
}
# Ensure ~/.zprofile sources ~/.profile for ZSH compatibility
# ZSH doesn't read ~/.profile by default, so we add a source line
# This is idempotent - only adds the line if not already present
# Skips on Kali Linux (already sources .profile in default .zshrc)
#
# Usage: ensure_zprofile_sources_profile
ensure_zprofile_sources_profile() {
# Kali Linux already sources .profile in its default ZSH config
is_kali_linux && return 0
local zprofile="$HOME/.zprofile"
local source_line='[[ -f ~/.profile ]] && emulate sh -c "source ~/.profile"'
# Create file if it doesn't exist
[ ! -f "$zprofile" ] && touch "$zprofile"
# Add source line if not present (using fixed string match)
if ! grep -qF "$source_line" "$zprofile" 2>/dev/null; then
echo "" >> "$zprofile"
echo "# Source ~/.profile for environment variables (added by linux-setup)" >> "$zprofile"
echo "$source_line" >> "$zprofile"
fi
}
# Apply all supply-chain hardening configurations
# Writes package manager configs (user-level + system-level fallbacks),
# telemetry opt-outs, and Go module hardening environment variables.
# Safe to call on systems where tools are not yet installed.
apply_supply_chain_hardening() {
log "Applying supply-chain hardening configurations..."
# --- npm hardening (user-level) ---
# Protects against npm being invoked directly or installed later;
# bun already blocks lifecycle scripts via trustedDependencies model
log "Configuring npm security hardening..."
cat > "$HOME/.npmrc" << 'EOF'
ignore-scripts=true
save-exact=true
audit=true
fund=false
min-release-age=10080
EOF
# --- Bun hardening (user-level) ---
log "Configuring Bun security hardening..."
cat > "$HOME/.bunfig.toml" << 'EOF'
[install]
exact = true
saveTextLockfile = true
minimumReleaseAge = 604800
EOF
# --- Cargo hardening (user-level, preserve existing) ---
log "Configuring Cargo security hardening..."
mkdir -p "$HOME/.cargo"
if [ ! -f "$HOME/.cargo/config.toml" ]; then
cat > "$HOME/.cargo/config.toml" << 'EOF'
[net]
git-fetch-with-cli = true
EOF
fi
# --- Python package manager hardening (user-level) ---
log "Configuring Python package manager hardening..."
mkdir -p "$HOME/.config/uv" "$HOME/.config/pip"
cat > "$HOME/.config/uv/uv.toml" << 'EOF'
exclude-newer = "1 week"
native-tls = true
python-preference = "system"
EOF
cat > "$HOME/.config/pip/pip.conf" << 'EOF'
[global]
prefer-binary = true
[install]
prefer-binary = true
EOF
# --- System-level fallback configs (defence-in-depth) ---
# If user deletes their dotfiles, system defaults still enforce hardening
log "Deploying system-level fallback configs..."
if sudo -n true 2>/dev/null; then
sudo mkdir -p /usr/local/etc /etc/uv
sudo tee /usr/local/etc/npmrc > /dev/null << 'EOF'
ignore-scripts=true
save-exact=true
audit=true
fund=false
min-release-age=10080
EOF
sudo tee /etc/uv/uv.toml > /dev/null << 'EOF'
exclude-newer = "1 week"
native-tls = true
python-preference = "system"
EOF
sudo tee /etc/pip.conf > /dev/null << 'EOF'
[global]
prefer-binary = true
[install]
prefer-binary = true
EOF
log "System-level fallback configs deployed"
else
warn "Could not obtain passwordless sudo - skipping system-level fallback configs"
fi
# --- Telemetry/Privacy opt-outs ---
log "Setting privacy/telemetry environment defaults..."
# Universal opt-out signal (proposed standard)
update_profile_export "DO_NOT_TRACK" "1"
# VS Code / .NET / PowerShell / Azure
update_profile_export "VSCODE_TELEMETRY_DISABLE" "1"
update_profile_export "VSCODE_CRASH_REPORTER_DISABLE" "1"
update_profile_export "DOTNET_CLI_TELEMETRY_OPTOUT" "1"
update_profile_export "POWERSHELL_TELEMETRY_OPTOUT" "1"
update_profile_export "AZURE_CORE_COLLECT_TELEMETRY" "0"
# Python packaging tools
update_profile_export "PYPI_DISABLE_TELEMETRY" "1"
update_profile_export "UV_NO_TELEMETRY" "1"
update_profile_export "SCARF_ANALYTICS" "false"
# Go module supply-chain hardening
update_profile_export "GOPROXY" "https://proxy.golang.org,off"
update_profile_export "GOSUMDB" "sum.golang.org"
update_profile_export "GONOSUMCHECK" ""
# Ensure ZSH sources ~/.profile on non-Kali systems
ensure_zprofile_sources_profile
log "Supply-chain hardening complete"
}
# Check if desktop environment is available
has_desktop_environment() {
# Check for desktop session files (most reliable)
if [ -d /usr/share/xsessions ] && [ -n "$(ls -A /usr/share/xsessions 2>/dev/null)" ]; then
return 0
fi
if [ -d /usr/share/wayland-sessions ] && [ -n "$(ls -A /usr/share/wayland-sessions 2>/dev/null)" ]; then
return 0
fi
# Check for display manager configuration
if [ -f /etc/X11/default-display-manager ] && [ -s /etc/X11/default-display-manager ]; then
return 0
fi
# Check for common DE packages (Kali uses XFCE)
if dpkg -l 2>/dev/null | grep -qE '^ii\s+(xfce4|gnome-shell|kde-plasma-desktop|plasma-desktop|lxde-core)'; then
return 0
fi
return 1
}
# Get installed Go version as comparable number
# Returns version in format: 1.19 -> 119, 1.24 -> 124
get_go_version() {
if ! command -v go &> /dev/null; then
echo "0"
return
fi
local go_version=$(go version 2>/dev/null | grep -oP 'go\K[0-9]+\.[0-9]+' | head -1 || true)
if [ -z "$go_version" ]; then
echo "0"
return
fi
# Convert to comparable number (e.g., "1.19" -> 119, "1.24" -> 124)
echo "$go_version" | awk -F. '{print ($1 * 100) + $2}'
}
# Install Go tool
# Usage: install_go_tool <tool-name> <go-package-path>
install_go_tool() {
local tool_name="$1"
local package_path="$2"
if ! command -v "$tool_name" &> /dev/null; then
log "Installing ${tool_name}..."
else
log "Updating ${tool_name}..."
fi
export PATH=$HOME/go/bin:$PATH
export GOPROXY="https://proxy.golang.org,off"
export GOSUMDB="sum.golang.org"
export GONOSUMCHECK=""
go install -v "$package_path"
}
# Install Rust via rustup
install_rust_via_rustup() {
log "Installing Rust via rustup (official Rust installer)..."
# Download and run rustup-init
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
# Source cargo environment for this script
export CARGO_HOME="$HOME/.cargo"
export RUSTUP_HOME="$HOME/.rustup"
export PATH="$CARGO_HOME/bin:$PATH"
if [ -f "$HOME/.cargo/env" ]; then
source "$HOME/.cargo/env" || true
fi
log "Rust installed successfully via rustup"
}
if ! is_kali_linux; then
warn "This script is primarily designed for Kali Linux. Continuing anyway..."
fi
#############################################################################
# PHASE 0: Self-Update
#############################################################################
log "Checking for script updates..."
# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
if git rev-parse --git-dir > /dev/null 2>&1; then
log "Git repository detected, checking for updates..."
# Fetch latest changes
git fetch origin 2>/dev/null || true
# Count commits we don't have that remote has
BEHIND=$(git rev-list HEAD..@{u} 2>/dev/null | wc -l || echo "0")
if [ "$BEHIND" -gt 0 ]; then
log "Updates found! Pulling latest changes..."
git pull --ff-only
log "Re-executing updated script..."
exec "$0" "${ORIGINAL_ARGS[@]}" || error "Failed to re-execute updated script"
else
log "Script is up to date"
fi
else
warn "Not running from a git repository. Self-update disabled."
fi
# --harden-only: apply supply-chain hardening and exit (no installs)
if [[ "$HARDEN_ONLY" == "true" ]]; then
log "Running in harden-only mode (no package installs, no shell changes)"
apply_supply_chain_hardening
log "Harden-only mode complete!"
exit 0
fi
#############################################################################
# PHASE 1: System Setup
#############################################################################
log "Starting Linux setup..."
# Update package lists and upgrade system
log "Updating package lists and upgrading system..."
sudo apt-get update
sudo apt-get dist-upgrade -y
# Install essential packages
log "Installing essential packages..."
sudo apt-get install -y \
ca-certificates \
build-essential \
curl \
wget \
unzip \
git \
fzf \
tree \
hstr \
bubblewrap \
ripgrep \
fd-find \
moreutils \
unp \
htop \
ncdu \
lsof \
jq \
bat \
exiftool \
libpcap-dev \
ufw \
python3-dev \
python3-pip \
python3-venv \
golang \
zsh \
zsh-autosuggestions \
zsh-syntax-highlighting
# Install Rust - either from repo (if >= 1.85) or via rustup
log "Checking Rust version in repositories..."
REPO_RUST_VERSION=$(apt-cache policy rustc 2>/dev/null | grep -oP 'Candidate:\s*\K[0-9]+\.[0-9]+' | head -1 || true)
if [ -z "$REPO_RUST_VERSION" ]; then
REPO_RUST_VERSION="0.0"
warn "Could not determine repository Rust version"
fi
# Convert version to comparable number (e.g., "1.85" -> 185)
REPO_RUST_VERSION_NUM=$(echo "$REPO_RUST_VERSION" | awk -F. '{print ($1 * 100) + $2}')
MINIMUM_RUST_VERSION=185 # Rust 1.85 minimum for modern tools
log "Repository has Rust version: $REPO_RUST_VERSION (numeric: $REPO_RUST_VERSION_NUM, minimum required: $MINIMUM_RUST_VERSION)"
if ! command -v cargo &> /dev/null; then
# Rust not installed - choose installation method based on repo version
if [ "$REPO_RUST_VERSION_NUM" -ge "$MINIMUM_RUST_VERSION" ]; then
log "Installing Rust from repositories (version $REPO_RUST_VERSION)..."
sudo apt-get install -y cargo rustc
else
log "Repository version $REPO_RUST_VERSION is < 1.85, installing Rust via rustup..."
install_rust_via_rustup
fi
else
if command -v rustup &> /dev/null; then
log "Updating Rust via rustup..."
rustup update stable
else
log "Rust is already installed (apt-managed, updated via dist-upgrade)"
fi
fi
# Install Bun (JavaScript/TypeScript runtime, package manager, drop-in Node.js replacement)
log "Installing Bun..."
if ! command -v bun &> /dev/null; then
curl --proto '=https' --tlsv1.2 -fsSL https://bun.com/install | bash
# Source bun environment for this script
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
log "Bun installed successfully"
else
log "Updating Bun..."
bun upgrade
fi
# Create node/npx symlinks pointing to bun for Node.js drop-in compatibility
# Bun only auto-symlinks node temporarily during `bun run` (in /tmp/bun-node/);
# these permanent symlinks make `node` and `npx` work system-wide for scripts,
# shebangs (#!/usr/bin/env node), and tools that invoke node/npx directly.
# Note: npm is NOT symlinked — bun's package manager uses its own CLI interface
# (bun install, bun add, etc.) and does not emulate npm's command set when
# invoked as "npm".
log "Setting up Node.js compatibility symlinks for Bun..."
BUN_BIN="${BUN_INSTALL:-$HOME/.bun}/bin"
if [ -x "$BUN_BIN/bun" ]; then
ln -sf "$BUN_BIN/bun" "$BUN_BIN/node"
ln -sf "$BUN_BIN/bunx" "$BUN_BIN/npx"
log "Created node, npx symlinks in $BUN_BIN"
else
warn "Bun binary not found at $BUN_BIN/bun, skipping Node.js compatibility symlinks"
fi
#############################################################################
# Package Manager Supply-Chain Hardening
#############################################################################
apply_supply_chain_hardening
# Install GUI applications if desktop environment is available
if has_desktop_environment; then
log "Desktop environment detected - installing GUI applications"
sudo apt-get install -y \
gedit \
gedit-plugins \
fonts-firacode \
terminator \
meld \
xsel
# Configure GTK terminal padding
log "Configuring GTK terminal padding..."
mkdir -p ~/.config/gtk-3.0
cat > ~/.config/gtk-3.0/gtk.css << 'EOF'
VteTerminal, TerminalScreen, vte-terminal {
padding: 8px 8px 8px 8px; /* Top Right Bottom Left */
-VteTerminal-inner-border: 8px 8px 8px 8px; /* Older versions might need this */
}
EOF
else
log "No desktop environment detected - skipping GUI applications"
fi
# Install Kali-specific package - only install on Kali Linux
if is_kali_linux && [ "$NO_HACKING_TOOLS" != true ]; then
log "Installing hacking tools..."
sudo apt-get install -y massdns mitmproxy || true
else
warn "Skipping hacking tools installation"
fi
# Install pipx (Python application installer)
log "Installing pipx..."
if ! command -v pipx &> /dev/null; then
#python3 -m pip install --user pipx
sudo apt-get install -y pipx
else
log "pipx is already installed"
fi
# Install uv (modern Python package installer)
log "Installing uv..."
export PATH=$HOME/.local/bin:$PATH
if ! command -v uv &> /dev/null; then
pipx install uv
else
log "Updating uv..."
pipx upgrade uv 2>/dev/null || pipx install --force uv
fi
# Install Python tools with uv
log "Installing Python tools with uv..."
if command -v uv &> /dev/null; then
uv tool install --force httpie
uv tool install --force name-that-hash
uv tool install --force tldr
else
warn "uv not available, skipping Python tools installation"
fi
# Install Docker CE
log "Installing Docker CE..."
if ! command -v docker &> /dev/null; then
# Remove conflicting packages
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove -y "$pkg" || true; done
# Detect distribution and codename
if is_ubuntu; then
. /etc/os-release
DOCKER_DISTRO="ubuntu"
DOCKER_CODENAME="${UBUNTU_CODENAME:-$VERSION_CODENAME}"
# Validate against supported Ubuntu versions
case "$DOCKER_CODENAME" in
questing|noble|jammy)
# Officially supported Ubuntu versions (25.10, 24.04 LTS, 22.04 LTS)
;;
*)
log "Warning: Ubuntu codename '$DOCKER_CODENAME' is not officially supported by Docker. Falling back to Trixie."
DOCKER_DISTRO="debian"
DOCKER_CODENAME="trixie"
;;
esac
elif [ -f /etc/os-release ]; then
. /etc/os-release
if [ "$ID" = "debian" ] || [ "$ID" = "kali" ] || echo "$ID_LIKE" | grep -q "debian"; then
DOCKER_DISTRO="debian"
DOCKER_CODENAME="$VERSION_CODENAME"
# Validate against supported Debian versions
case "$DOCKER_CODENAME" in
trixie|bookworm|bullseye)
# Officially supported Debian versions (13, 12, 11)
;;
kali-rolling)
# Kali uses Debian repos, default to trixie
DOCKER_CODENAME="trixie"
;;
*)
log "Warning: Debian codename '$DOCKER_CODENAME' is not officially supported by Docker. Falling back to Trixie."
DOCKER_CODENAME="trixie"
;;
esac
else
log "Warning: Unknown distribution '$ID'. Falling back to Debian Trixie."
DOCKER_DISTRO="debian"
DOCKER_CODENAME="trixie"
fi
else
log "Warning: Cannot detect distribution. Falling back to Debian Trixie."
DOCKER_DISTRO="debian"
DOCKER_CODENAME="trixie"
fi
log "Using Docker repository: $DOCKER_DISTRO/$DOCKER_CODENAME"
# Add Docker's official GPG key
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl --proto '=https' --tlsv1.2 -fsSL https://download.docker.com/linux/$DOCKER_DISTRO/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/$DOCKER_DISTRO $DOCKER_CODENAME stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Install Docker CE and components
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# Enable and start Docker service
sudo systemctl enable docker || true
sudo systemctl start docker || true
log "Docker CE installed and started successfully. You'll need to log out and back in for group changes to take effect."
else
log "Docker is already installed"
fi
# Configure Docker group and permissions
log "Configuring Docker group and permissions..."
sudo groupadd docker 2>/dev/null || true
sudo usermod -aG docker "$USER"
if [[ -d "$HOME/.docker" ]]; then
sudo chown "$USER":"$USER" "$HOME/.docker" -R
sudo chmod g+rwx "$HOME/.docker" -R
fi
# Install Visual Studio Code
if has_desktop_environment; then
log "Installing Visual Studio Code..."
if ! command -v code &> /dev/null; then
sudo apt-get install -y gpg
curl --proto '=https' --tlsv1.2 -fsSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > /tmp/microsoft.gpg
sudo install -m 644 /tmp/microsoft.gpg /usr/share/keyrings/microsoft.gpg
rm -f /tmp/microsoft.gpg
# Create VSCode sources file
sudo tee /etc/apt/sources.list.d/vscode.sources > /dev/null << 'EOF'
Types: deb
URIs: https://packages.microsoft.com/repos/code
Suites: stable
Components: main
Architectures: amd64,arm64,armhf
Signed-By: /usr/share/keyrings/microsoft.gpg
EOF
sudo apt-get install -y apt-transport-https
sudo apt-get update
sudo apt-get install -y code
else
log "Visual Studio Code is already installed"
fi
else
log "No desktop environment detected - skipping Visual Studio Code installation"
fi
# Install up tool
install_go_tool "up" "github.com/akavel/up@latest"
sudo cp "$HOME/go/bin/up" /usr/local/bin/ 2>/dev/null || true
# Configure AppArmor to allow bwrap to create user namespaces
# Ubuntu 24.04+ restricts unprivileged user namespaces via AppArmor by default,
# which breaks bwrap sandboxing (used by the 'up' and 'polster' aliases)
if command -v apparmor_parser &> /dev/null && \
[ -d /sys/module/apparmor ] && \
[ -f /proc/sys/kernel/apparmor_restrict_unprivileged_userns ] && \
[ "$(cat /proc/sys/kernel/apparmor_restrict_unprivileged_userns)" = "1" ] && \
[ ! -f /etc/apparmor.d/bwrap ]; then
log "Configuring AppArmor profile for bwrap..."
if sudo tee /etc/apparmor.d/bwrap > /dev/null <<'APPARMOR'
abi <abi/4.0>,
include <tunables/global>
profile bwrap /usr/bin/bwrap flags=(unconfined) {
userns,
include if exists <local/bwrap>
}
APPARMOR
then
sudo apparmor_parser -r /etc/apparmor.d/bwrap || warn "Failed to load AppArmor bwrap profile"
else
warn "Failed to write AppArmor bwrap profile"
fi
else
log "AppArmor bwrap profile already configured or not needed"
fi
# Install Go-based tools
install_go_tool "eget" "github.com/zyedidia/eget@latest"
# lazygit and lazydocker require Go 1.24+
GO_VERSION=$(get_go_version)
MINIMUM_GO_VERSION=124 # Go 1.24
if [ "$GO_VERSION" -ge "$MINIMUM_GO_VERSION" ]; then
install_go_tool "lazygit" "github.com/jesseduffield/lazygit@latest"
install_go_tool "lazydocker" "github.com/jesseduffield/lazydocker@latest"
install_go_tool "gitsnip" "github.com/dagimg-dot/gitsnip/cmd/gitsnip@latest"
else
GO_VERSION_STR=$(go version 2>/dev/null | grep -oP 'go\K[0-9]+\.[0-9]+' | head -1 || true)
warn "Skipping lazygit, lazydocker and gitsnip - require Go 1.24+, found Go ${GO_VERSION_STR:-unknown}"
fi
# Install or update zoxide (smarter cd)
if ! command -v zoxide &> /dev/null; then
log "Installing zoxide..."
else
log "Checking zoxide for updates..."
fi
cargo install zoxide --locked
# Install or update sd (modern sed replacement)
if ! command -v sd &> /dev/null; then
log "Installing sd..."
sudo apt-get install -y sd || cargo install sd --locked
else
if [ -f "$HOME/.cargo/bin/sd" ]; then
log "Checking sd for updates..."
cargo install sd --locked
else
log "sd is already installed (apt-managed, updated via dist-upgrade)"
fi
fi
# Disable screensaver and power management
if has_desktop_environment; then
log "Disabling screensaver and power save options..."
if command -v xfconf-query &> /dev/null; then
# Disable screensaver and lock screen (create setting if it doesn't exist)
xfconf-query -c xfce4-screensaver -p /saver/enabled --create -t bool -s false || true
xfconf-query -c xfce4-screensaver -p /lock/enabled --create -t bool -s false || true
# Disable Display Power Management entirely
xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/dpms-enabled --create -t bool -s false || true
else
warn "xfconf-query not available, skipping power management configuration"
fi
else
log "No desktop environment detected - skipping screensaver configuration"
fi
# Set Terminator as default terminal
if has_desktop_environment; then
log "Setting Terminator as default terminal..."
mkdir -p ~/.config/xfce4
cat > ~/.config/xfce4/helpers.rc << 'EOF'
TerminalEmulator=terminator
EOF
else
log "No desktop environment detected - skipping terminal configuration"
fi
# Configure .zshenv for Ubuntu systems to skip global compinit
if is_ubuntu; then
log "Configuring .zshenv for Ubuntu (skip global compinit for faster startup)..."
if [ -f ~/.zshenv ] && grep -q 'skip_global_compinit=1' ~/.zshenv; then
log ".zshenv already has skip_global_compinit setting"
else
cat >> ~/.zshenv << 'EOF'
# Skip Ubuntu's global compinit for faster zsh startup
# Ubuntu sources /etc/zsh/zshrc which runs compinit, but we handle
# completion initialization more efficiently in ~/.zshrc with caching
skip_global_compinit=1
EOF
log ".zshenv configured successfully"
fi
else
log "Not Ubuntu - skipping .zshenv configuration"
fi
# Configure zsh with Kali Linux default baseline plus enhancements
log "Configuring zsh..."
# Check if .zshrc exists and prompt for overwrite
OVERWRITE_ZSHRC=true
if [ -f ~/.zshrc ]; then
if prompt_yes_no "Overwrite existing .zshrc (strongly recommended on first run!)?" "Y"; then
backup_file ~/.zshrc
else
OVERWRITE_ZSHRC=false
log "Keeping existing .zshrc"
fi
fi
if [ "$OVERWRITE_ZSHRC" = true ]; then
cat > ~/.zshrc << 'EOF'
# Default ~/.zshrc from Kali Linux
# ~/.zshrc file for zsh interactive shells.
# see /usr/share/doc/zsh/examples/zshrc for examples
setopt autocd # change directory just by typing its name
#setopt correct # auto correct mistakes
setopt interactivecomments # allow comments in interactive mode
setopt magicequalsubst # enable filename expansion for arguments of the form ‘anything=expression’
setopt nonomatch # hide error message if there is no match for the pattern
setopt notify # report the status of background jobs immediately
setopt numericglobsort # sort filenames numerically when it makes sense
setopt promptsubst # enable command substitution in prompt
WORDCHARS='_-' # Don't consider certain characters part of the word
# hide EOL sign ('%')
PROMPT_EOL_MARK=""
# configure key keybindings
bindkey -e # emacs key bindings
bindkey ' ' magic-space # do history expansion on space
bindkey '^U' backward-kill-line # ctrl + U
bindkey '^[[3;5~' kill-word # ctrl + Supr
bindkey '^[[3~' delete-char # delete
bindkey '^[[1;5C' forward-word # ctrl + ->
bindkey '^[[1;5D' backward-word # ctrl + <-
bindkey '^[[5~' beginning-of-buffer-or-history # page up
bindkey '^[[6~' end-of-buffer-or-history # page down
bindkey '^[[H' beginning-of-line # home
bindkey '^[[F' end-of-line # end
bindkey '^[[Z' undo # shift + tab undo last action
# enable completion features
autoload -Uz compinit
# Only update completion cache once a day to speed up zsh start
zcompdump_file="${XDG_CACHE_HOME:-$HOME/.cache}/zcompdump"
mkdir -p "${zcompdump_file%/*}"
setopt extended_glob
# Check if cache is fresh (less than 20 hours old)
if [[ -n $zcompdump_file(#qNmh-20) ]]; then
# Cache exists and is fresh - use it without checks
compinit -C -d "$zcompdump_file"
else
# Cache is stale or doesn't exist - regenerate
compinit -i -d "$zcompdump_file"
touch "$zcompdump_file"
fi
unsetopt extended_glob
zstyle ':completion:*:*:*:*:*' menu select
zstyle ':completion:*' auto-description 'specify: %d'
zstyle ':completion:*' completer _expand _complete
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'
zstyle ':completion:*' rehash true
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' use-compctl false
zstyle ':completion:*' verbose true
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
# History configurations
HISTFILE=~/.zsh_history
HISTSIZE=1000
SAVEHIST=2000
setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE
setopt hist_ignore_dups # ignore duplicated commands history list
setopt hist_ignore_space # ignore commands that start with space
setopt hist_verify # show command with history expansion to user before running it
#setopt share_history # share command history data
# force zsh to show the complete history
alias history="history 0"
# configure `time` format
TIMEFMT=$'\nreal\t%E\nuser\t%U\nsys\t%S\ncpu\t%P'
# make less more friendly for non-text input files, see lesspipe(1)
#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"