Naposledy aktivní 1760251296

Revize 393e4114902a49a7e753dd051f68ffe2256ed071

aptupdate Raw
1#!/bin/sh
2sudo apt update
3sudo DEBIAN_FRONTEND=noninteractive apt -y upgrade
4sudo DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade
5sudo apt -y autoremove
6sudo apt -y autoclean
7sudo apt -y clean
firstrun Raw
1#!/bin/sh
2cd ~
3# sudo apt-mark hold grub* ssh*
4sudo DEBIAN_FRONTEND=noninteractive apt-get -y update
5sudo DEBIAN_FRONTEND=noninteractive apt-get -y upgrade
6sudo apt -y install gdebi
7
8
9sudo apt update
10sudo apt -y upgrade
11sudo apt -y autoremove
12sudo apt -y autoclean
13sudo apt -y clean
14
15# sudo apt-mark unhold grub* ssh*
16sudo curl -L https://gist.yais.me/yaisme/util/raw/HEAD/aptupdate -o /tmp/aptupdate
17sudo mv /tmp/aptupdate /usr/bin/aptupdate
18sudo chmod +x /usr/bin/aptupdate
19sudo apt remove -y unattended-upgrades
20
firstrunv2.sh Raw
1#!/usr/bin/env bash
2set -euo pipefail
3
4# =========================
5# Settings (adjust freely)
6# =========================
7PREFER_EDITOR="${PREFER_EDITOR:-vim}"
8PACKAGES=(
9 bash-completion git curl wget ca-certificates gnupg
10 vim tmux htop tree unzip zip
11 ripgrep fd-find fzf
12 build-essential gdebi-core
13)
14
15APTUPDATE_PATH="/usr/bin/aptupdate"
16APTUPDATE_URL="https://gist.yais.me/yaisme/util/raw/HEAD/aptupdate"
17
18# =========================
19# Helpers
20# =========================
21msg() { printf "\033[1;32m[OK]\033[0m %s\n" "$*"; }
22warn() { printf "\033[1;33m[WARN]\033[0m %s\n" "$*"; }
23err() { printf "\033[1;31m[ERR]\033[0m %s\n" "$*" >&2; }
24
25backup_file() {
26 local f="$1"; [ -f "$f" ] || return 0
27 local ts; ts="$(date +%Y%m%d-%H%M%S)"
28 cp -a "$f" "${f}.bak.${ts}"
29 msg "Backup: ${f}.bak.${ts}"
30}
31
32append_once() {
33 # $1=file, $2=tag_line(unique), $3=payload
34 local file="$1" tag="$2" payload="$3"
35 grep -Fqx "$tag" "$file" 2>/dev/null && return 0
36 printf "\n%s\n%s\n" "$tag" "$payload" >>"$file"
37}
38
39ensure_local_bin() {
40 mkdir -p "$HOME/.local/bin"
41 case ":${PATH:-}:" in
42 *":$HOME/.local/bin:"*) : ;;
43 *) echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$HOME/.profile" ;;
44 esac
45}
46
47# =========================
48# 0) System update/upgrade
49# =========================
50cd "$HOME"
51
52export DEBIAN_FRONTEND=noninteractive
53sudo apt-get -y update
54sudo apt-get -y upgrade || true
55
56# Keep your style (and keep unattended-upgrades removed)
57sudo apt -y update
58sudo apt -y upgrade || true
59sudo apt -y autoremove
60sudo apt -y autoclean
61sudo apt -y clean
62sudo apt remove -y unattended-upgrades || true
63msg "Base update/upgrade complete (unattended-upgrades removed)."
64
65# =========================
66# 1) Install /usr/bin/aptupdate
67# (download; if fails, write a built-in fallback)
68# =========================
69tmpfile="$(mktemp)"
70if command -v curl >/dev/null 2>&1 && curl -fsSL "$APTUPDATE_URL" -o "$tmpfile"; then
71 sudo mv "$tmpfile" "$APTUPDATE_PATH"
72 msg "Installed aptupdate from gist."
73else
74 warn "Could not fetch aptupdate; installing fallback script."
75 cat >"$tmpfile" <<'EOF'
76#!/bin/sh
77sudo apt update
78sudo DEBIAN_FRONTEND=noninteractive apt -y upgrade
79sudo DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade
80sudo apt -y autoremove
81sudo apt -y autoclean
82sudo apt -y clean
83EOF
84 sudo mv "$tmpfile" "$APTUPDATE_PATH"
85fi
86sudo chmod +x "$APTUPDATE_PATH"
87
88# =========================
89# 2) Install common packages
90# =========================
91sudo apt-get update -y
92sudo DEBIAN_FRONTEND=noninteractive apt-get install -y "${PACKAGES[@]}" || warn "Some packages failed to install; continuing."
93
94# Map Ubuntu's fdfind → fd for consistency
95if command -v fdfind >/dev/null 2>&1 && ! command -v fd >/dev/null 2>&1; then
96 ensure_local_bin
97 ln -sf "$(command -v fdfind)" "$HOME/.local/bin/fd"
98 msg "Linked fdfind → fd at ~/.local/bin/fd"
99fi
100
101# =========================
102# 3) Shell customization
103# =========================
104BASHRC="${HOME}/.bashrc"
105INPUTRC="${HOME}/.inputrc"
106[ -f "$BASHRC" ] || touch "$BASHRC"
107[ -f "$INPUTRC" ] || touch "$INPUTRC"
108backup_file "$BASHRC"
109backup_file "$INPUTRC"
110
111# 3a) force_color_prompt=yes (ensure near top for Ubuntu-style .bashrc)
112if grep -Eq '^[[:space:]]*#?[[:space:]]*force_color_prompt[[:space:]]*=' "$BASHRC"; then
113 sed -i '0,/^[[:space:]]*#\{0,1\}[[:space:]]*force_color_prompt[[:space:]]*=.*/s//force_color_prompt=yes/' "$BASHRC"
114else
115 sed -i '1iforce_color_prompt=yes' "$BASHRC"
116fi
117msg "Enabled force_color_prompt=yes."
118
119# 3b) bash-completion
120COMPLETION_TAG="# >>> chatgpt: bash-completion enable >>>"
121COMPLETION_BLOCK=$(cat <<'EOF'
122# >>> chatgpt: bash-completion enable >>>
123if [ -n "$BASH_VERSION" ] && ! shopt -oq posix; then
124 if [ -f /usr/share/bash-completion/bash_completion ]; then
125 . /usr/share/bash-completion/bash_completion
126 elif [ -f /etc/bash_completion ]; then
127 . /etc/bash_completion
128 fi
129fi
130# <<< chatgpt: bash-completion enable <<<
131EOF
132)
133append_once "$BASHRC" "$COMPLETION_TAG" "$COMPLETION_BLOCK"
134msg "Ensured bash-completion is sourced when available."
135
136# 3c) History: timestamps + safe/merged history
137HIST_TAG="# >>> chatgpt: history settings >>>"
138HIST_BLOCK=$(cat <<'EOF'
139# >>> chatgpt: history settings >>>
140# Timestamps (YYYY-MM-DD HH:MM:SS)
141export HISTTIMEFORMAT='%F %T '
142# Safer history
143export HISTCONTROL=ignoredups:ignorespace:erasedups
144export HISTSIZE=200000
145export HISTFILESIZE=400000
146# Merge history across concurrent shells
147shopt -s histappend
148if [[ -n "${PROMPT_COMMAND:-}" ]]; then
149 case "$PROMPT_COMMAND" in
150 *'history -a; history -c; history -r'*) : ;;
151 *) PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND" ;;
152 esac
153else
154 PROMPT_COMMAND='history -a; history -c; history -r'
155fi
156# <<< chatgpt: history settings <<<
157EOF
158)
159append_once "$BASHRC" "$HIST_TAG" "$HIST_BLOCK"
160msg "Enabled history timestamps and merging."
161
162# 3d) QoL: prompt, aliases, shopt, editor/pager (no Kubernetes)
163QOL_TAG="# >>> chatgpt: QoL shell block >>>"
164QOL_BLOCK=$(cat <<'EOF'
165# >>> chatgpt: QoL shell block >>>
166# Minimal Git branch helper
167__chatgpt_git_branch() {
168 local b
169 b=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) || return 0
170 [ "$b" = "HEAD" ] && b=$(git rev-parse --short HEAD 2>/dev/null)
171 [ -n "$b" ] && printf ' (%s)' "$b"
172}
173
174# Prompt: exit code + user@host:cwd + (git)
175__chatgpt_set_ps1() {
176 local exit="$?"
177 local red="\[\e[31m\]" green="\[\e[32m\]" yellow="\[\e[33m\]" blue="\[\e[34m\]" magenta="\[\e[35m\]" cyan="\[\e[36m\]" reset="\[\e[0m\]"
178 local code=""
179 [ "$exit" -ne 0 ] && code="${red}↯${exit}${reset} "
180 PS1="${code}${green}\u${reset}@${blue}\h${reset}:${magenta}\w${reset}\$(__chatgpt_git_branch)\n${cyan}\$ ${reset}"
181}
182case "${PROMPT_COMMAND:-}" in
183 *"__chatgpt_set_ps1"*) : ;;
184 "") PROMPT_COMMAND="__chatgpt_set_ps1" ;;
185 *) PROMPT_COMMAND="__chatgpt_set_ps1; $PROMPT_COMMAND" ;;
186esac
187
188# shopt toggles
189shopt -s checkwinsize cdspell autocd globstar
190
191# Common aliases
192alias ls='ls --color=auto -F --group-directories-first'
193alias ll='ls -lah'
194alias la='ls -A'
195alias grep='grep --color=auto'
196alias df='df -h'
197alias free='free -h'
198alias watchd='watch -n1 -d'
199alias cp='cp -i'
200alias mv='mv -i'
201alias rm='rm -I' # prompt once if >3 files
202
203# Prefer modern tools if present
204command -v batcat >/dev/null 2>&1 && alias bat='batcat'
205command -v bat >/dev/null 2>&1 && alias cat='bat --paging=never'
206command -v lsd >/dev/null 2>&1 && alias ls='lsd'
207
208# Defaults
209export EDITOR="${EDITOR:-vim}"
210export VISUAL="$EDITOR"
211export PAGER="${PAGER:-less}"
212export LESS='-R'
213export GPG_TTY="$(tty 2>/dev/null || true)"
214# <<< chatgpt: QoL shell block <<<
215EOF
216)
217append_once "$BASHRC" "$QOL_TAG" "$QOL_BLOCK"
218msg "Added prompt/aliases/shopt/editor QoL block."
219
220# 3e) Ensure desired EDITOR
221if grep -Fq 'export EDITOR=' "$BASHRC"; then
222 sed -i "0,/export EDITOR=.*/s//export EDITOR=\"${PREFER_EDITOR}\"/" "$BASHRC"
223else
224 echo "export EDITOR=\"${PREFER_EDITOR}\"" >> "$BASHRC"
225fi
226msg "Default EDITOR set to ${PREFER_EDITOR}"
227
228# 3f) ~/.inputrc readline tweaks
229INPUT_TAG="# >>> chatgpt: readline tweaks >>>"
230INPUT_BLOCK=$(cat <<'EOF'
231# >>> chatgpt: readline tweaks >>>
232set show-all-if-ambiguous on
233set menu-complete-display-prefix on
234set colored-stats on
235set mark-symlinked-directories on
236set completion-ignore-case on
237set completion-map-case on
238"\e[A": history-search-backward
239"\e[B": history-search-forward
240# <<< chatgpt: readline tweaks <<<
241EOF
242)
243append_once "$INPUTRC" "$INPUT_TAG" "$INPUT_BLOCK"
244msg "Improved interactive completion in ~/.inputrc."
245
246# =========================
247# 4) Wrap up
248# =========================
249msg "First-run setup complete. Open a NEW terminal or run: source ~/.bashrc"
250
getpubkey.sh Raw
1#!/bin/bash
2
3# Prompt the user for their GitHub username
4read -p "Enter your GitHub username: " USERNAME
5
6# Get the GitHub public key URL
7KEY_URL="https://github.com/$USERNAME.keys"
8
9pushd ~/.ssh/
10
11# Download the public key
12wget -q -O - "$KEY_URL" > ~/.ssh/authorized_keys
13
14# Set appropriate permissions for the authorized_keys file
15chmod 600 ~/.ssh/authorized_keys
16
17# Check if the .ssh directory exists and create it if it doesn't
18if [ ! -d ~/.ssh ]; then
19 mkdir -p ~/.ssh
20 chmod 700 ~/.ssh
21fi
22
23echo "Public key successfully added to authorized_keys"