Skip to content

Commit

Permalink
Merge pull request #40 from egalpin/39_bug_remove_sudo_dependence
Browse files Browse the repository at this point in the history
39 bug remove sudo dependence
  • Loading branch information
egalpin authored Jun 29, 2016
2 parents e051bb0 + 0b88439 commit dade050
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 21 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ _Note: you may need to close and reopen your terminal_
5. Change to the cloned directory
- `cd apt-vim`
5. Run `./apt-vim init`
- You will be prompted for `sudo` password during installation
- `sudo` is only required to copy the `apt-vim` script to `/usr/local/bin`
- You may be prompted for `sudo` password during installation if you are missing dependencies such as `git` or `vim`
- See [apt-vim:550](https://github.com/egalpin/apt-vim/blame/master/apt-vim#L550)
6. Add `~/.vimpkg/bin` to your `PATH`
- This can be done by adding `export PATH=$PATH:~/.vimpkg/bin` to `~/.bashrc` or `~/.bash_profile` or equivalent shell configuration file
Expand Down
21 changes: 17 additions & 4 deletions apt-vim
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ BUNDLE_PATH = os.path.abspath(os.path.join(VIM_ROOT_DIR, 'bundle'))
SRC_DIR = os.path.abspath(os.path.join(SCRIPT_ROOT_DIR, 'src'))
BIN_DIR = os.path.abspath(os.path.join(SCRIPT_ROOT_DIR, 'bin'))
VIM_CONFIG_PATH = os.path.abspath(os.path.join(SCRIPT_ROOT_DIR, 'vim_config.json'))
SCRIPT_EXE_PATH = '/usr/local/bin/apt-vim'
SCRIPT_EXE_PATH = os.path.abspath(os.path.join(BIN_DIR, 'apt-vim'))
GBL = 'global'
DPND = 'depends-on'
NAME = 'name'
Expand Down Expand Up @@ -547,8 +547,8 @@ class aptvim(object):
os.makedirs(SRC_DIR)


if not self.call_silent(['sudo', 'cp', os.path.realpath(__file__), '/usr/local/bin']):
report_fail('Failed to copy `apt-vim` to `/usr/local/bin`\n' + \
if not self.call_silent(['cp', os.path.realpath(__file__), SCRIPT_EXE_PATH]):
report_fail('Failed to copy `apt-vim` to `PATH`\n' + \
'Please ensure that `apt-vim` is in your PATH',
confirm_continue=False,
ASSUME_YES=self.ASSUME_YES)
Expand Down Expand Up @@ -584,13 +584,26 @@ class aptvim(object):
' is in your PATH'
report_fail(msg, confirm_continue=False, ASSUME_YES=self.ASSUME_YES)

def confirm_install_ok(self, install_requester, commands):
confirm_string = 'Package `' + install_requester + '` wants to run the following commands:\n'
command_string = ''
for command in commands:
command_string += command + '\n'
confirm_string += command_string + 'Is this ok?'

if self.ASSUME_YES or user_confirm(confirm_string, ASSUME_YES=self.ASSUME_YES):
return True
return False

def init(self):
self.verify_bin_in_path()
missing_deps = []
deps = self.VIM_CONFIG[GBL][DPND]
for dep in deps:
dep = Dependency.dict_to_dep(dep, ASSUME_YES=self.ASSUME_YES)
if not self.check_requirements([dep.name]):
if not self.check_requirements([dep.name]) and \
(len(dep.get_recipe(ASSUME_YES=self.ASSUME_YES)) > 0 and self.confirm_install_ok(dep.name, dep.get_recipe(ASSUME_YES=self.ASSUME_YES))):
print('Attempting to install `' + dep.name + '`')
if not self.exe_shell_commands(dep.get_recipe(ASSUME_YES=self.ASSUME_YES)):
missing_deps.append(dep.name)
return missing_deps
Expand Down
49 changes: 34 additions & 15 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
#! /usr/bin/env sh

start_dir=$(pwd)

if [ -f /etc/profile ] && [ $(sudo grep -c "export PATH=\$PATH:${HOME}/.vimpkg/bin" /etc/profile) -eq 0 ]; then
sudo chmod 666 /etc/profile
sudo echo "export PATH=\$PATH:${HOME}/.vimpkg/bin" >> /etc/profile
sudo chmod 444 /etc/profile
fi

if [ -f /etc/bash.bashrc ] && [ $(sudo grep -c "export PATH=\$PATH:${HOME}/.vimpkg/bin" /etc/bash.bashrc) -eq 0 ]; then
sudo chmod 666 /etc/bash.bashrc
sudo echo "export PATH=\$PATH:${HOME}/.vimpkg/bin" >> /etc/bash.bashrc
sudo chmod 444 /etc/bash.bashrc
fi
bin_string="export PATH=${PATH}:${HOME}/.vimpkg/bin"

# Download the apt-vim files
curl -fSsLo ${HOME}/apt-vim/apt-vim --create-dirs \
Expand All @@ -32,12 +21,26 @@ if [ $(grep -c "call pathogen#helptags()" ${HOME}/.vimrc) -eq 0 ]; then
echo "call pathogen#helptags()" >> ${HOME}/.vimrc
fi

# Update path for current shell
export PATH=${PATH}:${HOME}/.vimpkg/bin
# Update path for executing shell
eval "$bin_string"

added_to_profile=false
already_present=false
for rc in bashrc zshrc bash_profile; do
if [ -s "$HOME/.$rc" ]; then
if grep -q "$bin_string" "$HOME/.$rc"; then
already_present=true
else
printf "\n$bin_string\n" >> "$HOME/.$rc"
printf "== Added apt-vim PATH to '~/.$rc'\n"
added_to_profile=true
fi
fi
done

# Execute apt-vim init
cd ${HOME}/apt-vim
sudo -E python - <<EOF
python - <<EOF
import imp, os
print('apt-vim setup starting')
HOME = os.path.expanduser("~")
Expand All @@ -52,4 +55,20 @@ av = aptvim.aptvim(ASSUME_YES=True, VIM_CONFIG='', INSTALL_TARGET='')
av.first_run()
av.handle_install(None, None, None)
EOF
python_result=$?

cd $start_dir

echo
if [ "$python_result" -ne 0 ]; then
echo "== Error:"
echo " Installation failed."
elif [ "$added_to_profile" = false ] && [ "$already_present" = false ]; then
echo "== Error:"
echo " Found no profile to add apt-vim PATH to."
echo " Add the following line to your shell profile and source it to install manually:"
printf " $exec_string\n"
else
echo "== apt-vim installation succeeded! Run 'source ~/.bashrc || source ~/.bash_profile' or 'source ~/.zshrc'"
echo " to access the executable script."
fi

0 comments on commit dade050

Please sign in to comment.