carbs

Cem's Auto Rice Bootstrapping Scripts
git clone git://git.ckyln.com/carbs.git
Log | Files | Refs | README | LICENSE

commit 2d8739f920d14feda471f912fd529a0bc6e7a0e1
parent 0107f8235d3782b2b46de8c3143203f78cd100a7
Author: Cem Keylan <cem@ckyln.com>
Date:   Thu, 21 Nov 2019 11:11:50 +0300

linting

Diffstat:
Mcarbs | 83++++++++++++++++++++++++++++++++++++++++---------------------------------------
1 file changed, 42 insertions(+), 41 deletions(-)

diff --git a/carbs b/carbs @@ -24,8 +24,9 @@ warning() { out "==> WARNING: $@"; } >&2 msg() { out "==> $@"; } msg2() { out " -> $@";} die() { error "$@"; exit 1; } +fallback() { error "$@"; return 1; } -[ $(id -u) = 0 ] && die 'Please run this script without root priviliges' +[ "$(id -u)" = "0" ] && die 'Please run this script without root priviliges' usage() { cat <<EOF @@ -54,23 +55,23 @@ fi while getopts ':p::d::r:n:P::k::s:' flag; do case $flag in - P) curl -Lo $OPTARG https://git.ckyln.com/raw/carbs/progs.csv && exit || die 'Could not download progs.csv' ;; - p) [ -e $OPTARG ] && progs="$(realpath $OPTARG)" || die "Could not find progs.csv file" ;; - r) git ls-remote $OPTARG >/dev/null 2>&1 && dotfiles=$OPTARG || die "Could not find repo" ;; - d) [ -d $OPTARG ] && targetdir="$(realpath $OPTARG)" || die "Target location $OPTARG does not exist or is not a directory" ;; + P) curl -Lo "$OPTARG" https://git.ckyln.com/raw/carbs/progs.csv && exit || die 'Could not download progs.csv' ;; + p) [ -e "$OPTARG" ] && progs="$(realpath "$OPTARG")" || die "Could not find progs.csv file" ;; + r) git ls-remote "$OPTARG" >/dev/null 2>&1 && dotfiles=$OPTARG || die "Could not find repo" ;; + d) [ -d "$OPTARG" ] && targetdir="$(realpath "$OPTARG")" || die "Target location $OPTARG does not exist or is not a directory" ;; n) sudo -V >/dev/null 2>&1 && interactive=0 || die "Sudo must be installed in order to have a non interactive installation" ;; k) XK=$OPTARG ;; - s) [ -d $OPTARG ] && PIDIR="$(realpath $OPTARG)" || die "Could not find post-install directory" ;; + s) [ -d "$OPTARG" ] && PIDIR="$(realpath "$OPTARG")" || die "Could not find post-install directory" ;; :) die "${0##*/}: option requires an argument -- $OPTARG" ;; ?) die "${0##*/}: invalid option -- $OPTARG" ;; esac done -[ -z $dotfiles ] && dotfiles="git://git.ckyln.com/dotfiles" -[ -z $targetdir ] && targetdir="$HOME" -[ -z $progs ] && curl -Lo /tmp/progs.csv https://git.ckyln.com/raw/carbs/progs.csv && progs="/tmp/progs.csv" -[ -z $interactive ] && interactive=1 -[ "$interactive" = "0" ] && [ -z $XK ] && XK="us" +[ -z "$dotfiles" ] && dotfiles="git://git.ckyln.com/dotfiles" +[ -z "$targetdir" ] && targetdir="$HOME" +[ -z "$progs" ] && curl -Lo /tmp/progs.csv https://git.ckyln.com/raw/carbs/progs.csv && progs="/tmp/progs.csv" +[ -z "$interactive" ] && interactive=1 +[ "$interactive" = "0" ] && [ -z "$XK" ] && XK="us" welcomepage() { clear @@ -108,10 +109,10 @@ refreshsystem() { } makeinstall() { - cd /tmp + cd /tmp || fallback "Could not change directory to /tmp" dir="$(mktemp -d)" - git clone --depth 1 $1 $dir || die 'Could not clone git repo' - cd $dir + git clone --depth 1 "$1" "$dir" || die 'Could not clone git repo' + cd "$dir" || fallback "Could not change directory to $dir" make 2>/dev/null sudo make install || die "Could not build or install $1" } @@ -127,21 +128,21 @@ makelist() { installcsv() {\ [ -e $progs ] || die 'Could not retrieve progs.csv' - mkdir -p $HOME/.local/share/carbs && makelist > $HOME/.local/share/carbs/packages + mkdir -p "$HOME/.local/share/carbs" && makelist > "$HOME/.local/share/carbs/packages" while IFS=, read -r src name do case $src in y) out "Installing $name" - yay -S --noconfirm --needed $name >/dev/null || die "Could not install $name" + yay -S --noconfirm --needed "$name" >/dev/null || die "Could not install $name" msg "Installed $name" ;; g) - out "Installing $(basename $name)" - makeinstall $name || die "Could not install $name" - msg "Installed $(basename $name)" ;; + out "Installing $(basename "$name")" + makeinstall "$name" || die "Could not install $name" + msg "Installed $(basename "$name")" ;; *) out "Installing $name" - sudo pacman -S --noconfirm --needed $name >/dev/null || die "Could not install $name" + sudo pacman -S --noconfirm --needed "$name" >/dev/null || die "Could not install $name" msg "Installed $name" ;; esac done < $progs @@ -149,10 +150,10 @@ installcsv() {\ installyay() {\ error 'Could not install yay-bin, building from source' - cd /tmp + cd /tmp || fallback "Could not change directory to /tmp" dir=$(mktemp -d) - cd $dir - curl -Lo $dir/PKGBUILD "https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=yay" + cd "$dir" || fallback "Could not change directory to $dir" + curl -Lo "$dir/PKGBUILD" "https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=yay" makepkg --noconfirm --ignore-arch -si || die 'Could not install yay' } @@ -161,7 +162,7 @@ basedevelopenrc () { gettext grep groff gzip libtool m4 make patch pkgconf sed sudo texinfo util-linux which" for pkg in ${ORBDL}; do out "Installing $pkg" - sudo pacman -S --noconfirm --needed $pkg >/dev/null || die "Could not install $pkg" + sudo pacman -S --noconfirm --needed "$pkg" >/dev/null || die "Could not install $pkg" msg "Installed $pkg" done } @@ -172,10 +173,10 @@ installyaybin() {\ else sudo pacman -S --noconfirm --needed base-devel || die 'Could not install base-devel' fi - cd /tmp + cd /tmp || fallback "Could not change directory to /tmp" dir=$(mktemp -d) - cd $dir - curl -Lo $dir/PKGBUILD "https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=yay-bin" + cd "$dir" || fallback "Could not change directory to $dir" + curl -Lo "$dir/PKGBUILD" "https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=yay-bin" makepkg --noconfirm -si || installyay } @@ -186,32 +187,32 @@ sudouser() {\ } dotfilesinstall() { - cd /tmp + cd /tmp || fallback "Could not change directory to /tmp" dir="$(mktemp -d)" - git clone --recursive --depth 1 $1 $dir/repo - cp -rfT $dir/repo $targetdir - rm $targetdir/README* $targetdir/LICENSE $targetdir/.git -rf $targetdir/screenshots + git clone --recursive --depth 1 "$1" "$dir/repo" + cp -rfT "$dir/repo" "$targetdir" + rm "$targetdir/README"* "$targetdir/LICENSE" "$targetdir/.git" -rf "$targetdir/screenshots" } wallpaperinstall() { out ' Installing wallpapers' - mkdir -p $targetdir/Pictures - git clone --depth 1 git://git.ckyln.com/Wallpapers $targetdir/Pictures/Wallpapers && msg 'Downloaded Wallpapers' || error 'Could not install wallpapers' + mkdir -p "$targetdir/Pictures" + git clone --depth 1 git://git.ckyln.com/Wallpapers "$targetdir/Pictures/Wallpapers" && msg 'Downloaded Wallpapers' || error 'Could not install wallpapers' } keyboardset() { if [ -z $XK ]; then XK="$(sed '/^! layout$/,/^ *$/!d;//d' /usr/share/X11/xkb/rules/base.lst | fzf --prompt "What X11 Keymap are you going to use? (default: us) " | awk '{print $1}')" - [ -z $XK ] && XK="us" + [ -z "$XK" ] && XK="us" fi - printf "KEYMAP=$XK\\n" > $HOME/.config/xkeymap + printf "KEYMAP=$XK\\n" > "$HOME/.config/xkeymap" } addusergroups() { groups="wheel audio video power" for group in ${groups}; do msg "Adding user to the $group group" - sudo usermod -a -G $group $USER || error "Could not add you to the $group group, you might want to do it yourself" + sudo usermod -a -G "$group" "$USER" || error "Could not add you to the $group group, you might want to do it yourself" done } @@ -226,16 +227,16 @@ EOF postinstall() { out "Starting post-installation" if [ -z "$PIDIR" ]; then - cd /tmp + cd /tmp || fallback "Could not change directory to /tmp" DIR="$(mktemp -d)" PIDIR="${DIR}/post-install" - git clone git://git.ckyln.com/carbs $DIR >/dev/null + git clone git://git.ckyln.com/carbs "$DIR" >/dev/null out "Cloning CARBS repository for post-installation scripts" fi - cd $PIDIR + cd "$PIDIR" || fallback "Could not change directory to $PIDIR" for script in *; do case $script in - *.sh) ./${script} $targetdir ;; + *.sh) ./"${script}" "$targetdir" ;; README) continue ;; template) continue ;; *) warning "$script is not a shell script, not running" ;; @@ -247,7 +248,7 @@ postinstall() { if [ $interactive = 1 ]; then welcomepage - sudo -V >/dev/null 2>&1 || sudouser $USER + sudo -V >/dev/null 2>&1 || sudouser "$USER" fi refreshsystem sudo pacman -S --noconfirm --needed fzf curl git