Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,51 @@

<p align="center">
<img src="https://i.imgur.com/3qLFAvW.jpeg">
</p>
<p align="center">
<img alt="GitHub Stars" src="https://img.shields.io/github/stars/vtempest/server-shell-setup">
<a href="https://github.com/vtempest/server-shell-setup/discussions">
<img alt="GitHub Discussions"
src="https://img.shields.io/github/discussions/vtempest/server-shell-setup">
</a>
<a href="http://makeapullrequest.com">
<img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square" alt="PRs Welcome">
</a>
<a href="https://codespaces.new/vtempest/server-shell-setup">
<img src="https://github.com/codespaces/badge.svg" width="150" height="20">
</a>
</p>

## The Devil Is In The Defaults

> If you hold a unix shell up to your ear, can you hear the C?

# The Devil Is In The Defaults
Setup server shell with `vscode`, `nvim`, `nu`, `bun`, `node`, `helix`, `starship prompt`, `pacstall installer`, and other dev tools.

`vscode`, `nvim`, `nu`, `bun`, `node`, `helix`, `starship prompt` and other dev tools.
## Install: Bash Script to Setup Shell

## System Info When Opening Shell
```bash
sudo bash -c "$( wget -q https://raw.githubusercontent.com/vtempest/server-shell-setup/refs/heads/master/install-shell.sh -O -)"
```

👤 user@XPS15 🔝 0% fish 📁 1% 🌎 130.212.146.39 👮 California State University 📈 Intel(R) Core(TM) i5-7300HQ CPU @ 2.50GHz 💻 Debian GNU/Linux 12 (bookworm) 🔧 5.15.90.1-microsoft-standard-WSL2 🚀 apt docker git npm pip
Note: Launch Ubuntu server instance, connect and on first time login run `sudo passwd $USER` to set password. You need to enter sudo password when running this setup

`wget -qO- https://raw.githubusercontent.com/vtempest/server-shell-setup/master/systeminfo.sh | bash`
## Example: System Info When Opening Shell

```bash
👤 user@XPS15 🔝 0% fish 📁 1% 🌎 130.212.146.39 👮 California State University
📈 Intel(R) Core(TM) i5-7300HQ CPU @ 2.50GHz 💻 Debian GNU/Linux 12 (bookworm)
🔧 5.15.90.1-microsoft-standard-WSL2 🚀 apt docker git npm pip
```

## Reference Docs - 🪄 Magic Spells for Open Sourcery
## Reference Docs: 🪄 Magic Spells for Open Sourcery

- [nushell Docs](https://www.nushell.sh/book/)
- [Fish Features Overview](https://medium.com/the-glitcher/fish-shell-3ec1a6cc6128)
- [Fish Playground](https://rootnroll.com/d/fish-shell/)
- [Bun.js Runtime Docs](https://bun.sh/docs)
- [Node.js Best Packages](https://github.com/sindresorhus/awesome-nodejs)
- [nvm Node Installer](https://github.com/nvm-sh/nvm)
- [Volta Node Installer](https://docs.volta.sh/guide/)
- [pnpm Package Installer](https://pnpm.io/pnpm-cli)
- [Starship Prompt](https://starship.rs/guide/#%F0%9F%9A%80-installation)
- [VSCode Docs](https://code.visualstudio.com/docs)
Expand Down
215 changes: 215 additions & 0 deletions clean-server-disk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
#!/bin/bash

# Comprehensive Disk Space Cleanup Script
# WARNING: This script performs aggressive cleanup. Review before running.
# Run with sudo privileges

# Color definitions
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'

# Check for root privileges
if [ "$EUID" -ne 0 ]; then
echo -e "${RED}Error: Please run as root (sudo)${NC}"
exit 1
fi

# Function to print section headers
print_header() {
echo -e "\n${BLUE}=== $1 ===${NC}"
}

# Function to print success messages
print_success() {
echo -e "${GREEN}✓ $1${NC}"
}

# Function to format sizes
format_size() {
local size=$1
if [ $size -gt 1073741824 ]; then
echo "$(awk "BEGIN {printf \"%.2f\", $size/1024/1024/1024}") GB"
elif [ $size -gt 1048576 ]; then
echo "$(awk "BEGIN {printf \"%.2f\", $size/1024/1024}") MB"
elif [ $size -gt 1024 ]; then
echo "$(awk "BEGIN {printf \"%.2f\", $size/1024}") KB"
else
echo "${size} B"
fi
}

# Get initial disk usage
initial_usage=$(df -B1 / | awk 'NR==2 {print $3}')

print_header "Starting Aggressive Disk Cleanup"
echo -e "${YELLOW}⚠️ This will perform a thorough system cleanup${NC}"
sleep 2

# 1. Package Manager Cleanup
print_header "Package Manager Cleanup"

if command -v apt-get &> /dev/null; then
# APT cleanup
apt-get clean -y
apt-get autoremove -y
apt-get autoclean -y
rm -rf /var/lib/apt/lists/*
print_success "APT cache and unused packages cleaned"

elif command -v yum &> /dev/null; then
# YUM cleanup
yum clean all
yum autoremove -y
print_success "YUM cache and unused packages cleaned"

elif command -v dnf &> /dev/null; then
# DNF cleanup
dnf clean all
dnf autoremove -y
print_success "DNF cache and unused packages cleaned"
fi

# 2. Docker Cleanup (if installed)
print_header "Docker Resource Cleanup"

if command -v docker &> /dev/null; then
docker system prune -af --volumes
docker builder prune -af
rm -rf ~/.docker/buildx
print_success "Docker resources cleaned"
fi

# 3. Log File Cleanup
print_header "Log Cleanup"

# System logs
find /var/log -type f -name "*.log" -exec truncate -s 0 {} \;
find /var/log -type f -name "*.gz" -delete
find /var/log -type f -name "*.old" -delete
find /var/log -type f -name "*.1" -delete
find /var/log -type f -name "*.2" -delete
find /var/log -type f -name "*.rotated" -delete

# Journal logs
if command -v journalctl &> /dev/null; then
journalctl --vacuum-time=3d
journalctl --vacuum-size=100M
fi

print_success "System logs cleaned"

# 4. Cache Cleanup
print_header "Cache Cleanup"

# Browser caches (for all users)
find /home -type f -path "*/cache/*" -delete
find /home -type f -path "*/.cache/*" -delete
find /root -type f -path "*/cache/*" -delete
find /root -type f -path "*/.cache/*" -delete

# Thumbnail cache
find /home -type f -path "*/.thumbnails/*" -delete
rm -rf ~/.thumbnails/*

# Font cache
fc-cache -f

# Man page cache
if command -v mandb &> /dev/null; then
rm -rf /var/cache/man/*
mandb
fi

print_success "System caches cleaned"

# 5. Temp Files Cleanup
print_header "Temporary Files Cleanup"

# System temp directories
rm -rf /tmp/*
rm -rf /var/tmp/*

# User specific temp files
find /home -type f -name "*.tmp" -delete
find /home -type f -name "*.temp" -delete
find /home -type f -name "tmp.*" -delete

# Crash reports and core dumps
rm -rf /var/crash/*
rm -rf /var/cores/*
echo "kernel.core_pattern=|/bin/false" > /etc/sysctl.d/50-coredump.conf
sysctl -p /etc/sysctl.d/50-coredump.conf

print_success "Temporary files cleaned"

# 6. Old Kernel Cleanup
print_header "Kernel Cleanup"

# Keep only the current and one previous kernel version
if command -v dpkg &> /dev/null; then
current_kernel=$(uname -r | sed 's/-*[a-z].*//g' | sed 's/-$//')
dpkg -l 'linux-*' | sed '/^ii/!d;/'"${current_kernel}"'/d' | awk '{print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e '[0-9]' | xargs apt-get -y purge
fi

print_success "Old kernels cleaned"

# 7. Application Specific Cleanup
print_header "Application Specific Cleanup"

# Clean pip cache
if command -v pip3 &> /dev/null; then
pip3 cache purge
fi

# Clean npm cache
if command -v npm &> /dev/null; then
npm cache clean --force
fi

# Clean yarn cache
if command -v yarn &> /dev/null; then
yarn cache clean
fi

# Clean snapd cache
if command -v snap &> /dev/null; then
snap set system refresh.retain=2
rm -rf /var/lib/snapd/cache/*
fi

# Clean flatpak unused runtimes
if command -v flatpak &> /dev/null; then
flatpak uninstall --unused -y
fi

print_success "Application caches cleaned"

# 8. User Cleanup
print_header "User Directory Cleanup"

# Clean user Downloads folders older than 30 days
find /home/*/Downloads -type f -atime +30 -delete 2>/dev/null

# Remove old bash history
find /home -type f -name ".bash_history" -exec sh -c 'echo "" > {}' \;

print_success "User directories cleaned"

# Calculate space freed
final_usage=$(df -B1 / | awk 'NR==2 {print $3}')
space_freed=$((initial_usage - final_usage))
formatted_space=$(format_size $space_freed)

print_header "Cleanup Complete"
echo -e "${GREEN}Total space freed: $formatted_space${NC}"

# Show current disk usage
echo -e "\n${YELLOW}Current Disk Usage:${NC}"
df -h / | awk 'NR==1{print} NR==2{print}'

# Optional: Sync disks and clear RAM cache
sync
echo 3 > /proc/sys/vm/drop_caches
59 changes: 42 additions & 17 deletions install-shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,72 @@
# setup shell with best dev tools on Ubuntu
# fish, nushell, nvim, helix, node, bun, pacstall, docker

# sudo passwd ${USER} # set password for user
# INSTALL:
# sudo bash -c "$( wget -q https://raw.githubusercontent.com/vtempest/server-shell-setup/refs/heads/master/install-shell.sh -O -)"

setup_shell(){

#add fish nvim helix to ubuntu PPA
sudo apt-add-repository ppa:fish-shell/release-3
sudo add-apt-repository ppa:neovim-ppa/stable
sudo add-apt-repository ppa:maveonair/helix-editor
echo -e '\n' | sudo apt-add-repository ppa:fish-shell/release-3
echo -e '\n' | sudo add-apt-repository ppa:neovim-ppa/stable
echo -e '\n' | sudo add-apt-repository ppa:maveonair/helix-editor
sudo apt update

sudo apt install -y fish neovim git wget curl helix

# fish plugins config
curl https://raw.githubusercontent.com/oh-my-fish/oh-my-fish/master/bin/install | fish
omf install fzf nvm

#bun
curl -fsSL https://bun.sh/install | bash

#node
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash;
nvm install node

#node with volta
bash -c "$(curl -sS https://get.volta.sh )"

source ~/.bashrc
bash -c "volta install node"

#install nushell
npm i -g pnpm nushell

#nvim config
git clone https://github.com/LazyVim/starter ~/.config/nvim


#install greeting
sudo wget https://raw.githubusercontent.com/vtempest/server-shell-setup/refs/heads/master/systeminfo.sh -O ~/.config/systeminfo.sh
sudo chmod +x ~/.config/systeminfo.sh
sudo echo "bash ~/.config/systeminfo.sh" >> ~/.bashrc
sudo echo "bash ~/.config/systeminfo.sh" >> ~/.config/fish/config.fish


#pacstall - discover 3rd party deb packages
yes | sudo bash -c "$(curl -fsSL https://pacstall.dev/q/install || wget -q https://pacstall.dev/q/install -O -)"

#clear default greeting
sudo rm /etc/motd; sudo rm -rf /etc/update-motd.d; touch ~/.hushlogin;
fish -c "set -U fish_greeting \"\""
sudo rm -f /etc/motd; sudo rm -rf /etc/update-motd.d; touch ~/.hushlogin;


# fish plugins config - goes into fish
curl https://raw.githubusercontent.com/oh-my-fish/oh-my-fish/master/bin/install > omf-install.sh
chmox +x omf-install.sh
fish -c "./omf-install.sh --path=~/.local/share/omf --config=~/.config/omf"
fish -c "omf install fzf nvm"
rm -f omf-install.sh

#starship prompt
curl -sS https://starship.rs/install.sh | sh

#starship prompt -- needs manual setup
sudo sh -c "$(curl -sS https://starship.rs/install.sh )"

#install prompt into nu shell
echo "mkdir ~/.cache/starship; starship init nu | save -f ~/.cache/starship/init.nu" >> (/home/$USER/.config/nushell/env.nu)
echo "use ~/.cache/starship/init.nu" >> (/home/$USER/.config/nushell/config.nu)
echo "mkdir ~/.cache/starship; starship init nu | save -f ~/.cache/starship/init.nu" >> /home/$USER/.config/nushell/env.nu
echo "use ~/.cache/starship/init.nu" >> /home/$USER/.config/nushell/config.nu

#install prompt into fish shell
echo "starship init fish | source" >> ~/.config/fish/config.fish

#pacstall - discover 3rd party deb packages
curl -fsSL https://pacstall.dev/q/install | bash


}


Expand Down Expand Up @@ -73,3 +97,4 @@ setup_root(){
#run main
setup_shell

setup_docker
Loading