Skip to content

Commit

Permalink
[Feature] Cargo Export/Import multimachine (#13)
Browse files Browse the repository at this point in the history
* Added cargo export/import

* Fix(dump.sh): Apply patch to fix wrong importing file
- Fixed wrong importing file when computer hostname was similar to another one
- Fixed errors in messages

* Restored dot and output from master to avoid merging problems

* Added double quotes in _main for DOTLY_PATH because it can contain non alphabetical chars

* Improved output::join with a stackoverflow function in: https://stackoverflow.com/a/17841619
Removed duplicate functions

* Added closed and unapproved PR #61 because it is needed when I use beta branch for testing and developing.

* Added a way to modify DOTFILES_PATH structure when add a feature to dotly, fixed all the way init-scripts were loaded because they fail. Fixed some issues.

* Added some core functions:
* Added new functions to get the current script_name or script_path where the functions were run
* Added function to conver mayus to lower

* Added async library
Added script 'dot symlinks update'

* Added couple of kill to view the effecto of importing defaults

* Fixed not well included dump.sh library

* Added couple of kill to view the effect of importing defaults

* Fixed not well included dump.sh library

* Fix update when no update yaml file is given and no choose in fzf selection

* Changed the name of dot::get_script_src_path to dot::load_library.

Co-authored-by: Gabriel Trabanco Llano <gtrabanco@users.noreply.github.com>
  • Loading branch information
gtrabanco and gtrabanco committed Jun 25, 2021
1 parent 8224b3a commit c06b491
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 12 deletions.
8 changes: 8 additions & 0 deletions scripts/package/dump
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fi
HOMEBREW_DUMP_FILE_PATH="$DOTFILES_PATH/os/$(platform::os)/brew/${HOSTNAME}.txt"
APT_DUMP_FILE_PATH="$DOTFILES_PATH/os/linux/apt/${HOSTNAME}.txt"
SNAP_DUMP_FILE_PATH="$DOTFILES_PATH/os/linux/snap/${HOSTNAME}.txt"
CARGO_DUMP_FILE_PATH="$DOTFILES_PATH/langs/rust/cargo/${HOSTNAME}.txt"
PYTHON_DUMP_FILE_PATH="$DOTFILES_PATH/langs/python/${HOSTNAME}.txt"
NPM_DUMP_FILE_PATH="$DOTFILES_PATH/langs/js/npm/${HOSTNAME}.txt"
VOLTA_DUMP_FILE_PATH="$DOTFILES_PATH/langs/js/volta/${HOSTNAME}.txt"
Expand All @@ -51,6 +52,13 @@ VOLTA_DUMP_FILE_PATH="$DOTFILES_PATH/langs/js/volta/${HOSTNAME}.txt"
output::empty_line
} || package::clarification "${snap_title:-SNAP}"

{
platform::command_exists cargo &&\
package::cargo_dump "$CARGO_DUMP_FILE_PATH" &&\
output::answer "${cargo_title:-Cargo} apps dumped on $CARGO_DUMP_FILE_PATH" &&\
output::empty_line
} || package::clarification "${cargo_title:-Cargo}"

{
platform::command_exists pip3 && \
package::python_dump "$PYTHON_DUMP_FILE_PATH" && \
Expand Down
11 changes: 11 additions & 0 deletions scripts/package/import
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ docs::parse "$@"
BREW_PATH="${BREW_PATH:-$DOTFILES_PATH/os/$(platform::os)/brew}"
APT_PATH="${APT_PATH:-$DOTFILES_PATH/os/linux/apt}"
SNAP_PATH="${SNAP_PATH:-$DOTFILES_PATH/os/linux/snap}"
CARGO_PATH="${CARGO_PATH:-$DOTFILES_PATH/langs/rust/cargo/}"
PYTHON_PATH="${PYTHON_PATH:-$DOTFILES_PATH/langs/python}"
NPM_PATH="${NPM_PATH:-$DOTFILES_PATH/langs/js/npm}"
VOLTA_PATH="${VOLTA_PATH:-$DOTFILES_PATH/langs/js/volta}"
Expand All @@ -36,6 +37,7 @@ VOLTA_PATH="${VOLTA_PATH:-$DOTFILES_PATH/langs/js/volta}"
HOMEBREW_DUMP_FILE_PATH="$(package::exists_dump_current_machine_file "$BREW_PATH")"
APT_DUMP_FILE_PATH="$(package::exists_dump_current_machine_file "$APT_PATH")"
SNAP_DUMP_FILE_PATH="$(package::exists_dump_current_machine_file "$SNAP_PATH")"
CARGO_DUMP_FILE_PATH="$(package::exists_dump_current_machine_file "$CARGO_PATH")"
PYTHON_DUMP_FILE_PATH="$(package::exists_dump_current_machine_file "$PYTHON_PATH")"
NPM_DUMP_FILE_PATH="$(package::exists_dump_current_machine_file "$NPM_PATH")"
VOLTA_DUMP_FILE_PATH="$(package::exists_dump_current_machine_file "$VOLTA_PATH")"
Expand All @@ -44,6 +46,7 @@ if ! ${never_prompt:-false}; then
platform::command_exists brew && [[ -z "$HOMEBREW_DUMP_FILE_PATH" ]] || ${prompt:-false} && package::which_file "$BREW_PATH" "Select ${brew_title:-Brew} file to import" "HOMEBREW_DUMP_FILE_PATH"
platform::command_exists apt && [[ -z "$APT_DUMP_FILE_PATH" ]] || ${prompt:-false} && package::which_file "$APT_PATH" "Select ${apt_title:-APT} file of modules to import" "APT_DUMP_FILE_PATH"
platform::command_exists snap && [[ -z "$SNAP_DUMP_FILE_PATH" ]] || ${prompt:-false} && package::which_file "$SNAP_PATH" "Select ${snap_title:-SNAP} file of modules to import" "SNAP_DUMP_FILE_PATH"
platform::command_exists cargo && [[ -z "$CARGO_DUMP_FILE_PATH" ]] || ${prompt:-false} && package::which_file "$CARGO_PATH" "Select ${cargo_title:-Cargo} file to import" "CARGO_DUMP_FILE_PATH"
platform::command_exists pip3 && [[ -z "$PYTHON_DUMP_FILE_PATH" ]] || ${prompt:-false} && package::which_file "$PYTHON_PATH" "Select ${pip_title:-Python} requirements file to import" "PYTHON_DUMP_FILE_PATH"
platform::command_exists volta && [[ -z "$VOLTA_DUMP_FILE_PATH" ]] || ${prompt:-false} && package::which_file "$VOLTA_PATH" "Select ${volta_title:-volta} file to import" "VOLTA_DUMP_FILE_PATH"
platform::command_exists npm && [[ -z "$NPM_DUMP_FILE_PATH" ]] || ${prompt:-false} && package::which_file "$NPM_PATH" "Select ${npm_title:-NPM} file of modules to import" "NPM_DUMP_FILE_PATH"
Expand Down Expand Up @@ -75,6 +78,14 @@ output::write "🎩 Let's import your packages (this could take a while)" && out
} ||\
output::answer "Ignoring SNAP"

{
platform::command_exists cargo &&\
output::header "Importing Cargo apps from $CARGO_DUMP_FILE_PATH" &&\
package::cargo_import &&\
output::empty_line
} ||\
output::answer "Ignoring Cargo"

{
platform::command_exists pip3 && [[ -n "$PYTHON_DUMP_FILE_PATH" ]] &&\
output::empty_line &&\
Expand Down
48 changes: 36 additions & 12 deletions scripts/package/src/dump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ package::brew_dump() {
if package::common_dump_check brew "$HOMEBREW_DUMP_FILE_PATH"; then
output::write "🚀 Starting Brew dump to '$HOMEBREW_DUMP_FILE_PATH'"

brew bundle dump --file="$HOMEBREW_DUMP_FILE_PATH" --force | log::file "Exporting $brew_title packages list"
brew bundle dump --file="$HOMEBREW_DUMP_FILE_PATH" --force | log::file "Exporting $brew_title packages"
brew bundle --file="$HOMEBREW_DUMP_FILE_PATH" --force cleanup || true

return 0
Expand All @@ -92,7 +92,7 @@ package::brew_import() {

if package::common_import_check brew "$HOMEBREW_DUMP_FILE_PATH"; then
output::write "🚀 Importing 🍺 brew from '$HOMEBREW_DUMP_FILE_PATH'"
brew bundle install --file="$HOMEBREW_DUMP_FILE_PATH" | log::file "Importing $brew_title packages list"
brew bundle install --file="$HOMEBREW_DUMP_FILE_PATH" | log::file "Importing $brew_title packages"

return 0
fi
Expand All @@ -105,7 +105,7 @@ package::apt_dump() {

if package::common_dump_check apt "$APT_DUMP_FILE_PATH"; then
output::write "🚀 Starting APT dump to '$APT_DUMP_FILE_PATH'"
apt-mark showmanual >|"$APT_DUMP_FILE_PATH" | log::file "Exporting $apt_title packages list"
apt-mark showmanual >|"$APT_DUMP_FILE_PATH" | log::file "Exporting $apt_title packages"

return 0
fi
Expand All @@ -118,7 +118,7 @@ package::apt_import() {

if package::common_import_check apt "$APT_DUMP_FILE_PATH"; then
output::write "🚀 Importing APT from '$HOMEBREW_DUMP_FILE_PATH'"
xargs sudo apt-get install -y <"$APT_DUMP_FILE_PATH" | log::file "Importing $apt_title packages list"
xargs sudo apt-get install -y <"$APT_DUMP_FILE_PATH" | log::file "Importing $apt_title packages"
fi
}

Expand All @@ -127,7 +127,7 @@ package::snap_dump() {

if package::common_dump_check snap "$SNAP_DUMP_FILE_PATH"; then
output::write "🚀 Starting SNAP dump to '$SNAP_DUMP_FILE_PATH'"
snap list | tail -n +2 | awk '{ print $1 }' >|"$SNAP_DUMP_FILE_PATH" | log::file "Exporting $snap_title containers list"
snap list | tail -n +2 | awk '{ print $1 }' >|"$SNAP_DUMP_FILE_PATH" | log::file "Exporting $snap_title containers"

return 0
fi
Expand All @@ -140,7 +140,7 @@ package::snap_import() {

if package::common_import_check snap "$SNAP_DUMP_FILE_PATH"; then
output::write "🚀 Importing SNAP from '$HOMEBREW_DUMP_FILE_PATH'"
xargs -I_ sudo snap install "_" <"$SNAP_DUMP_FILE_PATH" | log::file "Importing $snap_title containers list"
xargs -I_ sudo snap install "_" <"$SNAP_DUMP_FILE_PATH" | log::file "Importing $snap_title containers"
fi
}

Expand All @@ -149,7 +149,7 @@ package::python_dump() {

if package::common_dump_check pip3 "$PYTHON_DUMP_FILE_PATH"; then
output::write "🚀 Starting Python dump to '$PYTHON_DUMP_FILE_PATH'"
pip3 freeze >"$PYTHON_DUMP_FILE_PATH" | log::file "Exporting $pip_title packages list"
pip3 freeze >"$PYTHON_DUMP_FILE_PATH" | log::file "Exporting $pip_title packages"

return 0
fi
Expand All @@ -161,7 +161,7 @@ package::python_import() {
PYTHON_DUMP_FILE_PATH="${1:-$PYTHON_DUMP_FILE_PATH}"

if package::common_import_check pip3 "$PYTHON_DUMP_FILE_PATH"; then
output::write "🚀 Importing Python packages from '$PYTHON_DUMP_FILE_PATH'" | log::file "Importing $pip_title packages list"
output::write "🚀 Importing Python packages from '$PYTHON_DUMP_FILE_PATH'" | log::file "Importing $pip_title packages"
pip3 install -r "$PYTHON_DUMP_FILE_PATH"

return 0
Expand All @@ -175,7 +175,7 @@ package::npm_dump() {

if package::common_dump_check npm "$NPM_DUMP_FILE_PATH"; then
output::write "🚀 Starting NPM dump to '$NPM_DUMP_FILE_PATH'"
ls -1 /usr/local/lib/node_modules | grep -v npm >|"$NPM_DUMP_FILE_PATH" | log::file "Exporting $npm_title packages list"
ls -1 /usr/local/lib/node_modules | grep -v npm >|"$NPM_DUMP_FILE_PATH" | log::file "Exporting $npm_title packages"

return 0
fi
Expand All @@ -188,7 +188,7 @@ package::npm_import() {

if package::common_import_check npm "$NPM_DUMP_FILE_PATH"; then
output::write "🚀 Importing NPM packages from '$NPM_DUMP_FILE_PATH'"
xargs -I_ npm install -g "_" < "$NPM_DUMP_FILE_PATH" | log::file "Importing $npm_title packages list"
xargs -I_ npm install -g "_" < "$NPM_DUMP_FILE_PATH" | log::file "Importing $npm_title packages"
fi

return 1
Expand All @@ -199,7 +199,7 @@ package::volta_dump() {

if package::common_dump_check volta "$VOLTA_DUMP_FILE_PATH"; then
output::write "🚀 Starting VOLTA packages from '$VOLTA_DUMP_FILE_PATH'"
volta list all --format plain | awk '{print $2}' >|"$VOLTA_DUMP_FILE_PATH" | log::file "Exporting $volta_title packages list"
volta list all --format plain | awk '{print $2}' >|"$VOLTA_DUMP_FILE_PATH" | log::file "Exporting $volta_title packages"

return 0
fi
Expand All @@ -212,7 +212,31 @@ package::volta_import() {

if package::common_import_check volta "$VOLTA_DUMP_FILE_PATH"; then
output::write "🚀 Importing VOLTA packages from '$VOLTA_DUMP_FILE_PATH'"
xargs -I_ volta install "_" <"$VOLTA_DUMP_FILE_PATH" | log::file "Importing ⚡︎⚔️ volta packages list"
xargs -I_ volta install "_" <"$VOLTA_DUMP_FILE_PATH" | log::file "Importing $volta_title packages"

return 0
fi

return 1
}

package::cargo_dump() {
CARGO_DUMP_FILE_PATH="${1:-$CARGO_DUMP_FILE_PATH}"

if package::common_dump_check cargo "$CARGO_DUMP_FILE_PATH"; then
cargo install --list | grep -E '^[a-z0-9_-]+ v[0-9.]+:$' | cut -f1 -d' ' >|"$CARGO_DUMP_FILE_PATH" | log::file "Exporting $cargo_title packages"

return 0
fi

return 1
}

package::cargo_import() {
CARGO_DUMP_FILE_PATH="${1:-$VOLTA_DUMP_FILE_PATH}"

if package::common_import_check cargo "$CARGO_DUMP_FILE_PATH"; then
xargs -I_ cargo install < "$CARGO_DUMP_FILE_PATH" | log::file "Importing $cargo_title packages"

return 0
fi
Expand Down

0 comments on commit c06b491

Please sign in to comment.