mirror of
https://github.com/adi1090x/rofi.git
synced 2025-12-10 12:22:49 +01:00
Add fixes for setup script
Use `$0` instead of `pwd` command - pwd will cause errors if the script is launched from some other directory. False positive with `[[ -f "$ROFI_DIR/config.rasi" ]]` - This may give a false successful installation message if the user's original 'config.rasi' is still in the directory. - Add `set -eu` which will cause the script to exit if there are any errors to prevent data loss. - Add `trap` command to print error message on script exit. Some more fixes/changes - Check if XDG user direcotries are set. - Simplify script by replacing `if` statements with `||` and `case`.
This commit is contained in:
parent
aba9eb3d1a
commit
1f12de8e12
53
setup.sh
53
setup.sh
@ -3,37 +3,28 @@
|
|||||||
# Install script for rofi themes
|
# Install script for rofi themes
|
||||||
|
|
||||||
# Dirs
|
# Dirs
|
||||||
DIR=`pwd`
|
DIR="${0%/*}"
|
||||||
FONT_DIR="$HOME/.local/share/fonts"
|
FONT_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/fonts"
|
||||||
ROFI_DIR="$HOME/.config/rofi"
|
ROFI_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/rofi"
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
exit_msg="[!] Failed to install.\n"
|
||||||
|
trap 'echo -e $exit_msg' EXIT
|
||||||
|
|
||||||
# Install Fonts
|
# Install Fonts
|
||||||
install_fonts() {
|
install_fonts() {
|
||||||
echo -e "\n[*] Installing fonts..."
|
echo -e "\n[*] Installing fonts..."
|
||||||
if [[ -d "$FONT_DIR" ]]; then
|
[[ -d "$FONT_DIR" ]] || mkdir -p "$FONT_DIR"
|
||||||
cp -rf $DIR/fonts/* "$FONT_DIR"
|
cp -r "$DIR"/fonts/* "$FONT_DIR"
|
||||||
else
|
|
||||||
mkdir -p "$FONT_DIR"
|
|
||||||
cp -rf $DIR/fonts/* "$FONT_DIR"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Install Themes
|
# Install Themes
|
||||||
install_themes() {
|
install_themes() {
|
||||||
if [[ -d "$ROFI_DIR" ]]; then
|
if [[ -d "$ROFI_DIR" ]]; then
|
||||||
echo -e "[*] Creating a backup of your rofi configs..."
|
echo -e "[*] Creating a backup of your rofi configs..."
|
||||||
mv "$ROFI_DIR" "${ROFI_DIR}.old"
|
mv -f "$ROFI_DIR" "${ROFI_DIR}.old"
|
||||||
{ mkdir -p "$ROFI_DIR"; cp -rf $DIR/$RES/* "$ROFI_DIR"; }
|
|
||||||
else
|
|
||||||
{ mkdir -p "$ROFI_DIR"; cp -rf $DIR/$RES/* "$ROFI_DIR"; }
|
|
||||||
fi
|
|
||||||
if [[ -f "$ROFI_DIR/config.rasi" ]]; then
|
|
||||||
echo -e "[*] Successfully Installed.\n"
|
|
||||||
exit 0
|
|
||||||
else
|
|
||||||
echo -e "[!] Failed to install.\n"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
cp -r "$DIR/$RES" "$ROFI_DIR"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Main
|
# Main
|
||||||
@ -50,18 +41,16 @@ main() {
|
|||||||
|
|
||||||
read -p "[?] Select Option : "
|
read -p "[?] Select Option : "
|
||||||
|
|
||||||
if [[ $REPLY == "1" ]]; then
|
case $REPLY in
|
||||||
RES='1080p'
|
1) RES='1080p' ;;
|
||||||
install_fonts
|
2) RES='720p' ;;
|
||||||
install_themes
|
*) exit_msg="\n[!] Invalid Option, Exiting...\n"; exit 1 ;;
|
||||||
elif [[ $REPLY == "2" ]]; then
|
esac
|
||||||
RES='720p'
|
|
||||||
install_fonts
|
install_fonts
|
||||||
install_themes
|
install_themes
|
||||||
else
|
exit_msg="[*] Successfully Installed.\n"
|
||||||
echo -e "\n[!] Invalid Option, Exiting...\n"
|
exit 0
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main
|
main
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user