Compare commits

..

No commits in common. "main" and "v1.1.0" have entirely different histories.
main ... v1.1.0

4 changed files with 28 additions and 62 deletions

View file

@ -22,7 +22,7 @@ My goal with this script is to keep it simple, just a single line that gives use
<hr> <hr>
### Installing: ### Installing:
#### Automatic Installation via Curl #### Via Curl
<sub>Bash:</sub> <sub>Bash:</sub>
``` ```
bash -c "$(curl -s https://raw.githubusercontent.com/G2-Games/welcome.sh/main/install.sh)" bash -c "$(curl -s https://raw.githubusercontent.com/G2-Games/welcome.sh/main/install.sh)"
@ -35,7 +35,7 @@ zsh -c "$(curl -s https://raw.githubusercontent.com/G2-Games/welcome.sh/main/ins
It installs to `~/.welcome/welcome.sh`, and adds a line to the bottom of `~/.bashrc` or `~/.zshrc` It installs to `~/.welcome/welcome.sh`, and adds a line to the bottom of `~/.bashrc` or `~/.zshrc`
#### Manual Installation #### Manual Installation
To install it manually, download the latest `welcome.sh` from <a href="https://github.com/G2-Games/welcome.sh/releases/latest">releases</a> and place it in your home directory. Then add `bash ~/welcome.sh` to your `.bashrc`. It works without the config file, but you can also add that to your home directory for easier manual updates. To use it, download the latest `welcome.sh` from <a href="https://github.com/G2-Games/welcome.sh/releases/latest">releases</a> and place it in your home directory. Then add `bash ~/welcome.sh` to your `.bashrc`. It works without the config file, but you can also add that to your home directory for easier manual updates.
### Updating: ### Updating:
Run the script again to check for an update. If you have an older version it will prompt you. You can update **from** any version **to** any newer version. The proper files will be downloaded as necessary. Run the script again to check for an update. If you have an older version it will prompt you. You can update **from** any version **to** any newer version. The proper files will be downloaded as necessary.

View file

@ -1,25 +0,0 @@
#!/bin/bash
version=1
echo "Ensuring welcome.sh is installed in the new location..."
# Check if welcome.sh is installed in the old location
if [[ -f ~/.welcome ]]\
|| [[ -f ~/.welcome/welcome.sh ]]\
|| [[ -f ~/.welcome/config.cfg ]];
then
# Modify the files with proper paths
sed "${i}d" "$zshrc" > file.tmp && mv file.tmp "$zshrc"
# Create the directories in the proper spots
mkdir -p ~/.config/welcome.sh/
mkdir -p ~/.local/bin/
# Move the welcome files to the proper folders
mv ~/.welcome/config.cfg ~/.config/welcome.sh/config.cfg
mv ~/.welcome/welcome.sh ~/.local/bin/welcome.sh
echo "welcome.sh is now installed in the new location!"
else
echo "welcome.sh is already installed properly!"
fi

View file

@ -35,7 +35,6 @@ uninstall () {
echo "Goodbye. Uninstalling..." echo "Goodbye. Uninstalling..."
tput sc tput sc
rm ~/.welcome/welcome.sh 2> /dev/null rm ~/.welcome/welcome.sh 2> /dev/null
rm ~/.welcome/install.sh 2> /dev/null
rm ~/.welcome/config.cfg 2> /dev/null rm ~/.welcome/config.cfg 2> /dev/null
rm ~/.welcome/config_old.cfg 2> /dev/null rm ~/.welcome/config_old.cfg 2> /dev/null
rm -r ~/.welcome rm -r ~/.welcome
@ -62,11 +61,9 @@ update () {
echo "Updating..." echo "Updating..."
tput sc tput sc
mkdir -p ~/.welcome mkdir -p ~/.welcome
rm ~/.welcome/welcome.sh 2> /dev/null rm ~/.welcome/welcome.sh
rm ~/.welcome/install.sh 2> /dev/null
curl -SL https://github.com/G2-Games/welcome.sh/releases/download/v"${version}"/welcome.sh --output ~/.welcome/welcome.sh curl -SL https://github.com/G2-Games/welcome.sh/releases/download/v"${version}"/welcome.sh --output ~/.welcome/welcome.sh
curl -SL https://raw.githubusercontent.com/G2-Games/welcome.sh/main/install.sh --output ~/.welcome/install.sh
if [[ $vernum -ge 100 ]] && [[ $overcfg -gt 0 ]]; then if [[ $vernum -ge 100 ]] && [[ $overcfg -gt 0 ]]; then
echo "Backing up: config.cfg >> config_old.cfg" echo "Backing up: config.cfg >> config_old.cfg"
mv ~/.welcome/config.cfg ~/.welcome/config_old.cfg mv ~/.welcome/config.cfg ~/.welcome/config_old.cfg
@ -74,19 +71,19 @@ update () {
fi fi
# Check for older versions and replace bashrc lines # Check for older versions and replace bashrc lines
lines=$(grep -sn 'bash ~/.welcome/welcome.sh' "$bashrc" | sed -e 's/:.*//g' && grep -sn 'bash /home/$USER/.welcome/welcome.sh' "$bashrc" | sed -e 's/:.*//g') # Find target line number lines=$(grep -sn 'bash ~/.welcome/welcome.sh' $bashrc | sed -e 's/:.*//g' && grep -sn 'bash /home/$USER/.welcome/welcome.sh' $bashrc | sed -e 's/:.*//g')
lines=$(printf '%s\n' "$lines" | sed '1!G;h;$!d' | sed ':a;N;$!ba;s/\n/ /g') # Format the line number properly (macos doesn't have Cut)
for i in $lines; do
sed "${i}d" "$bashrc" > file.tmp && mv file.tmp "$bashrc"
done
echo 'bash ~/.welcome/welcome.sh' >> "$bashrc"
lines=$(grep -sn 'zsh ~/.welcome/welcome.sh' "$zshrc" | sed -e 's/:.*//g' && grep -sn 'zsh /home/$USER/.welcome/welcome.sh' "$zshrc" | sed -e 's/:.*//g')
lines=$(printf '%s\n' "$lines" | sed '1!G;h;$!d' | sed ':a;N;$!ba;s/\n/ /g') lines=$(printf '%s\n' "$lines" | sed '1!G;h;$!d' | sed ':a;N;$!ba;s/\n/ /g')
for i in $lines; do for i in $lines; do
sed "${i}d" "$zshrc" > file.tmp && mv file.tmp "$zshrc" sed "${i}d" $bashrc > file.tmp && mv file.tmp $bashrc
done done
echo 'zsh ~/.welcome/welcome.sh' >> "$zshrc" echo 'bash ~/.welcome/welcome.sh' >> $bashrc
lines=$(grep -sn 'zsh ~/.welcome/welcome.sh' $zshrc | sed -e 's/:.*//g' && grep -sn 'zsh /home/$USER/.welcome/welcome.sh' $zshrc | sed -e 's/:.*//g')
lines=$(printf '%s\n' "$lines" | sed '1!G;h;$!d' | sed ':a;N;$!ba;s/\n/ /g')
for i in $lines; do
sed "${i}d" $zshrc > file.tmp && mv file.tmp $zshrc
done
echo 'zsh ~/.welcome/welcome.sh' >> $zshrc
tput rc el ed tput rc el ed
echo -e "\e[32mUpdated to v$version! \e[0m" echo -e "\e[32mUpdated to v$version! \e[0m"
@ -128,12 +125,9 @@ this script!\e[0m Please use \e[3mBash \e[0mor \e[3mZsh.\e[0m\n" "${environment}
fi fi
# Check if already installed # Check if already installed
if ! grep -qs 'bash ~/.welcome/welcome.sh' $bashrc && if ! grep -qs 'bash ~/.welcome/welcome.sh' $bashrc && ! grep -qs 'zsh ~/.welcome/welcome.sh' $zshrc && ! grep -qs 'bash /home/$USER/.welcome/welcome.sh' $bashrc && ! grep -qs 'zsh /home/$USER/.welcome/welcome.sh' $zshrc; then
! grep -qs 'zsh ~/.welcome/welcome.sh' $zshrc &&
! grep -qs 'bash /home/$USER/.welcome/welcome.sh' $bashrc &&
! grep -qs 'zsh /home/$USER/.welcome/welcome.sh' $zshrc;
then
#==== Execute if first time installing...====# #==== Execute if first time installing...====#
tput rc tput rc
echo "Welcome! Installing v$version in $environment..." echo "Welcome! Installing v$version in $environment..."
tput sc tput sc
@ -141,8 +135,6 @@ then
cd ~/ || exit 1 cd ~/ || exit 1
mkdir -p ~/.welcome mkdir -p ~/.welcome
curl -SL https://github.com/G2-Games/welcome.sh/releases/download/v"${version}"/welcome.sh --output ~/.welcome/welcome.sh curl -SL https://github.com/G2-Games/welcome.sh/releases/download/v"${version}"/welcome.sh --output ~/.welcome/welcome.sh
curl -SL https://raw.githubusercontent.com/G2-Games/welcome.sh/main/install.sh --output ~/.welcome/install.sh
if [[ $vernum -ge 100 ]]; then if [[ $vernum -ge 100 ]]; then
curl -SL https://github.com/G2-Games/welcome.sh/releases/download/v"${version}"/config.cfg --output ~/.welcome/config.cfg curl -SL https://github.com/G2-Games/welcome.sh/releases/download/v"${version}"/config.cfg --output ~/.welcome/config.cfg
fi fi

View file

@ -1,8 +1,13 @@
# shellcheck source=/home/g2/Documents/projects/code/misc/welcome.sh/welcome.sh
# Bash "strict mode" => http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
IFS=$'\n\t'
export LC_NUMERIC="en_US.UTF-8" &> /dev/null #Fix for locales that use , instead of . as a decimal delimiter export LC_NUMERIC="en_US.UTF-8" &> /dev/null #Fix for locales that use , instead of . as a decimal delimiter
# Define "global" variables # Define "global" variables
environment=$(ps -o args= -p $$ | grep -Em 1 -o '\w{0,5}sh' | head -1) environment=$(ps -o args= -p $$ | grep -Em 1 -o '\w{0,5}sh' | head -1)
version=1.1.2 version=1.0.5
#========Welcome=======# #========Welcome=======#
welcome () { welcome () {
@ -19,7 +24,7 @@ welcome () {
fi fi
if [ "$randgreeting" = "on" ]; then if [ "$randgreeting" = "on" ]; then
msg=${greetings[@]:$greetingsNumber:1} msg=${greetings[$greetingsNumber]}
fi fi
# Print the welcome message # Print the welcome message
@ -119,12 +124,12 @@ updates () {
# Check for updates from different places... wonder if there's a better way # Check for updates from different places... wonder if there's a better way
updchk () { updchk () {
# Check for APT (Debian based) # Check for APT
if command -v apt-get &> /dev/null; then if command -v apt-get &> /dev/null; then
debian=$(apt-get -s dist-upgrade -V | grep -c '=>') debian=$(apt-get -s dist-upgrade -V | grep -c '=>')
fi fi
# Check for Arch things # Check for different Arch things
if command -v checkupdates &> /dev/null; then if command -v checkupdates &> /dev/null; then
arch=$(checkupdates 2> /dev/null | wc -l) arch=$(checkupdates 2> /dev/null | wc -l)
elif command -v yay &> /dev/null; then elif command -v yay &> /dev/null; then
@ -144,12 +149,6 @@ updates () {
fedora=$((fedora-1)) fedora=$((fedora-1))
fi fi
# Check for OpenSUSE things
if command -v zypper &> /dev/null; then
suse=$(zypper list-updates 2> /dev/null | wc -l)
suse=$((suse-4))
fi
# Check for Brew updates # Check for Brew updates
if command -v brew &> /dev/null; then if command -v brew &> /dev/null; then
brew=$(brew outdated 2> /dev/null | wc -l) brew=$(brew outdated 2> /dev/null | wc -l)
@ -161,7 +160,7 @@ updates () {
fi fi
# Add all update counts together # Add all update counts together
updates=$((debian + arch + fedora + suse + flatpak + brew)) updates=$((debian + arch + fedora + flatpak + brew))
echo $updates >| ~/.welcome/updates echo $updates >| ~/.welcome/updates
pkill -P "${pid}" sleep # When update checking is finished, kill the sleep function running under this bash process pkill -P "${pid}" sleep # When update checking is finished, kill the sleep function running under this bash process
sleep 5 sleep 5
@ -170,7 +169,7 @@ updates () {
fi fi
} }
pid=$$ # Grab the PID of the process pid=$$ # Grab the PID of the process
updchk & # Check for updates Asynchronously updchk & # Check for updates Asynchronously
set +e # Allow nonzero exit status for killing sleep set +e # Allow nonzero exit status for killing sleep
@ -272,9 +271,9 @@ lastdate=$(cat ~/.welcome/udm 2>/dev/null)
if [[ $((date - lastdate)) -ge 86400 ]]; then if [[ $((date - lastdate)) -ge 86400 ]]; then
if [[ "$environment" = "bash" ]]; then if [[ "$environment" = "bash" ]]; then
bash ~/.welcome/install.sh auto bash install.sh auto
elif [[ "$environment" = "zsh" ]]; then elif [[ "$environment" = "zsh" ]]; then
zsh ~/.welcome/install.sh auto zsh install.sh auto
fi fi
date +%s >| ~/.welcome/udm 2>/dev/null date +%s >| ~/.welcome/udm 2>/dev/null
elif ! [[ -f ~/.welcome/udm ]]; then elif ! [[ -f ~/.welcome/udm ]]; then