Skip to content

Instantly share code, notes, and snippets.

@ulisesantana
Last active January 10, 2023 10:30
Show Gist options
  • Save ulisesantana/5f13880a18541459ccd90ef38d9e9fbe to your computer and use it in GitHub Desktop.
Save ulisesantana/5f13880a18541459ccd90ef38d9e9fbe to your computer and use it in GitHub Desktop.
Raspberry Pi init script
# Prevent from using the custom alias on 3rd party scripts. Must be at the top of the file
[ -z "$PS1" ] && return
# alias
alias blog='cd ~/projects/blog'
alias blog-posts='cd ~/projects/blog/content/blog'
alias .zshrc='nvim ~/.zshrc'
alias gitlog="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
alias wifi='nmcli device show wlan0'
function cd {
builtin cd "$@" && ll
}
#!/bin/bash
# Update everything first
sudo apt update && sudo apt upgrade
# SSH and MOSH
sudo systemctl enable ssh
sudo systemctl start ssh
sudo apt install mosh -y
# Install zsh and zim
sudo apt install zsh -y
sudo chsh -s $(which zsh)
sudo curl -fsSL https://raw.githubusercontent.com/zimfw/install/master/install.zsh | bash
# Install starship
sh -c "$(curl -fsSL https://starship.rs/install.sh)"
echo 'eval "$(starship init zsh)"' >> $HOME/.zshrc
# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | zsh
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
## Install Node.js LTS
nvm install --lts
## Install yarn
npm install -g yarn
# Install docker
curl -sSL https://get.docker.com | sh
sudo groupadd docker
sudo usermod -aG docker ${USER}
# Install Wifi Connect
## Wifi Connect is installed by default in /usr/local/sbin, so let's add it to PATH
echo "PATH=$PATH:/usr/local/sbin" >> $HOME/.zshrc
## Install wifi-connect
bash <(curl -L https://github.com/balena-io/wifi-connect/raw/master/scripts/raspbian-install.sh)
## Add script for starting wifi-connect
curl curl https://gist.githubusercontent.com/ulisesantana/5f13880a18541459ccd90ef38d9e9fbe/raw/3698194e9c70b811c7b86d8edde465ebcd503398/start-wifi-connect.sh > $HOME/start-wifi-connect.sh
sudo chmod +x start-wifi-connect.sh
## Add service
wget curl https://gist.githubusercontent.com/ulisesantana/5f13880a18541459ccd90ef38d9e9fbe/raw/2acd59d6447f3a1779371fdedd58b3c24eaa9fd2/wifi-connect-start.service
sudo mv wifi-connect-start.service /lib/systemd/system/wifi-connect-start.service
## Enable it
sudo systemctl enable wifi-connect-start.service
sudo chmod -R 755 /usr/sbin/NetworkManager
sudo chmod -R 755 /etc/NetworkManager/system-connections
# Install neovim
## Install required dependencies
sudo apt-get install ninja-build gettext libtool libtool-bin autoconf automake cmake g++ pkg-config unzip -y
sudo apt install xclip xsel -y
sudo apt install python3-pip -y
sudo apt install python-pip -y
sudo python3 -m pip install neovim
sudo python -m pip install neovim
python3 -m pip install --upgrade neovim
python -m pip install --upgrade neovim
npm i -g neovim
## Create directory for build neovim
mkdir -p $HOME/apps
cd $HOME/apps
git clone https://github.com/neovim/neovim
cd neovim
git checkout stable
make -j4
make CMAKE_BUILD_TYPE=RelWithDebInfo
sudo make install
## Install vim-plug
curl -fLo $HOME/.local/share/nvim/site/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
mkdir -p $HOME/.config/nvim
curl https://gist.githubusercontent.com/ulisesantana/5f13880a18541459ccd90ef38d9e9fbe/raw/3e87c92b116b28a5be604dbea9dd054bc29e5987/init.vim > $HOME/.config/nvim/init.vim
nvim +PlugInstall
call plug#begin('~/.local/share/nvim/plugged')
Plug 'haishanh/night-owl.vim'
Plug 'scrooloose/nerdtree'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes' " Temas para airline
Plug 'Yggdroot/indentLine'
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
Plug 'Shougo/neco-syntax' " Fuente general de auto completado
Plug 'ervandew/supertab'
Plug 'Shougo/echodoc.vim'
Plug 'w0rp/ale'
Plug 'sheerun/vim-polyglot'
Plug 'haya14busa/incsearch.vim'
Plug 'tpope/vim-surround'
Plug 'jiangmiao/auto-pairs'
Plug 'scrooloose/nerdcommenter'
call plug#end()
" If you have vim >=8.0 or Neovim >= 0.1.5
if (has("termguicolors"))
set termguicolors
endif
" For Neovim 0.1.3 and 0.1.4
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
""""" enable the theme
syntax enable
colorscheme night-owl
" To enable the lightline theme
let g:lightline = { 'colorscheme': 'nightowl' }
let g:NERDTreeChDirMode = 2 " Cambia el directorio actual al nodo padre actual
" Abrir/cerrar NERDTree con F2
map <F2> :NERDTreeToggle<CR>
let g:airline#extensions#tabline#enabled = 1 " Mostrar buffers abiertos (como pestañas)
let g:airline#extensions#tabline#fnamemod = ':t' " Mostrar sólo el nombre del archivo
" Cargar fuente Powerline y símbolos (ver nota)
let g:airline_powerline_fonts = 1
set noshowmode " No mostrar el modo actual (ya lo muestra la barra de estado)
let g:indentLine_fileTypeExclude = ['text', 'sh', 'help', 'terminal']
let g:indentLine_bufNameExclude = ['NERD_tree.*', 'term:.*']
" Activar deoplete al iniciar Neovim
let g:deoplete#enable_at_startup = 1
" Cerrar automaticamente la ventana de vista previa (donde se muestra documentación, si existe)
augroup deopleteCompleteDoneAu
autocmd!
autocmd CompleteDone * silent! pclose!
augroup END
" Invertir direccion de navegacion (de arriba a abajo)
let g:SuperTabDefaultCompletionType = '<c-n>'
" Activar echodoc al iniciar Neovim
let g:echodoc_enable_at_startup = 1
" Mostrar mejor mensajes de error
let g:ale_echo_msg_error_str = '🚨'
let g:ale_echo_msg_warning_str = '⚠️'
let g:ale_echo_msg_format = '[%linter%] %s [%severity%]'
" Maps requeridos
map / <Plug>(incsearch-forward)
map ? <Plug>(incsearch-backward)
" Quitar resaltado luego de buscar
let g:incsearch#auto_nohlsearch = 1
let g:NERDSpaceDelims = 1 " Agregar un espacio después del delimitador del comentario
let g:NERDTrimTrailingWhitespace = 1 " Quitar espacios al quitar comentario
" CONFIGURACION BASE
set title " Muestra el nombre del archivo en la ventana de la terminal
set number " Muestra los números de las líneas
set mouse=a " Permite la integración del mouse (seleccionar texto, mover el cursor)
set nowrap " No dividir la línea si es muy larga
set cursorline " Resalta la línea actual
set colorcolumn=120 " Muestra la columna límite a 120 caracteres
" Indentación a 2 espacios
set tabstop=2
set shiftwidth=2
set softtabstop=2
set shiftround
set expandtab " Insertar espacios en lugar de <Tab>s
set hidden " Permitir cambiar de buffers sin tener que guardarlos
set ignorecase " Ignorar mayúsculas al hacer una búsqueda
set smartcase " No ignorar mayúsculas si la palabra a buscar contiene mayúsculas
set spelllang=en,es " Corregir palabras usando diccionarios en inglés y español
let g:mapleader = ' ' " Definir espacio como la tecla líder
nnoremap <leader>s :w<CR> " Guardar con <líder> + s
nnoremap <leader>e :e $MYVIMRC<CR> " Abrir el archivo init.vim con <líder> + e
" Usar <líder> + y para copiar al portapapeles
vnoremap <leader>y "+y
nnoremap <leader>y "+y
" Usar <líder> + d para cortar al portapapeles
vnoremap <leader>d "+d
nnoremap <leader>d "+d
" Usar <líder> + p para pegar desde el portapapeles
nnoremap <leader>p "+p
vnoremap <leader>p "+p
nnoremap <leader>P "+P
vnoremap <leader>P "+P
" Moverse al buffer siguiente con <líder> + l
nnoremap <leader>l :bnext<CR>
" Moverse al buffer anterior con <líder> + j
nnoremap <leader>j :bprevious<CR>
" Cerrar el buffer actual con <líder> + q
nnoremap <leader>q :bdelete<CR>
[character]
format = "🍓 "
[git_branch]
symbol = "🌱 "
[java]
disabled = false
[nodejs]
symbol = "⬢ "
[package]
symbol = "📦 "
[directory]
fish_style_pwd_dir_length = 10
[time]
disabled = false
format = '🕙 [\[ $time \]]($style) '
time_format = "%T"
#!/usr/bin/env bash
sleep 10
# Is there an active WiFi connection?
iwgetid -r
if [ $? -eq 0 ]; then
printf 'Skipping WiFi Connect\n'
else
printf 'Starting WiFi Connect\n'
wifi-connect
fi
[Unit]
Description=Balena wifi connect service
After=NetworkManager.service
[Service]
Type=simple
ExecStart=/home/pi/start-wifi-connect.sh
Restart=on-failure
StandardOutput=syslog
SyslogIdentifier=wifi-connect
Type=idle
User=root
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment