Personal shell scripts for Mobian on Pinephone.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

38 lines
627 B

#!/bin/bash
# A script to change the current username
# Get current username
printf "\nType the current username:\n"
read old
# Set desired username
printf "\nType the desired username:\n"
read new
# Home paths
ohp="home/$old"
nhp="home/$new"
# Change username
printf "\nChanging username\n"
for file in group gshadow passwd shadow subgid subuid
do
sed -i "s/$old/$new/g" /etc/$file*
done
# Rename home folder
mv /$ohp /$nhp
# Fix path references in /home for new user
printf "\nAdjusting paths in home directory\n"
grep -rl "$ohp" /$nhp | xargs sed -i "s+$ohp+$nhp+g"
# Set user info
echo
chfn $new
sync
reboot