Add etc skel sync script
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
eb3a1178b6
commit
9e2f188ba1
3 changed files with 112 additions and 10 deletions
|
@ -5,19 +5,19 @@
|
||||||
set -e;
|
set -e;
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "Script to synchronize dotfiles or common scripts";
|
echo "Script to synchronize dotfiles-system with your system";
|
||||||
echo "---";
|
|
||||||
echo "- Press 1 to sync the git folder's '/etc' with system's '/etc'";
|
|
||||||
echo "";
|
echo "";
|
||||||
echo "- Press 2 to sync the git folder's '/etc' with all command line users with a certain shell";
|
echo "(1) to sync the git folder's '/etc' --> system's '/etc'";
|
||||||
echo "";
|
echo "";
|
||||||
echo "- Press 3 to sync the git folder's '/etc' ('/etc/skel') with a specific user's home folder"
|
echo "(2) to sync the git folder's '/etc' with all command line users with a certain shell";
|
||||||
|
echo "";
|
||||||
|
echo "(3) to sync the git folder's '/etc' ('/etc/skel') with a specific user's home folder"
|
||||||
echo "";
|
echo "";
|
||||||
echo "- Press 4 to list command line users for sync";
|
echo "(4) to list command line users for sync";
|
||||||
echo "";
|
echo "";
|
||||||
echo "- Press 5 to sync the git folder's '/usr' with system's '/usr'";
|
echo "(5) to sync the git folder's '/usr' with system's '/usr'";
|
||||||
echo "---";
|
echo "";
|
||||||
echo "Press 0 or [CTRL+C] to exit";
|
echo "(0) or [CTRL+C] to exit";
|
||||||
}
|
}
|
||||||
|
|
||||||
menu() {
|
menu() {
|
|
@ -9,7 +9,7 @@ set bs=2
|
||||||
set cc=80,120
|
set cc=80,120
|
||||||
set fdm=syntax
|
set fdm=syntax
|
||||||
set formatoptions+=j
|
set formatoptions+=j
|
||||||
set lcs=tab:\│\ ,trail:·,eol:¬
|
"set lcs=tab:\│\ ,trail:·,eol:¬
|
||||||
set ls=2
|
set ls=2
|
||||||
set nu
|
set nu
|
||||||
set rnu
|
set rnu
|
||||||
|
|
102
usr/local/bin/dotfiles-system-sync-skel
Executable file
102
usr/local/bin/dotfiles-system-sync-skel
Executable file
|
@ -0,0 +1,102 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Be careful what you are doing with this script. You may overwrite files.
|
||||||
|
# cd into the repository before executing the script!
|
||||||
|
set -e;
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo "Script to synchronize dotfiles-system skel files";
|
||||||
|
echo "";
|
||||||
|
echo "(1) /etc/skel --> ~/... ALL users (with given shell)";
|
||||||
|
echo "";
|
||||||
|
echo "(2) /etc/skel --> ~/specific user";
|
||||||
|
echo "";
|
||||||
|
echo "(3) list line all users with given shell, e.g. zsh";
|
||||||
|
echo "";
|
||||||
|
echo "(0) or [CTRL+C] to exit";
|
||||||
|
}
|
||||||
|
|
||||||
|
menu() {
|
||||||
|
usage;
|
||||||
|
read -n 1 -e -p ">" menuInput
|
||||||
|
echo "";
|
||||||
|
|
||||||
|
if [ "$menuInput" = "1" ]; then
|
||||||
|
# require root
|
||||||
|
[[ $UID -eq 0 ]] || (>&2 echo "ERROR: need to be root!" && exit 1)
|
||||||
|
|
||||||
|
# determine shell
|
||||||
|
echo "Which shell (shortname, e.g. zsh)?";
|
||||||
|
read -e -p ">" shellInput
|
||||||
|
echo "";
|
||||||
|
|
||||||
|
# shell users
|
||||||
|
users=$(cat /etc/passwd|grep $shellInput| awk -F':' '{ print $1 }');
|
||||||
|
|
||||||
|
# stage
|
||||||
|
tmpDir=/tmp/dotfiles-system-sync/;
|
||||||
|
mkdir -p $tmpDir;
|
||||||
|
srcDir=$(pwd)/etc/skel/.
|
||||||
|
cp -R $srcDir $tmpDir;
|
||||||
|
|
||||||
|
# copy
|
||||||
|
for user in $users; do
|
||||||
|
exists=$(id -u $user);
|
||||||
|
primaryGroup=$(id -gn $user);
|
||||||
|
chown -R $user:$primaryGroup $tmpDir;
|
||||||
|
trgDir=$(eval echo ~$user/);
|
||||||
|
echo "Copy from $tmpDir to $trgDir";
|
||||||
|
cp -Rp $tmpDir/. $trgDir/;
|
||||||
|
done
|
||||||
|
|
||||||
|
# remove stage
|
||||||
|
rm -rf $tmpDir;
|
||||||
|
elif [ "$menuInput" = "2" ]; then
|
||||||
|
# determine shell
|
||||||
|
echo "Which user?";
|
||||||
|
read -e -p ">" user
|
||||||
|
echo "";
|
||||||
|
|
||||||
|
# stage
|
||||||
|
tmpDir=/tmp/dotfiles-system-sync/;
|
||||||
|
mkdir -p $tmpDir;
|
||||||
|
srcDir=$(pwd)/etc/skel/.
|
||||||
|
cp -R $srcDir $tmpDir;
|
||||||
|
|
||||||
|
# copy
|
||||||
|
exists=$(id -u $user);
|
||||||
|
|
||||||
|
if [ $UID -ne $exists ] && [ $UID -ne 0 ]; then
|
||||||
|
echo "ERROR: need to be $user or root!";
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
primaryGroup=$(id -gn $user);
|
||||||
|
chown -R $user:$primaryGroup $tmpDir;
|
||||||
|
trgDir=$(eval echo ~$user/);
|
||||||
|
echo "Copy from $tmpDir to $trgDir";
|
||||||
|
cp -Rp $tmpDir/. $trgDir/;
|
||||||
|
|
||||||
|
# remove stage
|
||||||
|
rm -rf $tmpDir;
|
||||||
|
|
||||||
|
elif [ "$menuInput" = "3" ]; then
|
||||||
|
echo "Which shell (shortname, e.g. zsh)?";
|
||||||
|
read -e -p ">" shellInput
|
||||||
|
echo "";
|
||||||
|
|
||||||
|
# shell users
|
||||||
|
users=$(cat /etc/passwd|grep $shellInput| awk -F':' '{ print $1 }');
|
||||||
|
echo "Users with shell $shellInput"
|
||||||
|
|
||||||
|
for u in $users; do
|
||||||
|
echo $u;
|
||||||
|
done
|
||||||
|
elif [ "$menuInput" = "0" ]; then
|
||||||
|
exit 0;
|
||||||
|
fi
|
||||||
|
|
||||||
|
menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
menu;
|
Loading…
Reference in a new issue