2025-05-21 12:03:12 -05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
# Update solus package and infra repos
|
|
|
|
|
|
|
|
|
|
current_date=$(date -I)
|
|
|
|
|
pr_dirs=()
|
2025-12-07 17:25:28 -06:00
|
|
|
src_dir=$HOME/kde/src
|
2025-05-21 12:03:12 -05:00
|
|
|
|
|
|
|
|
# Function to display script usage UPDATE
|
|
|
|
|
usage() {
|
|
|
|
|
echo "Usage: $0"
|
|
|
|
|
echo " -h, --help Display this help message"
|
|
|
|
|
echo "This script takes no arguments."
|
|
|
|
|
echo ''
|
|
|
|
|
echo 'It will check each directory under'
|
|
|
|
|
echo ' $HOME/kde/src and print any which are not on master.'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Silence output for these to avoid cli spam
|
|
|
|
|
pushd () {
|
|
|
|
|
command pushd "$@" > /dev/null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
popd () {
|
|
|
|
|
command popd "$@" > /dev/null
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-07 17:25:28 -06:00
|
|
|
# TODO add fix variable --fix / -f and only run fix function if passed
|
2025-05-21 12:03:12 -05:00
|
|
|
|
2025-12-07 17:25:28 -06:00
|
|
|
get_top_branch () {
|
|
|
|
|
top_branch_untrimmed=$(git log --oneline --graph --decorate | grep -o 'HEAD -> .*' | awk '/>\s/{ print $3 }')
|
|
|
|
|
top_branch="${top_branch_untrimmed%?}"
|
|
|
|
|
}
|
2025-05-21 12:03:12 -05:00
|
|
|
|
|
|
|
|
get_branch_per_dir () {
|
2025-12-07 17:25:28 -06:00
|
|
|
for dir in $(find ${src_dir} -maxdepth 1 -type d);
|
2025-05-21 12:03:12 -05:00
|
|
|
do
|
2025-12-07 17:25:28 -06:00
|
|
|
cd ${dir}
|
|
|
|
|
if [[ "${dir}" == *"src/log" || "${dir}" == "${src_dir}" ]]; then
|
|
|
|
|
printf "Skipping directory %s\n" ${dir}
|
|
|
|
|
continue
|
|
|
|
|
fi
|
|
|
|
|
|
2025-05-21 12:03:12 -05:00
|
|
|
dir_branch=$(git rev-parse --abbrev-ref HEAD)
|
2025-12-07 17:25:28 -06:00
|
|
|
get_top_branch
|
|
|
|
|
if [[ ! "${dir_branch}" == "${top_branch}" ]]; then
|
|
|
|
|
printf "%s not on its main branch\n" "${dir}"
|
2025-05-21 12:03:12 -05:00
|
|
|
pr_dirs+=("${dir}")
|
|
|
|
|
fi
|
2025-12-07 17:25:28 -06:00
|
|
|
|
|
|
|
|
cd ${src_dir}
|
2025-05-21 12:03:12 -05:00
|
|
|
done
|
2025-12-07 17:25:28 -06:00
|
|
|
echo "Done checking branches"
|
2025-05-21 12:03:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
print_array () {
|
|
|
|
|
a=("$@")
|
|
|
|
|
for b in "${a[@]}";
|
|
|
|
|
do
|
|
|
|
|
echo "$b"
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-07 17:25:28 -06:00
|
|
|
fix_branches () {
|
|
|
|
|
a=("$@")
|
|
|
|
|
for b in "${a[@]}";
|
|
|
|
|
do
|
|
|
|
|
echo "Fixing $b"
|
|
|
|
|
cd ${b}
|
|
|
|
|
get_top_branch
|
|
|
|
|
git reset --hard
|
|
|
|
|
git switch ${top_branch}
|
|
|
|
|
git fetch && git pull
|
|
|
|
|
done
|
|
|
|
|
}
|
2025-05-21 12:03:12 -05:00
|
|
|
|
2025-12-07 17:25:28 -06:00
|
|
|
if [[ ( $@ == "--help") || $@ == "-h" ]]; then
|
|
|
|
|
usage
|
|
|
|
|
exit 0
|
2025-05-21 12:03:12 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
printf "Getting KDE source directory branches...\n"
|
|
|
|
|
get_branch_per_dir
|
2025-12-07 17:25:28 -06:00
|
|
|
|
|
|
|
|
if [[ ${#pr_dirs[@]} -eq 0 ]]; then
|
|
|
|
|
echo "[INFO] No directories need to switch branches"
|
|
|
|
|
exit 0
|
|
|
|
|
else
|
|
|
|
|
printf "\n[INFO] Directories not on the top branch:\n"
|
|
|
|
|
print_array "${pr_dirs[@]}"
|
|
|
|
|
printf "\n[INFO] Switching branches to top branch\n"
|
|
|
|
|
fix_branches "${pr_dirs[@]}"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
printf "[INFO] Directories are up to date"
|