Skip to content

Commit

Permalink
Config: Parameterize migration, fix #49
Browse files Browse the repository at this point in the history
  • Loading branch information
ValShaped committed Jun 24, 2024
1 parent 97665a1 commit 10e9dd7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
40 changes: 29 additions & 11 deletions rwfus_include/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ function change_base {
}

function enable_testmode {
echo "Enabling test mode."
echo "Test mode active."
local testdir="${1:-./test}"
for value in $CF_TESTPATHS; do
if [[ ! "${!value}" = *"$testdir"* ]]; then
echo "${value}: ${testdir}${!value}"
# echo "${value}: ${testdir}${!value}"
export "${value}"="${testdir}${!value}"
fi
done
Expand Down Expand Up @@ -221,20 +221,38 @@ function load_config {
fi
fi
done < "$config_file"

CONFIG_LOADED=true
if [ "$TESTMODE" ]; then enable_testmode ./test; fi
}

# Removes a substring from a named config variable
function migrate_remove {
local name="$1"
local needle="$2"
local cf_var="cf_$name"
if [[ "${!cf_var}" =~ "$needle" ]]; then
echo "- $name ${!cf_var}"
export "$cf_var=${!cf_var/${needle}}"
export "$cf_var=${!cf_var// / }"
echo "+ $name ${!cf_var}"
fi
}

# Migrates config to the latest version
function migrate_config {
if [[ $cf_Version != $Version ]]; then
echo Changing "'Directories'"
echo "-${cf_Directories}"
cf_Directories="${cf_Directories/\/var\/lib\/pacman}"
cf_Directories="${cf_Directories// / }"
echo "+${cf_Directories}"
if [[ "${cf_Version}" != "$Version" ]]; then
echo
echo "Migrating config from '$cf_Version' to '$Version'. This will not delete any files."

migrate_remove "Directories" "/var/lib/pacman"

echo

cf_Version="${Version}"
save_config "$1"
cf_Version="$Version"
return 0
else
return 1
fi
}

Expand All @@ -251,7 +269,7 @@ function config {
save_config "$config_file"
;;
m|migrate)
migrate_config "$config_file"
migrate_config
;;
*)
return 127
Expand Down
2 changes: 1 addition & 1 deletion rwfus_include/info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
export Name="Rwfus"
export Description="Carry Pacman across SteamOS updates!"
export Repository="https://github.com/ValShaped/rwfus"
export Version="0.5.0.b2"
export Version="0.5.0.b3"
14 changes: 9 additions & 5 deletions rwfus_include/manage-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ function setup_pacman {
}

function perform_install {
#? SteamOS 3.5 migration: modify config
Log -p echo "$Name $Version is only compatible with SteamOS 3.5"
confirm "Are you sure you want to install $Name $Version?"
#> SteamOS 3.5 migration: modify config
Log config migrate
#? Migrate existing config
if config migrate; then
if (confirm "Are you sure you want to update to $Version?"); then
Log config store
else
exit 1;
fi
fi

Log -p echo "Creating overlays for $cf_Directories:"

if list_service > /dev/null; then
Expand Down

0 comments on commit 10e9dd7

Please sign in to comment.