Last active
April 29, 2025 15:50
-
-
Save Xiaorui-Huang/181ed9c72b6157a282d71d803965713b to your computer and use it in GitHub Desktop.
Setup Files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Prompt the user for a new username | |
| read -p "Please enter a new username: " NEW_USER | |
| # Exit the script if no username is provided | |
| if [[ -z "$NEW_USER" ]]; then | |
| echo "No username provided. Exiting." | |
| exit 1 | |
| fi | |
| # Confirm the username | |
| echo "You entered the username: $NEW_USER" | |
| read -p "Is this correct? [Y/n]: " CONFIRMATION | |
| # Check if the user confirmed the username, or if the input is empty (default to yes) | |
| while [[ "$CONFIRMATION" != "" && "$CONFIRMATION" != "y" && "$CONFIRMATION" != "Y" && "$CONFIRMATION" != "n" && "$CONFIRMATION" != "N" ]]; do | |
| echo "Invalid input. Please enter 'y' (yes), 'n' (no) or just press enter to confirm." | |
| read -p "Is this correct? [[y]/n]: " CONFIRMATION | |
| done | |
| if [[ "$CONFIRMATION" == "n" || "$CONFIRMATION" == "N" ]]; then | |
| echo "Username not confirmed. Exiting." | |
| exit 1 | |
| fi | |
| # Create the user | |
| useradd -m -G sudo -s /bin/bash "$NEW_USER" | |
| passwd "$NEW_USER" | |
| # Update the WSL configuration | |
| tee /etc/wsl.conf <<_EOF | |
| [user] | |
| default=${NEW_USER} | |
| _EOF | |
| echo 'Now terminate wsl for new user to take effect `wsl --terminate`' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # sudo apt install ghostscript pdftk | |
| # util functions | |
| pdfcompress() { | |
| if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then | |
| echo "Usage: pdfcompress <input_pdf> [compression_quality]" | |
| echo "Compression qualities: low, med, high, max" | |
| return 1 | |
| fi | |
| local infile="$1" | |
| local compression_quality="$2" | |
| local base_filename=$(basename "$infile") | |
| local home_compressed="${HOME}/${base_filename%.pdf}_compressed.pdf" | |
| local home_infile="${HOME}/${base_filename}" | |
| # Copy the original PDF to the home directory | |
| cp "$infile" "$home_infile" | |
| # Determine compression setting based on the given quality | |
| case "$compression_quality" in | |
| low) | |
| local quality_setting="/screen" | |
| ;; | |
| med) | |
| local quality_setting="/ebook" | |
| ;; | |
| high) | |
| local quality_setting="/printer" | |
| ;; | |
| max) | |
| local quality_setting="/prepress" | |
| ;; | |
| *) | |
| local quality_setting="/prepress" # default to max | |
| ;; | |
| esac | |
| # Run Ghostscript on the PDF in the home directory | |
| gs -q -dNOPAUSE -dBATCH \ | |
| -sDEVICE=pdfwrite \ | |
| -dCompatibilityLevel=1.4 \ | |
| -dPDFSETTINGS="$quality_setting" \ | |
| -dEmbedAllFonts=true \ | |
| -dSubsetFonts=true \ | |
| -dDownsampleColorImages=true \ | |
| -dColorImageDownsampleType=/Bicubic \ | |
| -dColorImageResolution=300 \ | |
| -dDownsampleGrayImages=true \ | |
| -dGrayImageDownsampleType=/Bicubic \ | |
| -dGrayImageResolution=300 \ | |
| -dDownsampleMonoImages=true \ | |
| -dMonoImageDownsampleType=/Bicubic \ | |
| -dMonoImageResolution=300 \ | |
| -sOutputFile="$home_compressed" "$home_infile" | |
| # Copy the compressed file back to the current working directory | |
| cp "$home_compressed" "./${base_filename%.pdf}_compressed.pdf" | |
| # Delete the original and compressed PDFs in the home directory | |
| rm "$home_infile" | |
| rm "$home_compressed" | |
| } | |
| splitpdf() { | |
| local parts="$1" | |
| local input_file="$2" | |
| # Get the total number of pages in the PDF | |
| local total_pages=$(pdftk "$input_file" dump_data | grep "NumberOfPages" | awk '{print $2}') | |
| echo "Pages: $total_pages" | |
| # Calculate the number of pages in each part | |
| local pages_per_part=$((total_pages / parts)) | |
| local remaining_pages=$((total_pages % parts)) | |
| local start_page=1 | |
| for (( i=1; i<=parts; i++ )); do | |
| local end_page=$((start_page + pages_per_part - 1)) | |
| # Distribute the remaining pages among the parts | |
| if (( remaining_pages > 0 )); then | |
| end_page=$((end_page + 1)) | |
| remaining_pages=$((remaining_pages - 1)) | |
| fi | |
| local output_file="${input_file%.pdf}_part${i}.pdf" | |
| pdftk "$input_file" cat "$start_page-$end_page" output "$output_file" | |
| echo "Created $output_file" | |
| start_page=$((end_page + 1)) | |
| done | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # for set usage refer to this https://gist.github.com/vncsna/64825d5609c146e80de8b1fd623011ca | |
| set -ex | |
| # get sudo and update default packages | |
| sudo apt update | |
| sudo apt upgrade -y | |
| sudo apt install build-essential -y | |
| sudo apt remove nano -y | |
| # for wsl only | |
| sudo apt install wslu -y | |
| sudo apt install unzip -y | |
| # variables | |
| echo "export profile=~/.bashrc" >> ~/.bash_aliases | |
| # set terminal to vim mode | |
| source ~/.bashrc | |
| profile=~/.bashrc | |
| echo "# setup configs" >> $profile | |
| echo "set -o vi" >> $profile | |
| # create ssh keys (can rely on gh instead) | |
| # ssh-keygen -t ed25519 -C "[email protected]" | |
| # eval "$(ssh-agent -s)" | |
| # ssh-add ~/.ssh/id_ed25519 | |
| # homebrew | |
| NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" | |
| (echo; echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"') >> $profile | |
| eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" | |
| # tools | |
| yes | brew install z gh fzf | |
| yes | brew install --cask font-cascadia-code-nf | |
| gh config set editor vi | |
| echo 'eval "$(gh completion -s bash)"' >> $profile | |
| echo 'eval "$(gh copilot alias -- bash)"' >> $profile | |
| echo '. /home/linuxbrew/.linuxbrew/etc/profile.d/z.sh' >> $profile | |
| # fzf key bindings | |
| echo '# fzf key binding remap' >> $profile | |
| $(brew --prefix)/opt/fzf/install --all | |
| echo "export FZF_DEFAULT_OPTS=\"\${FZF_DEFAULT_OPTS} --bind 'alt-j:down,alt-k:up'\"" >> $profile | |
| echo "bind '\"\\ef\": \"\\C-r\"' # Remap command search to Alt-f" >> $profile | |
| echo "bind '\"\\et\": \"\\C-t\"' # Remap file search to Alt-t" >> $profile | |
| # Append the specified lines to .inputrc | |
| cat <<EOF >> ~/.inputrc | |
| TAB:menu-complete | |
| "\e[Z":menu-complete-backward # shift tab | |
| set completion-ignore-case On | |
| set show-all-if-ambiguous On | |
| set show-all-if-unmodified On | |
| EOF | |
| brew install neovim | |
| echo 'alias vi=nvim' >> ~/.bash_aliases | |
| source $profile | |
| git config --global core.editor "nvim" | |
| git config --global user.email "[email protected]" | |
| git config --global user.name "Richard-Xiaorui Huang" | |
| # oh-my-posh with default skins | |
| brew install jandedobbeleer/oh-my-posh/oh-my-posh | |
| echo '# use oh-my-posh' >> $profile | |
| # echo 'eval "$(oh-my-posh init bash)"' >> $profile | |
| echo 'eval "$(oh-my-posh init bash --config $(brew --prefix oh-my-posh)/themes/bubblesextra.omp.toml)"' >> $profile | |
| source $profile | |
| ## Personal setup | |
| # git clone https://github.com/Xiaorui-Huang/nvim.git ~/.config/nvim | |
| git clone https://gist.github.com/Xiaorui-Huang/8133248ad21bc82525dfede2f8430e5a.git ~/omp_config | |
| mv ~/omp_config/bubblesextra.omp.toml $(brew --prefix oh-my-posh)/themes/bubblesextra.omp.toml | |
| rm -rf ~/omp_config | |
| source $profile | |
| echo "PLEASE login to gh and install gh-copilot to complete the setup" | |
| echo "gh auth login" | |
| echo "gh extension install github/gh-copilot" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Read https://docs.nvidia.com/cuda/wsl-user-guide/index.html#getting-started-with-cuda-on-wsl-2 | |
| # Install the wanted cuda toolkit version with LOCAL deb! | |
| # https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=WSL-Ubuntu&target_version=2.0&target_type=deb_local | |
| # Add the following to ~/.bashrc | |
| export PATH=$PATH:/usr/local/cuda/bin | |
| # https://github.com/microsoft/WSL/issues/8587#issuecomment-1229170859 | |
| export LD_LIBRARY_PATH=/usr/lib/wsl/lib:$LD_LIBRARY_PATH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment