Skip to content

Bottle configuration migration across versions #53

Closed
@PsykeDady

Description

@PsykeDady

I'm always frustrated when I have to update my bottles and get error key error because of adding a new parameter to json.

So, I think to this solution, is a customizable script that you can include on README, or wherever you want, to help the community migrating their bottles to a new version. The script also produce a "backup" version of the configuration in order to avoiding breaking of the bottle.

If you want, I can make the script generic for every bottle found under .local/share/bottles path.

I already know that at the end of beta you provide a native way to migrate the bottles,Ii hope this can be useful to help the testers of beta versions, a temp. solution.

Script

#!/bin/bash
function upgradeSingleBottle (){
	bottle_path=$1
	update=$2
	default=$3

	echo "Making a backup.."

	a=1

	if [[ -e $bottle_path.old ]]; then 
		echo "previous backup detected. Clean? [y/N]"
		read -r a
		if [[ $a != "Y" && $a != "y" ]]; then 
			a=0
		else 
			a=1
		fi
	fi

	if (( a==1 )); then
		cp "$bottle_path" "$bottle_path.old"
		echo "cp $bottle_path $bottle_path.old"
	fi

	if grep -q "$update" "$bottle_path"; then
		echo "this bottle is already upgraded to new version. Skip"
		return 0
	fi

	n_row=$(cat -n "$bottle_path" | grep "Parameters" | xargs | cut -d ' ' -f1 ) 

	suffix=$(head -"$n_row" "$bottle_path")  

	n_tot=$(wc -l "$bottle_path" | awk '{print($1)}')

	n_post=$(( n_tot - n_row )) 
	prefix=$(tail -$n_post "$bottle_path")

	echo -e "$suffix" '\n'\
			"\t\"$update\":$default, "\
			"\n""$prefix" | tee "$bottle_path"

}

# MAIN 

## put here the json key to add
update="aco_compiler"
## put here the default value of json key
default='""'

bottles_path="$HOME"/.local/share/bottles/bottles/
OIFS=$IFS
IFS=$'\n'
for i in "$bottles_path"/*; do
	echo "upgrading bottle $(basename "$i")"
	upgradeSingleBottle "$i"/bottle.json $update $default

done
IFS=$OIFS

echo "Update Complete. Good Bottles-Time to you Bro!"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions