-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add cleanup script for musl-libc
Signed-off-by: Yiyang Wu <[email protected]>
- Loading branch information
Showing
2 changed files
with
64 additions
and
5 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
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,60 @@ | ||
#!/bin/bash | ||
# Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU) | ||
# Licensed under the Mulan PSL v2. | ||
# You can use this software according to the terms and conditions of the Mulan PSL v2. | ||
# You may obtain a copy of Mulan PSL v2 at: | ||
# http://license.coscl.org.cn/MulanPSL2 | ||
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR | ||
# PURPOSE. | ||
# See the Mulan PSL v2 for more details. | ||
|
||
set -e | ||
|
||
self=$(basename "$0") | ||
|
||
function usage { | ||
echo "Usage: $self [target_absolute_path]" | ||
exit 1 | ||
} | ||
|
||
if [ "$#" -ne 1 ]; then | ||
usage | ||
fi | ||
|
||
if [[ $1 != /* ]]; then | ||
usage | ||
fi | ||
|
||
target=$1 | ||
|
||
# Cleaning up is based on mirror structure of the original backups. | ||
# We recursively iterate over each subdirectories and files under $target, for each file, check whether it's a symlink. If it's a symlink, then delete it and check whether its backup file exists. | ||
# For remaining backup files, we recover it without cleaning up the symlink. | ||
|
||
function traverse { | ||
for file in "$1"/*; do | ||
if [[ -d "$file" ]]; then | ||
if [[ -L "$file" ]]; then | ||
rm "$file" | ||
echo "--- Cleanup ${file} symlink" | ||
else | ||
traverse "$file" | ||
fi | ||
elif [[ -f "$file" && "$file" != *.bak ]]; then | ||
if [[ -L "$file" ]]; then | ||
rm "$file" | ||
echo "--- Cleanup ${file} symlink" | ||
fi | ||
if [[ -f "$file.bak" ]]; then | ||
mv "$file.bak" "$file" | ||
echo "--- Recover ${file}" | ||
fi | ||
elif [[ -f "$file" && "$file" == *.bak ]]; then | ||
mv $file ${file%.bak} | ||
echo "--- Recover ${file}" | ||
fi | ||
done | ||
} | ||
|
||
traverse $target |