mirror of
https://github.com/pratiktri/dotfiles.git
synced 2026-02-04 08:41:43 +05:30
feat(setup-script): Remove unnecessary options. Add --install &
--dry-run options. Start install script when opted for.
This commit is contained in:
52
README.md
52
README.md
@@ -1,21 +1,51 @@
|
||||
# dotfiles
|
||||
# Dotfiles
|
||||
|
||||
Place to keep my .dotfiles, so I do not have to worry about migrating to another system.
|
||||
1. Restore my dotfiles on any *nix OS.
|
||||
2. Install required applications on any Linux OS.
|
||||
|
||||
Dotfiles are symlinked from the repo to the required location.
|
||||
That is, changes on repository get auto reflected on the system.
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
$ bash bootstrap.sh -h
|
||||
$ git clone https://github.com/pratiktri/dotfiles
|
||||
|
||||
Applies all settings stored in the script's directory to your home directory
|
||||
$ bash setup.sh -h
|
||||
Apply all settings stored in the script's directory to your home directory.
|
||||
|
||||
Usage: bootstrap.sh [-q|--quiet] [-l|--create-links]
|
||||
-q, --quiet No screen outputs
|
||||
-l, --create-links Creates soft-links to files in the current directory instead of copying them
|
||||
|
||||
Example: bash ./bootstrap.sh -q --create-links
|
||||
Usage: ./setup.sh [OPTION]
|
||||
Options:
|
||||
-h, --help Show this help message.
|
||||
-d, --dry-run Simulate dotfile symlink without doing anything.
|
||||
-i, --install Install programs listed on package-list-os & package-list-brew files.
|
||||
```
|
||||
|
||||
## Why `--create-links`?
|
||||
## Installation
|
||||
|
||||
I have multiple Linux installations on my machine. Linking it from one place (this repository) keeps things tidy. Also, changes to dotfiles automatically get applied to all the distros.
|
||||
Installation scripts are inside `scripts` directory.
|
||||
|
||||
It reads 2 text files to gather lists of software to install:
|
||||
|
||||
1. `package-list-os` - To install using OS package manager.
|
||||
2. `package-list-brew` - To install using brew package manager.
|
||||
|
||||
Any package not available are *skipped*.
|
||||
|
||||
`install.sh` calls `install-os-packages.sh` and `install-brew-packages.sh`. Both can be executed separately.
|
||||
|
||||
## Test
|
||||
|
||||
1. Need to be inside this directory
|
||||
|
||||
```bash
|
||||
cd scripts/test
|
||||
```
|
||||
|
||||
2. Change `Dockerfile` as required
|
||||
|
||||
3. Run the script
|
||||
|
||||
```bash
|
||||
./run-test.sh
|
||||
```
|
||||
|
||||
115
setup.sh
Executable file
115
setup.sh
Executable file
@@ -0,0 +1,115 @@
|
||||
#!/bin/sh
|
||||
|
||||
INSTALL="n"
|
||||
DRY_RUN="n"
|
||||
|
||||
show_help() {
|
||||
echo "Apply all settings stored in the script's directory to your home directory"
|
||||
echo
|
||||
echo "usage: $0 [option]"
|
||||
echo "options:"
|
||||
echo " -h, --help show this help message"
|
||||
echo " -d, --dry-run Simulate dotfile linking without doing anything"
|
||||
echo " -i, --install Install programs listed on package-list-os & package-list-brew files"
|
||||
}
|
||||
|
||||
place_dotfile_at_target_location() {
|
||||
source_file_location="$1"
|
||||
file_target_location="$2"
|
||||
TS="$3"
|
||||
|
||||
# To avoid over writing an existing dot-file, we rename them
|
||||
# Appending the timestamp to file name
|
||||
if [ -f "$file_target_location" ] || [ -L "$file_target_location" ]; then
|
||||
[ "$DRY_RUN" = "y" ] && echo "mv ${file_target_location} ${file_target_location}_${TS}" && echo "Existing dotfile renamed to ${file_target_location}_${TS}"
|
||||
[ "$DRY_RUN" = "n" ] && mv "$file_target_location" "${file_target_location}_${TS}" && echo "Existing setting renamed to ${file_target_location}_${TS}"
|
||||
fi
|
||||
|
||||
target_directory=$(dirname "$file_target_location")
|
||||
if [ ! -d "$target_directory" ]; then
|
||||
mkdir -p "$target_directory" && echo "Directory ${target_directory} created"
|
||||
fi
|
||||
|
||||
[ "$DRY_RUN" = "y" ] && echo "ln -sf ${source_file_location} ${target_directory}"
|
||||
[ "$DRY_RUN" = "n" ] && ln -sf "$source_file_location" "$target_directory" && echo "Linked ${file_target_location}"
|
||||
}
|
||||
|
||||
parse_input() {
|
||||
# TODO: Accept input to execute install.sh script
|
||||
|
||||
while [ "${#}" -gt 0 ]; do
|
||||
case $1 in
|
||||
-i | --install)
|
||||
INSTALL="y"
|
||||
shift
|
||||
;;
|
||||
-d | --dry-run)
|
||||
DRY_RUN="y"
|
||||
shift
|
||||
;;
|
||||
-h | --help)
|
||||
show_help
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
show_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
setup_symlinks() {
|
||||
case $(uname -a) in
|
||||
Linux*)
|
||||
# TODO: Make it less KDE-Neon specific and more general Linux
|
||||
OS="kde-neon"
|
||||
|
||||
[ "$XDG_CURRENT_DESKTOP" = "KDE" ] && OS="kde-neon"
|
||||
;;
|
||||
Darwin*)
|
||||
OS="macos"
|
||||
;;
|
||||
*)
|
||||
OS="UNSUPPORTED"
|
||||
;;
|
||||
esac
|
||||
|
||||
TS=$(date '+%d_%m_%Y-%H_%M_%S')
|
||||
|
||||
# Switch inside dotfile repository directory
|
||||
cd -P "$(dirname "$0")" || exit
|
||||
|
||||
# Copy all files in "Common" dotfiles to $HOME directory ("~")
|
||||
find "./common" -type f -not -path '*.DS_Store' -not -path '*.directory' | while read -r file; do
|
||||
file_target_location="${HOME}${file#./common}"
|
||||
source_file_location="${PWD}${file#.}"
|
||||
place_dotfile_at_target_location "$source_file_location" "$file_target_location" "$TS"
|
||||
done
|
||||
|
||||
# Copy platform-specific files to $HOME directory ("~")
|
||||
find "./${OS}" -type f -not -path '*.DS_Store' -not -path '*.directory' | while read -r file; do
|
||||
file_target_location="${HOME}${file#./"${OS}"}"
|
||||
source_file_location="${PWD}${file#.}"
|
||||
place_dotfile_at_target_location "$source_file_location" "$file_target_location" "$TS"
|
||||
done
|
||||
}
|
||||
|
||||
main() {
|
||||
parse_input "$@"
|
||||
|
||||
install_file_location="$(
|
||||
cd -- "$(dirname "$0")" > /dev/null 2>&1 || exit
|
||||
pwd -P
|
||||
)/scripts"
|
||||
|
||||
setup_symlinks
|
||||
echo "$install_file_location"
|
||||
|
||||
if [ "$INSTALL" = "y" ]; then
|
||||
cd "$install_file_location" || exit
|
||||
[ "$DRY_RUN" = "n" ] && "$install_file_location"/install.sh
|
||||
fi
|
||||
}
|
||||
|
||||
main "$@"
|
||||
Reference in New Issue
Block a user