Skip to content

Instantly share code, notes, and snippets.

@theKidOfArcrania
Last active January 28, 2019 00:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theKidOfArcrania/c1d553ed9c76d3815c22620327e2b953 to your computer and use it in GitHub Desktop.
Save theKidOfArcrania/c1d553ed9c76d3815c22620327e2b953 to your computer and use it in GitHub Desktop.
#/bin/bash
set -eu
cd /tmp
_pushd() {
builtin pushd "$@" > /dev/null
}
alias pushd=_pushd
_popd() {
builtin popd "$@" > /dev/null
}
alias popd=_popd
prompt() {
while true; do
read -r -p "$1 [Y/n] " input
case $input in
[yY][eE][sS]|[yY])
return 0
;;
[nN][oO]|[nN])
return 1
;;
esac
done
}
if [ "$(id -u)" -ne "0" ]; then
echo "Must be root!"
exit 1
fi
# Default user is id 1000. Change it if not true
USERID=1000
USERNAME=$(id -nu $USERID)
###########################
# Step 0. User confirmation
###########################
echo "This script will prepare an assembly environment (nasmx, nasm, SASM)"
echo "for the user [$USERNAME]."
prompt "This looks okay to you?"
if [ ! -d "/home/$USERNAME" ]; then
echo "'/home/$USERNAME' is not a valid directory!"
exit 1
fi
##############################
# Step 1. Install applications
##############################
echo "*** Installing applications ***"
# Update stuff
apt-get update
if prompt "Do you want to upgrade software?"; then
apt-get upgrade -y
fi
# Basic stuff
apt-get install -y build-essential vim git nasm gdb subversion gcc-multilib g++-multilib
# For building SASM
apt-get install -y qt4-qmake libqt4-dev libxcb1 libxcb-render0 libxcb-icccm4
################################
# Step 2. Build and install sasm
################################
echo "*** Installing SASM ***"
git clone https://github.com/Dman95/SASM
pushd SASM
qmake
make -j10
make install
popd
rm -rf SASM
#######################
# Step 3. Install nasmx
#######################
echo "*** Installing nasmx ***"
svn checkout -q https://svn.code.sf.net/p/nasmx/code/trunk nasmx
rm -rf nasmx/.svn
mv nasmx /opt/nasmx-1.4
# Use nasmx by default in .bashrc
cat >> "/home/$USERNAME/.bashrc" <<EOF
# Set nasmx paths
OLD_DIR=\$(pwd)
cd /opt/nasmx-1.4; . ./setpaths.sh > /dev/null
cd "\$OLD_DIR"
unset OLD_DIR
EOF
# Link nasmx includes into SASM includes
SASM_INC="/usr/share/sasm/include"
NASM_INC="/opt/nasmx-1.4/inc"
mv $SASM_INC/* "$NASM_INC/"
rm -r "$SASM_INC/"
ln -s "$NASM_INC" "$SASM_INC"
############################
# Step 4. Copy desktop icons
############################
deploy_icon() {
SRC="/usr/share/applications/$1.desktop"
DEST="/home/$USERNAME/desktop/$1.desktop"
cp "$SRC" "$DEST"
chmod u+x "$DEST"
chown "$USERNAME:$USERNAME" "$DEST"
}
echo "*** Copying desktop icons ***"
deploy_icon firefox
deploy_icon sasm
##########################
# Step 5. Customize .vimrc
##########################
if prompt "Do you want to customize vimrc?"; then
cat > "/home/$USERNAME/.vimrc" <<EOF
au BufNewFile,BufRead *.asm set filetype=nasm
filetype plugin indent on
set tabstop=4
set shiftwidth=4
set expandtab
set ai
set ff=unix
set number
EOF
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment