-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide migration script migrate-to-minifai (WIP)
Executing it converts our existing config/* from FAI layout (e.g. config/files/$FILENAME/$CLASS) into the new minifai layout (e.g. config/files/$CLASS/$FILENAME). See #267
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/bash | ||
# Purpose: migrate config/files from FAI layout to new minifai layout, | ||
# see https://github.com/grml/grml-live/issues/267 | ||
|
||
set -euo pipefail | ||
|
||
if [ -d ".git" ] ; then | ||
echo "Git repository detected, operating with git" | ||
git_cmd='git' | ||
else | ||
echo "Not running within git repository, only echo-ing file actions" | ||
git_cmd='echo' | ||
fi | ||
|
||
## fcopy files | ||
# e.g. config/files/etc/hosts/GRMLBASE becomes config/files/GRMLBASE/etc/hosts | ||
find config/files/ -type f -print0 | while IFS= read -r -d '' file; do | ||
orig_filename="${file}" | ||
new_filename="$(dirname "${orig_filename#config/files/}")" | ||
class_name="$(basename "${orig_filename%/}")" | ||
mkdir -p "$(dirname config/files/"${class_name}/${new_filename}")" | ||
"$git_cmd" mv "${file}" "config/files/${class_name}/${new_filename}" | ||
done | ||
|
||
## hooks | ||
# e.g. config/hooks/instsoft.GRMLBASE becomes config/hooks/GRMLBASE/instsoft | ||
find config/hooks/ -type f -print0 | while IFS= read -r -d '' file; do | ||
case "$file" in | ||
"config/hooks/savelog.LAST.source") | ||
echo "WARN: skipping unsupported file config/hooks/savelog.LAST.source detected, remove or convert manually" | ||
continue | ||
;; | ||
esac | ||
orig_filename="${file}" | ||
new_filename="${file##*/}" # extract "instsoft.GRMLBASE" | ||
new_filename="${new_filename%.*}" # remove class name as last part (".GRMLBASE") | ||
class_name="$(basename "${orig_filename##*.}")" | ||
mkdir -p "$(dirname config/hooks/"${class_name}/${new_filename}")" | ||
"$git_cmd" mv "${file}" "config/hooks/${class_name}/${new_filename}" | ||
done | ||
|
||
## env | ||
# e.g. config/class/GRMLBASE.var becomes config/env/GRMLBASE | ||
find config/class/ -type f -print0 | while IFS= read -r -d '' file; do | ||
orig_filename="${file}" | ||
class_name="$(basename "${orig_filename%/}" .var)" | ||
mkdir -p config/env/ | ||
"$git_cmd" mv "${file}" "config/env/${class_name}" | ||
done |