vcarbs

Cem's Auto Rice Bootstrapping Scripts, for Void Linux
git clone git://git.ckyln.com/vcarbs.git
Log | Files | Refs | README | LICENSE

commit e733074ee452b019a766a65ff7fac7a6b4662388
parent aebd2f83dcacb198fdb23dabc147af29f12cf43a
Author: Cem Keylan <cem@ckyln.com>
Date:   Thu, 21 Nov 2019 10:53:45 +0300

linting

Diffstat:
Mcarbs | 70++++++++++++++++++++++++++++++++++++----------------------------------
1 file changed, 36 insertions(+), 34 deletions(-)

diff --git a/carbs b/carbs @@ -16,6 +16,7 @@ ## You should have received a copy of the GNU General Public License ## along with this program. If not, see <https://www.gnu.org/licenses/>. +# shellcheck disable=SC2048 # Messages below are taken from Arch scripts out() { printf "$1\\n"; } @@ -24,8 +25,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 +56,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/vcarbs/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/vcarbs/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/vdotfiles" -[ -z $targetdir ] && targetdir="$HOME" -[ -z $progs ] && curl -Lo /tmp/progs.csv https://git.ckyln.com/raw/vcarbs/progs.csv && progs="/tmp/progs.csv" -[ -z $interactive ] && interactive=1 -[ "$interactive" = "0" ] && [ -z $XK ] && XK="us" +[ -z "$dotfiles" ] && dotfiles="git://git.ckyln.com/vdotfiles" +[ -z "$targetdir" ] && targetdir="$HOME" +[ -z "$progs" ] && curl -Lo /tmp/progs.csv https://git.ckyln.com/raw/vcarbs/progs.csv && progs="/tmp/progs.csv" +[ -z "$interactive" ] && interactive=1 +[ "$interactive" = "0" ] && [ -z "$XK" ] && XK="us" welcomepage() { clear @@ -101,10 +103,10 @@ read ans } 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" } @@ -118,17 +120,17 @@ 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 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 xbps-install -y $name >/dev/null || die "Could not install $name" + sudo xbps-install -y "$name" >/dev/null || die "Could not install $name" msg "Installed $name" ;; esac done < $progs @@ -144,29 +146,29 @@ 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" } serviceinit() { - for service in $@; do + for service in $*; do out "Creating service for $service" sudo ln -s "/etc/sv/$service" /var/service sudo sv start "$service" @@ -177,7 +179,7 @@ addusergroups() { groups="wheel audio video" 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 } @@ -192,16 +194,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/vcarbs $DIR >/dev/null + git clone git://git.ckyln.com/vcarbs "$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" ;; @@ -217,7 +219,7 @@ umaskfix() { if [ $interactive = 1 ]; then welcomepage - sudo -V >/dev/null 2>&1 || sudouser $USER + sudo -V >/dev/null 2>&1 || sudouser "$USER" fi [ -z "$sudouser" ] && umaskfix "$USER" sudo xbps-install -y -Su || die 'Could not refresh xbps database'